Skip to content
This repository has been archived by the owner on Jul 13, 2020. It is now read-only.

Gates flags behind generational gaps.

License

Notifications You must be signed in to change notification settings

FullScreenShenanigans/FlagSwappr

This branch is 2 commits ahead of, 1 commit behind master.

Folders and files

NameName
Last commit message
Last commit date
Apr 8, 2018
Apr 13, 2019
Jun 18, 2018
Apr 14, 2019
Apr 13, 2019
Aug 30, 2018
Jun 11, 2017
Apr 8, 2018
May 1, 2020
May 1, 2020
Apr 14, 2019
Jun 13, 2017
Aug 16, 2018
Dec 29, 2017
Mar 5, 2018

Repository files navigation

FlagSwappr

Greenkeeper badge Build Status NPM version

Gates feature flags behind generational gaps.

Usage

FlagSwappr keeps track of whether features are enabled based on a current "generation". It's based off the concept of game generations, such as Pokemon, where features are turned on or off in different releases.

Constructor

const flagSwapper = new FlagSwappr({
    generations: {
        first: {
            eggs: false,
        },
        second: {
            eggs: true,
        }
    }
});

generation

Starting generation to enable, if not the first from generationNames.

const flagSwapper = new FlagSwappr({
    generation: "second",
    generations: {
        first: {
            eggs: false,
        },
        second: {
            eggs: true,
        }
    }
});

const { eggs } = flagSwapper.flags; // true

generationNames

Ordered names of the available generations, if not Object.keys(generations). The first key in this string[] is used as the starting generation.

const flagSwapper = new FlagSwappr({
    generationNames: ["second", "first"],
    generations: {
        first: {
            eggs: false,
        },
        second: {
            eggs: true,
        }
    }
});

const { eggs } = flagSwapper.flags; // true

generations

Groups of feature settings, in order. These represent the changes each generation made to the available feature flags.

Usage with TypeScript

FlagSwappr is templated across a TFlags type, where each of its flags are a Partial of that type.

The template is inferred from the constructor or can be specified manually.

interface IFlags {
    eggs: boolean;
}

const flagSwapper = new FlagSwappr<IFlags>({
    generations: {
        first: {
            eggs: false,
        },
        second: {
            eggs: true,
        }
    }
});

flags

Getter for the generation-variant flags. When a new generation is set, the internal representation is reset to an object with flags for what the current generation's state is for that generation. Each member flag is equal the most "recent" generation setting, as defined by the generationNames order.

const flagSwapper = new FlagSwappr({
    generation: "third",
    generationNames: ["first", "second", "third"],
    generations: {
        first: {
            eggs: false,
        },
        second: {
            eggs: true,
        },
    }
});

const { eggs } = flagSwapper.flags; // true

setGeneration

Parameters:

  • generationName: string: Generation for flag setting.

Sets flags to a generation.

const flagSwapper = new FlagSwappr({
    generation: "third",
    generationNames: ["first", "second", "third"],
    generations: {
        first: {
            eggs: false,
        },
        second: {
            eggs: true,
        },
    }
});

flagSwapper.setGeneration("first");

const { eggs } = flagSwapper.flags; // false

Development

After forking the repo from GitHub:

git clone https://github.com/<your-name-here>/FlagSwappr
cd FlagSwappr
npm install
npm run setup
npm run verify
  • npm run setup creates a few auto-generated setup files locally.
  • npm run verify builds, lints, and runs tests.

Building

npm run watch

Source files are written under src/ in TypeScript and compile in-place to JavaScript files. npm run watch will directly run the TypeScript compiler on source files in watch mode. Use it in the background while developing to keep the compiled files up-to-date.

Running Tests

npm run test

Tests are written in Mocha and Chai. Their files are written using alongside source files under src/ and named *.test.ts?. Whenever you add, remove, or rename a *.test.t* file under src/, watch will re-run npm run test:setup to regenerate the list of static test files in test/index.html. You can open that file in a browser to debug through the tests.

About

Gates flags behind generational gaps.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published