core-api: remove FeatureFlagsRegistry class

This commit is contained in:
Patrik Oldsberg
2020-10-28 17:43:43 +01:00
parent b986a73cfe
commit a9ea34404e
3 changed files with 13 additions and 52 deletions
@@ -15,7 +15,7 @@
*/
import { ApiRef, createApiRef } from '../system';
import { UserFlags, FeatureFlagsRegistry } from '../../app/FeatureFlags';
import { UserFlags } from '../../app/FeatureFlags';
/**
* The feature flags API is used to toggle functionality to users across plugins and Backstage.
@@ -46,15 +46,15 @@ export interface FeatureFlagsApi {
*/
registerFlag(flag: FeatureFlag): void;
/**
* Get a list of all registered flags.
*/
getRegisteredFlags(): FeatureFlag[];
/**
* Get a list of all feature flags from the current user.
*/
getFlags(): UserFlags;
/**
* Get a list of all registered flags.
*/
getRegisteredFlags(): FeatureFlagsRegistry;
}
export const featureFlagsApiRef: ApiRef<FeatureFlagsApi> = createApiRef({
@@ -141,11 +141,11 @@ describe('FeatureFlags', () => {
it('should return an empty list', () => {
featureFlags = new FeatureFlagsImpl();
expect(featureFlags.getRegisteredFlags().toObject()).toEqual([]);
expect(featureFlags.getRegisteredFlags()).toEqual([]);
});
it('should return an valid list', () => {
expect(featureFlags.getRegisteredFlags().toObject()).toMatchObject([
expect(featureFlags.getRegisteredFlags()).toEqual([
{ name: 'registered-flag-1', pluginId: 'plugin-one' },
{ name: 'registered-flag-2', pluginId: 'plugin-one' },
{ name: 'registered-flag-3', pluginId: 'plugin-two' },
@@ -179,7 +179,7 @@ describe('FeatureFlags', () => {
pluginId: 'plugin-three',
});
expect(flags.toObject()).toMatchObject([
expect(flags).toEqual([
{ name: 'registered-flag-1', pluginId: 'plugin-one' },
{ name: 'registered-flag-2', pluginId: 'plugin-one' },
{ name: 'registered-flag-3', pluginId: 'plugin-two' },
+4 -43
View File
@@ -126,45 +126,6 @@ export class UserFlags extends Map<string, FeatureFlagState> {
}
}
/**
* The FeatureFlagsRegistry class.
*
* This acts as a holding data structure for feature flags
* that plugins wish to register for use in Backstage.
*/
export class FeatureFlagsRegistry extends Array<FeatureFlag> {
static from(entries: FeatureFlag[]) {
Array.from(entries).forEach(entry => validateFlagName(entry.name));
return new FeatureFlagsRegistry(...entries);
}
push(...entries: FeatureFlag[]): number {
Array.from(entries).forEach(entry => validateFlagName(entry.name));
return super.push(...entries);
}
concat(
...entries: (FeatureFlag | ConcatArray<FeatureFlag>)[]
): FeatureFlag[] {
const _concat = super.concat(...entries);
Array.from(_concat).forEach(entry => validateFlagName(entry.name));
return _concat;
}
toObject() {
return [...this.values()];
}
toJSON() {
return JSON.stringify(this.toObject());
}
toString() {
return this.toJSON();
}
}
/**
* Create the FeatureFlags implementation based on the API.
*/
@@ -177,12 +138,12 @@ export class FeatureFlags implements FeatureFlagsApi {
this.registeredFeatureFlags.push(flag);
}
getRegisteredFlags(): FeatureFlag[] {
return this.registeredFeatureFlags.slice();
}
getFlags(): UserFlags {
if (!this.userFlags) this.userFlags = UserFlags.load();
return this.userFlags;
}
getRegisteredFlags(): FeatureFlagsRegistry {
return FeatureFlagsRegistry.from(this.registeredFeatureFlags);
}
}