-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feature-flags): create basic support for feature flags
- Loading branch information
1 parent
bc60be9
commit 926b571
Showing
6 changed files
with
181 additions
and
85 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
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,36 @@ | ||
import { EvaluationContext, OpenFeatureProvider, OpenFeature, InMemoryProvider } from "@openfeature/react-sdk"; | ||
import { FliptWebProvider } from "@openfeature/flipt-web-provider"; | ||
|
||
import { PropsWithChildren, useEffect } from "react"; | ||
|
||
const localFlagConfig = { | ||
"new-message": { | ||
disabled: false, | ||
variants: { | ||
on: true, | ||
off: false, | ||
}, | ||
defaultVariant: "on", | ||
contextEvaluator: (context: EvaluationContext) => { | ||
if (context.silly) { | ||
return "on"; | ||
} | ||
return "off"; | ||
}, | ||
}, | ||
}; | ||
|
||
const Provider = (props: PropsWithChildren) => { | ||
const { children } = props; | ||
useEffect(() => { | ||
const fliptProvider = new FliptWebProvider("sitrep-ui", { url: "https://flipt.sitrep.ch" }); | ||
OpenFeature.setLogger(console); | ||
OpenFeature.setProvider("local", new InMemoryProvider(localFlagConfig)); | ||
console.log("setting origin", document.location.host); | ||
OpenFeature.setProvider(fliptProvider, { domain: document.location.host.split(":")[0] }); | ||
}, []); | ||
|
||
return <OpenFeatureProvider>{children}</OpenFeatureProvider>; | ||
}; | ||
|
||
export { 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
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