Last active
January 11, 2021 22:21
-
-
Save JoshuaTheMiller/4c9b21ecfa6bd7efe3acbbfaf4c20c11 to your computer and use it in GitHub Desktop.
Poor Man's Feature Toggle Article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function buildForecast(location) { | |
| return `The forecast for ${location} is "cloudy"`; | |
| } | |
| function generateWeatherForecast(location) { | |
| const forecast = buildForecast(location); | |
| return forecast; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function buildForecast(location) { | |
| return `The forecast for ${location} is "cloudy"`; | |
| } | |
| function appendAmountOfRain(forecast) { | |
| return `${forecast} with 3cm of rain`; | |
| } | |
| function generateWeatherForecast(location) { | |
| let forecast = buildForecast(location); | |
| if(process.env.CURRENT_ENVIRONMENT === "nonprod") { | |
| forecast = appendAmountOfRain(forecast) | |
| } | |
| return forecast; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function buildForecast(location) { | |
| return `The forecast for ${location} is "cloudy"`; | |
| } | |
| function appendAmountOfRain(forecast) { | |
| return `${forecast} with 3cm of rain`; | |
| } | |
| const features = getFeatureServiceFromSomewhere() | |
| function generateWeatherForecast(location) { | |
| let forecast = buildForecast(location); | |
| if(features.isEnabled("amount-of-rain")) { | |
| forecast = appendAmountOfRain(forecast) | |
| } | |
| return forecast; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function environemntIsNonProduction() { | |
| return process.env.CURRENT_ENVIRONMENT === "nonprod"; | |
| } | |
| const featureServiceObject = { | |
| isEnabled: function(toggleName) { | |
| return environemntIsNonProduction() | |
| } | |
| } | |
| function getFeatureServiceFromSomewhere() { | |
| return featureServiceObject; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment