Skip to content

Commit 864b453

Browse files
committed
refactor: improve FeatureFlagProvider implementation
1 parent 46fa05a commit 864b453

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

packages/modules/feature-flag/src/FeatureFlagProvider.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Observable, filter, from, last, map, pairwise, reduce, switchMap } from 'rxjs';
1+
import { type Observable, filter, from, last, lastValueFrom, map, pairwise, reduce, switchMap } from 'rxjs';
22

33
import { BaseModuleProvider } from '@equinor/fusion-framework-module/provider';
44
import type { ModuleType } from '@equinor/fusion-framework-module';
@@ -186,17 +186,13 @@ export class FeatureFlagProvider
186186
filter((x): x is { key: string; enabled: boolean } => !!x),
187187
// reduce the toggle values to an array of toggle values
188188
reduce((acc, value) => acc.concat([value]), [] as Array<{ key: string; enabled: boolean }>),
189-
// take the last value
190-
last(),
191189
);
192190

193-
// subscribe to the onToggle observable
194-
const subscription = onToggle.subscribe((toggleValues) => {
195-
// dispatch the toggle values to the state
196-
this.#state.next(actions.toggleFeatures(toggleValues));
197-
});
198-
// remove the subscription when the provider is disposed
199-
subscription.add(this._addTeardown(subscription));
191+
// wait for the onToggle observable to complete and get the toggled features
192+
const toggledFeatures = await lastValueFrom(onToggle);
193+
194+
// dispatch the toggle values to the state
195+
this.#state.next(actions.toggleFeatures(toggledFeatures));
200196
}
201197

202198
public getFeature<T = unknown>(key: string): IFeatureFlag<T> | undefined {

0 commit comments

Comments
 (0)