Skip to content

Commit 86849cc

Browse files
[FSSDK-12294] review feedback addressed
1 parent 23fc3b6 commit 86849cc

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"test:coverage": "vitest run --coverage",
3636
"test:legacy": "jest --silent",
3737
"prepublishOnly": "npm run test && npm run build",
38-
"prepare": "husky"
38+
"prepare": "npm run build && husky"
3939
},
4040
"publishConfig": {
4141
"access": "public"

src/provider/ProviderStateStore.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ describe('ProviderStateStore', () => {
528528

529529
ctx.removeAllForcedDecisions();
530530

531-
// removeAll notifies per tracked key, each of which fires allListener
532-
expect(allListener).toHaveBeenCalledTimes(2);
531+
// removeAll broadcasts once (not once per key)
532+
expect(allListener).toHaveBeenCalledTimes(1);
533533
});
534534

535535
it('reset clears subscribeAllForcedDecisions listeners', () => {

src/provider/ProviderStateStore.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,31 @@ export class ProviderStateStore {
184184
}
185185

186186
/**
187-
* Notify listeners subscribed to a specific flagKey.
188-
* Also notifies "all" forced decision listeners.
189-
* Called internally by wrapped forced decision methods.
187+
* Notify listeners subscribed to a specific flagKey
188+
* and broadcast to "all" forced decision listeners.
189+
* Called by wrapped setForcedDecision / removeForcedDecision.
190190
*/
191191
notifyForcedDecision(flagKey: string): void {
192+
this.notifyPerKeyForcedDecision(flagKey);
193+
this.notifyAllForcedDecisionListeners();
194+
}
195+
196+
/**
197+
* Notify only per-key listeners (no broadcast).
198+
* Used internally by removeAllForcedDecisions to avoid
199+
* firing "all" listeners once per key.
200+
*/
201+
private notifyPerKeyForcedDecision(flagKey: string): void {
192202
const listeners = this.forcedDecisionListeners.get(flagKey);
193203
if (listeners) {
194204
listeners.forEach((cb) => cb());
195205
}
206+
}
207+
208+
/**
209+
* Notify broadcast ("all") forced decision listeners once.
210+
*/
211+
private notifyAllForcedDecisionListeners(): void {
196212
this.allForcedDecisionListeners.forEach((cb) => cb());
197213
}
198214

@@ -240,7 +256,9 @@ export class ProviderStateStore {
240256
const result = originalRemoveAll();
241257
if (result) {
242258
if (this.state.userContext === ctx) {
243-
forcedDecisionFlagKeys.forEach((flagKey) => this.notifyForcedDecision(flagKey));
259+
// Notify per-key listeners individually, then broadcast once
260+
forcedDecisionFlagKeys.forEach((flagKey) => this.notifyPerKeyForcedDecision(flagKey));
261+
this.notifyAllForcedDecisionListeners();
244262
}
245263
forcedDecisionFlagKeys.clear();
246264
}

0 commit comments

Comments
 (0)