JavaScript SDK
For browser based web applications.
npm add @featureboard/js-sdk
# Or
yarn add @featureboard/js-sdk
# Or
pnpm add @featureboard/js-sdk
const { client, close } = await FeatureBoardService.init('env-api-key', ['audiences', 'of', 'user'], {
/* options */
})
const featureValue = client.getFeatureValue('my-feature-key', fallbackValue)
const unsubscribe = subscribeToFeatureValue('my-feature-key', fallbackValue, (onValue) => {
// Will be called with the initial value and subsiquent updates
})
// Remove subscription
unsubscribe()
NOTE: You must specify a fallback value, this value is used when the feature is unavailable in the current environment.
The optional third argument to init
Provides the SDK with a set of initial flag values, if provided the subscription and update of the feature state will happen in the background. Allowing you to immediately use the SDK
Configure how the FeatureBoard SDK gets updated values, default 'live'
live
Connects to the FeatureBoard service using web sockets, giving near realtime updates
polling
Polls for updates using http. Default polling interval 30 seconds.
If you would like to control when feature state is updated, or not have updates just choose 'manual'
const { client, updateFeatures } = await FeatureBoardService.init('env-api-key', ['audiences', 'of', 'user'], {
updateStrategy: 'manual',
/* options */
})
// Triggers an update of the feature state
updateFeatures()
declare module '@featureboard/js-sdk' {
interface Features {
'my-feature-key': string
}
}
Last modified 1yr ago