Skip to content

Instantly share code, notes, and snippets.

@JoshuaTheMiller
Last active January 11, 2021 22:21
Show Gist options
  • Select an option

  • Save JoshuaTheMiller/4c9b21ecfa6bd7efe3acbbfaf4c20c11 to your computer and use it in GitHub Desktop.

Select an option

Save JoshuaTheMiller/4c9b21ecfa6bd7efe3acbbfaf4c20c11 to your computer and use it in GitHub Desktop.

Revisions

  1. JoshuaTheMiller revised this gist Jan 11, 2021. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion groundwork.js
    Original file line number Diff line number Diff line change
    @@ -14,5 +14,9 @@ class weatherForecasterService{
    }
    }

    function useWeatherForecaster(weatherForecaster) {
    console.log(weatherForecaster.generateWeatherForecast("Minnesota"))
    }

    const weatherForecaster = new weatherForecasterService();
    console.log(weatherForecaster.generateWeatherForecast("Minnesota"))
    useWeatherForecaster(weatherForecaster);
  2. JoshuaTheMiller renamed this gist Jan 11, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. JoshuaTheMiller revised this gist Jan 11, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion _README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    This Gist and the associated were created to support an article on Feature Flags (to be linked)
    This Gist and the associated files were created to support an article on Feature Flags (to be linked)
  4. JoshuaTheMiller revised this gist Jan 11, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions _README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    This Gist and the associated were created to support an article on Feature Flags (to be linked)
  5. JoshuaTheMiller revised this gist Jan 11, 2021. 5 changed files with 9 additions and 9 deletions.
    4 changes: 2 additions & 2 deletions groundwork.js
    Original file line number Diff line number Diff line change
    @@ -6,13 +6,13 @@ function appendAmountOfRain(forecast) {
    return `${forecast} with 3cm of rain`;
    }

    class weatherForcasterService{
    class weatherForecasterService{
    generateWeatherForecast(location) {
    const forecast = buildForecast(location);
    // We have been asked to insert appendAmountOfRain(...) here
    return forecast;
    }
    }

    const weatherForecaster = new weatherForcasterService();
    const weatherForecaster = new weatherForecasterService();
    console.log(weatherForecaster.generateWeatherForecast("Minnesota"))
    2 changes: 1 addition & 1 deletion v1.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    const weatherForcasterService = {
    const weatherForecasterService = {
    generateWeatherForecast: function (location) {
    let forecast = buildForecast(location);
    if(process.env.CURRENT_ENVIRONMENT === "nonprod") {
    2 changes: 1 addition & 1 deletion v2.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    const features = getFeatureFlagServiceFromSomewhere()
    class weatherForcasterService{
    class weatherForecasterService{
    generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(features.isEnabled("amount-of-rain")) {
    2 changes: 1 addition & 1 deletion v3.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    const featureDecisions = getFeatureDecisionServiceFromSomewhere()
    class weatherForcasterService{
    class weatherForecasterService{
    generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(featureDecisions.appendAmountOfRainToForecast()) {
    8 changes: 4 additions & 4 deletions v4.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    class weatherForcasterService{
    class weatherForecasterService{
    constructor(options) {
    this.options = options ?? {
    appendAmountOfRainToForecast: false
    @@ -13,14 +13,14 @@ class weatherForcasterService{
    }
    }

    class featureAwareWeatherForcasterServiceFactory{
    class featureAwareWeatherForecasterServiceFactory{
    build() {
    const options = {
    appendAmountOfRainToForecast: featureDecisions.appendAmountOfRainToForecast()
    }

    return new weatherForcasterService(options);
    return new weatherForecasterService(options);
    }
    }

    const weatherForecaster = new featureAwareWeatherForcasterServiceFactory().build();
    const weatherForecaster = new featureAwareWeatherForecasterServiceFactory().build();
  6. JoshuaTheMiller revised this gist Jan 7, 2021. 4 changed files with 33 additions and 7 deletions.
    6 changes: 3 additions & 3 deletions groundwork.js
    Original file line number Diff line number Diff line change
    @@ -6,13 +6,13 @@ function appendAmountOfRain(forecast) {
    return `${forecast} with 3cm of rain`;
    }

    const weatherForcasterService = {
    generateWeatherForecast: function (location) {
    class weatherForcasterService{
    generateWeatherForecast(location) {
    const forecast = buildForecast(location);
    // We have been asked to insert appendAmountOfRain(...) here
    return forecast;
    }
    }

    const weatherForecaster = weatherForcasterService;
    const weatherForecaster = new weatherForcasterService();
    console.log(weatherForecaster.generateWeatherForecast("Minnesota"))
    4 changes: 2 additions & 2 deletions v2.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    const features = getFeatureFlagServiceFromSomewhere()
    const weatherForcasterService = {
    generateWeatherForecast: function (location) {
    class weatherForcasterService{
    generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(features.isEnabled("amount-of-rain")) {
    forecast = appendAmountOfRain(forecast)
    4 changes: 2 additions & 2 deletions v3.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    const featureDecisions = getFeatureDecisionServiceFromSomewhere()
    const weatherForcasterService = {
    generateWeatherForecast: function (location) {
    class weatherForcasterService{
    generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(featureDecisions.appendAmountOfRainToForecast()) {
    forecast = appendAmountOfRain(forecast)
    26 changes: 26 additions & 0 deletions v4.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    class weatherForcasterService{
    constructor(options) {
    this.options = options ?? {
    appendAmountOfRainToForecast: false
    }
    }
    generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(this.options.appendAmountOfRainToForecast) {
    forecast = appendAmountOfRain(forecast)
    }
    return forecast;
    }
    }

    class featureAwareWeatherForcasterServiceFactory{
    build() {
    const options = {
    appendAmountOfRainToForecast: featureDecisions.appendAmountOfRainToForecast()
    }

    return new weatherForcasterService(options);
    }
    }

    const weatherForecaster = new featureAwareWeatherForcasterServiceFactory().build();
  7. JoshuaTheMiller revised this gist Jan 7, 2021. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions v1.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,9 @@
    function generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(process.env.CURRENT_ENVIRONMENT === "nonprod") {
    forecast = appendAmountOfRain(forecast)
    const weatherForcasterService = {
    generateWeatherForecast: function (location) {
    let forecast = buildForecast(location);
    if(process.env.CURRENT_ENVIRONMENT === "nonprod") {
    forecast = appendAmountOfRain(forecast)
    }
    return forecast;
    }
    return forecast;
    }
  8. JoshuaTheMiller revised this gist Jan 7, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion groundwork.js
    Original file line number Diff line number Diff line change
    @@ -14,5 +14,5 @@ const weatherForcasterService = {
    }
    }

    const weatherForecaster = weatherForcasterService
    const weatherForecaster = weatherForcasterService;
    console.log(weatherForecaster.generateWeatherForecast("Minnesota"))
  9. JoshuaTheMiller revised this gist Jan 7, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion groundwork.js
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,5 @@ const weatherForcasterService = {
    }
    }

    console.log(weatherForcasterService.generateWeatherForecast("Minnesota"))
    const weatherForecaster = weatherForcasterService
    console.log(weatherForecaster.generateWeatherForecast("Minnesota"))
  10. JoshuaTheMiller revised this gist Jan 7, 2021. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions groundwork.js
    Original file line number Diff line number Diff line change
    @@ -14,9 +14,4 @@ const weatherForcasterService = {
    }
    }

    function retrieveWeatherForecaster() {
    return weatherForcasterService;
    }

    const weatherForecaster = retrieveWeatherForecaster()
    console.log(weatherForecaster.generateWeatherForecast("Minnesota"))
    console.log(weatherForcasterService.generateWeatherForecast("Minnesota"))
  11. JoshuaTheMiller revised this gist Jan 7, 2021. 3 changed files with 28 additions and 15 deletions.
    19 changes: 14 additions & 5 deletions groundwork.js
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,17 @@ function appendAmountOfRain(forecast) {
    return `${forecast} with 3cm of rain`;
    }

    function generateWeatherForecast(location) {
    const forecast = buildForecast(location);
    // We have been asked to insert appendAmountOfRain(...) here
    return forecast;
    }
    const weatherForcasterService = {
    generateWeatherForecast: function (location) {
    const forecast = buildForecast(location);
    // We have been asked to insert appendAmountOfRain(...) here
    return forecast;
    }
    }

    function retrieveWeatherForecaster() {
    return weatherForcasterService;
    }

    const weatherForecaster = retrieveWeatherForecaster()
    console.log(weatherForecaster.generateWeatherForecast("Minnesota"))
    12 changes: 7 additions & 5 deletions v2.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    const features = getFeatureFlagServiceFromSomewhere()
    function generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(features.isEnabled("amount-of-rain")) {
    forecast = appendAmountOfRain(forecast)
    const weatherForcasterService = {
    generateWeatherForecast: function (location) {
    let forecast = buildForecast(location);
    if(features.isEnabled("amount-of-rain")) {
    forecast = appendAmountOfRain(forecast)
    }
    return forecast;
    }
    return forecast;
    }
    12 changes: 7 additions & 5 deletions v3.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    const featureDecisions = getFeatureDecisionServiceFromSomewhere()
    function generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(featureDecisions.appendAmountOfRainToForecast()) {
    forecast = appendAmountOfRain(forecast)
    const weatherForcasterService = {
    generateWeatherForecast: function (location) {
    let forecast = buildForecast(location);
    if(featureDecisions.appendAmountOfRainToForecast()) {
    forecast = appendAmountOfRain(forecast)
    }
    return forecast;
    }
    return forecast;
    }
  12. JoshuaTheMiller revised this gist Jan 7, 2021. 2 changed files with 19 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions v3.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    const featureDecisions = getFeatureDecisionServiceFromSomewhere()
    function generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(featureDecisions.appendAmountOfRainToForecast()) {
    forecast = appendAmountOfRain(forecast)
    }
    return forecast;
    }
    11 changes: 11 additions & 0 deletions v3_featuredecision.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    const features = getFeatureFlagServiceFromSomewhere()

    const featureDecisionObject = {
    appendAmountOfRainToForecast: function() {
    return features.isEnabled("amount-of-rain")
    }
    }

    function getFeatureDecisionServiceFromSomewhere() {
    return featureServiceObject
    }
  13. JoshuaTheMiller revised this gist Jan 7, 2021. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion v2.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    const features = getFeatureServiceFromSomewhere()
    const features = getFeatureFlagServiceFromSomewhere()
    function generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(features.isEnabled("amount-of-rain")) {
    2 changes: 1 addition & 1 deletion v2_service.js
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,6 @@ const featureServiceObject = {
    }
    }

    function getFeatureServiceFromSomewhere() {
    function getFeatureFlagServiceFromSomewhere() {
    return featureServiceObject;
    }
  14. JoshuaTheMiller revised this gist Jan 7, 2021. 4 changed files with 6 additions and 17 deletions.
    5 changes: 5 additions & 0 deletions groundwork.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,12 @@ function buildForecast(location) {
    return `The forecast for ${location} is "cloudy"`;
    }

    function appendAmountOfRain(forecast) {
    return `${forecast} with 3cm of rain`;
    }

    function generateWeatherForecast(location) {
    const forecast = buildForecast(location);
    // We have been asked to insert appendAmountOfRain(...) here
    return forecast;
    }
    8 changes: 0 additions & 8 deletions v1.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,3 @@
    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") {
    8 changes: 0 additions & 8 deletions v2.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,3 @@
    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);
    2 changes: 1 addition & 1 deletion v2_service.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ function environemntIsNonProduction() {
    }

    const featureServiceObject = {
    isEnabled: function(toggleName) {
    isEnabled: function(flagName) {
    return environemntIsNonProduction()
    }
    }
  15. JoshuaTheMiller revised this gist Jan 7, 2021. 2 changed files with 7 additions and 2 deletions.
    1 change: 1 addition & 0 deletions v2.js
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@ 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")) {
    8 changes: 6 additions & 2 deletions v2_service.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,13 @@
    function environemntIsNonProduction() {
    return false
    return process.env.CURRENT_ENVIRONMENT === "nonprod";
    }

    const features = {
    const featureServiceObject = {
    isEnabled: function(toggleName) {
    return environemntIsNonProduction()
    }
    }

    function getFeatureServiceFromSomewhere() {
    return featureServiceObject;
    }
  16. JoshuaTheMiller revised this gist Jan 7, 2021. 2 changed files with 9 additions and 17 deletions.
    17 changes: 0 additions & 17 deletions v2.js
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,3 @@
    function environemntIsNonProduction() {
    return false
    }

    // Some nonsense builder function to get this example rolling
    function featureToggleService() {
    const fnName = "isEnabled";
    const someObj = {};
    someObj[fnName] = function(toggleName) {
    // For any toggle, just check the env var
    return environemntIsNonProduction()
    };
    return someObj;
    }

    const features = featureToggleService()

    function buildForecast(location) {
    return `The forecast for ${location} is "cloudy"`;
    }
    9 changes: 9 additions & 0 deletions v2_service.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    function environemntIsNonProduction() {
    return false
    }

    const features = {
    isEnabled: function(toggleName) {
    return environemntIsNonProduction()
    }
    }
  17. JoshuaTheMiller revised this gist Jan 7, 2021. 3 changed files with 44 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions groundwork.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    function buildForecast(location) {
    return `The forecast for ${location} is "cloudy"`;
    }

    function generateWeatherForecast(location) {
    const forecast = buildForecast(location);
    return forecast;
    8 changes: 8 additions & 0 deletions v1.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,11 @@
    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") {
    32 changes: 32 additions & 0 deletions v2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    function environemntIsNonProduction() {
    return false
    }

    // Some nonsense builder function to get this example rolling
    function featureToggleService() {
    const fnName = "isEnabled";
    const someObj = {};
    someObj[fnName] = function(toggleName) {
    // For any toggle, just check the env var
    return environemntIsNonProduction()
    };
    return someObj;
    }

    const features = featureToggleService()

    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(features.isEnabled("amount-of-rain")) {
    forecast = appendAmountOfRain(forecast)
    }
    return forecast;
    }
  18. JoshuaTheMiller created this gist Jan 7, 2021.
    4 changes: 4 additions & 0 deletions groundwork.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    function generateWeatherForecast(location) {
    const forecast = buildForecast(location);
    return forecast;
    }
    7 changes: 7 additions & 0 deletions v1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    function generateWeatherForecast(location) {
    let forecast = buildForecast(location);
    if(process.env.CURRENT_ENVIRONMENT === "nonprod") {
    forecast = appendAmountOfRain(forecast)
    }
    return forecast;
    }