-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from elite-se/feature/feature-flags
Feature/feature flags
- Loading branch information
Showing
23 changed files
with
174 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Configuration } from 'elite-types'; | ||
|
||
const configuration: Configuration = { | ||
featureMap: { | ||
'under-construction-message': true, | ||
}, | ||
}; | ||
|
||
export default configuration; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "elite-configuration", | ||
"version": "1.0.0", | ||
"private": true, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"types": "dist/index.d.ts", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"clean": "rm -rf dist/ node_modules/ tsconfig.tsbuildinfo" | ||
}, | ||
"devDependencies": { | ||
"elite-types": "^1.0.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../development.configuration.ts |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import devConfig from './development.configuration'; | ||
import prodConfig from './production.configuration'; | ||
import { Configuration } from 'elite-types'; | ||
|
||
export function getConfiguration(): Configuration { | ||
return process.env.NODE_ENV === 'development' ? devConfig : prodConfig; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../production.configuration.ts |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"baseUrl": "src" | ||
}, | ||
"include": ["src/**/*"], | ||
"references": [ | ||
{ | ||
"path": "../types" | ||
} | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "elite-feature-flags", | ||
"version": "1.0.0", | ||
"private": true, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"types": "dist/index.d.ts", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"clean": "rm -rf dist/ node_modules/ tsconfig.tsbuildinfo" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^16.9.11", | ||
"elite-types": "^1.0.0" | ||
}, | ||
"dependencies": { | ||
"react": "^16.12.0" | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/feature-flags/src/components/featureFlag.component.tsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { PureComponent, createContext, Context } from 'react'; | ||
import { FeatureMap } from 'elite-types'; | ||
|
||
const FeatureFlags: Context<FeatureMap> = createContext<FeatureMap>({}); | ||
|
||
export interface FeatureToggleProperties { | ||
readonly inverted?: boolean; | ||
readonly featureName: string; | ||
} | ||
|
||
export class FeatureFlag extends PureComponent<FeatureToggleProperties> { | ||
render() { | ||
const { children, inverted, featureName } = this.props; | ||
|
||
return ( | ||
<FeatureFlags.Consumer> | ||
{(featureMap: FeatureMap) => { | ||
if ((featureMap[featureName] && !inverted) || (!featureMap[featureName] && inverted)) { | ||
return children; | ||
} else { | ||
return null; | ||
} | ||
}} | ||
</FeatureFlags.Consumer> | ||
); | ||
} | ||
} | ||
|
||
export const FeatureFlagsProvider = FeatureFlags.Provider; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/featureFlag.component'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"baseUrl": "src" | ||
}, | ||
"include": ["src/**/*"], | ||
"references": [ | ||
{ | ||
"path": "../types" | ||
} | ||
] | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { FeatureMap } from './featureMap.type'; | ||
|
||
export type Configuration = { | ||
featureMap: FeatureMap; | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type FeatureMap = { [key: string]: boolean }; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './configuration.type'; | ||
export * from './featureMap.type'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './config'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Configuration } from 'elite-types'; | ||
|
||
const configuration: Configuration = { | ||
featureMap: { | ||
'under-construction-message': false, | ||
}, | ||
}; | ||
|
||
export default configuration; |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5546,7 +5546,7 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: | |
resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" | ||
integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo= | ||
|
||
minimatch@3.0.4, minimatch@^3.0.4: | ||
minimatch@^3.0.4: | ||
version "3.0.4" | ||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" | ||
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== | ||
|
@@ -7094,15 +7094,6 @@ repeating@^2.0.0: | |
dependencies: | ||
is-finite "^1.0.0" | ||
|
||
replace@^1.1.3: | ||
version "1.1.5" | ||
resolved "https://registry.yarnpkg.com/replace/-/replace-1.1.5.tgz#adac4e0cd111b57da568393cba03f3ef8fac7f96" | ||
integrity sha512-Mww6GyTix4GqN1GSbJDkUzftkjQE0xfzzlGkFF26ukm8DBzgwGPFntvmVsvAKJogwSSMjvAoZei7fJ2tfiKMcA== | ||
dependencies: | ||
chalk "2.4.2" | ||
minimatch "3.0.4" | ||
yargs "^12.0.5" | ||
|
||
request@^2.88.0: | ||
version "2.88.2" | ||
resolved "https://registry.yarnpkg.com/request/-/request-2.88.2.tgz#d73c918731cb5a87da047e207234146f664d12b3" | ||
|
@@ -8851,7 +8842,7 @@ yargs-parser@^15.0.0: | |
camelcase "^5.0.0" | ||
decamelize "^1.2.0" | ||
|
||
[email protected], yargs@^12.0.5: | ||
[email protected]: | ||
version "12.0.5" | ||
resolved "https://registry.yarnpkg.com/yargs/-/yargs-12.0.5.tgz#05f5997b609647b64f66b81e3b4b10a368e7ad13" | ||
integrity sha512-Lhz8TLaYnxq/2ObqHDql8dX8CJi97oHxrjUcYtzKbbykPtVW9WB+poxI+NM2UIzsMgNCZTIf0AQwsjK5yMAqZw== | ||
|