[core/apis] adapted to build on existing data structures

This commit is contained in:
Bilawal Hameed
2020-03-27 19:45:59 +01:00
parent 6fa6373536
commit 64a14b2191
11 changed files with 387 additions and 356 deletions
+4 -7
View File
@@ -4,7 +4,7 @@ The `featureFlags` object passed to the `register` function makes it possible fo
```typescript
export type FeatureFlagsHooks = {
registerFeatureFlag(name: FeatureFlagName): void;
register(name: FeatureFlagName): void;
};
```
@@ -17,7 +17,7 @@ export default createPlugin({
id: 'welcome',
register({ router, featureFlags }) {
// router.registerRoute('/', Component);
featureFlags.registerFeatureFlag('enable-example-feature');
featureFlags.register('enable-example-feature');
},
});
```
@@ -48,11 +48,10 @@ import { Button } from '@material-ui/core';
import { featureFlagsApiRef, useApi } from '@backstage/core';
const ExampleButton: FC<{}> = () => {
const { useFeatureFlag } = useApi(featureFlagsApiRef);
const [flagState, setFlagState] = useFeatureFlag('enable-example-feature');
const flags = useApi(featureFlagsApiRef).getFlags();
const handleClick = () => {
setFlagState(FeatureFlagState.Enabled);
flags.set('enable-example-feature', FeatureFlagState.Enabled);
};
return (
@@ -63,6 +62,4 @@ const ExampleButton: FC<{}> = () => {
};
```
Note that you must register it with `registerFeatureFlag` otherwise the `useFeatureFlag` will throw an error.
[Back to References](README.md)
+1 -1
View File
@@ -33,7 +33,7 @@ import ExampleComponent from './components/ExampleComponent';
export default createPlugin({
id: 'new-plugin',
register({ router, featureFlags }) {
featureFlags.registerFeatureFlag('enable-example-component');
featureFlags.register('enable-example-component');
router.registerRoute('/new-plugin', ExampleComponent);
},