Skip to content

Commit 71caed5

Browse files
committed
Fix event tests. Add developer notes.
1 parent 1dedc7c commit 71caed5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/shared/sdk-client/__tests__/LDClientImpl.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ describe('sdk-client object', () => {
268268
const carContext2: LDContext = { kind: 'car', key: 'test-car-2' };
269269
await ldc.identify(carContext2);
270270

271-
expect(emitter.listenerCount('change')).toEqual(1);
271+
// No default listeners. This is important for clients to be able to determine if there are
272+
// any listeners and act on that information.
273+
expect(emitter.listenerCount('change')).toEqual(0);
272274
expect(emitter.listenerCount('error')).toEqual(1);
273275
});
274276

packages/shared/sdk-client/src/LDEmitter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { LDLogger } from '@launchdarkly/js-sdk-common';
22

33
export type EventName = 'error' | 'change';
44

5+
/**
6+
* Implementation Note: There should not be any default listeners for change events in a client
7+
* implementation. Default listeners mean a client cannot determine when there are actual
8+
* application developer provided listeners. If we require default listeners, then we should add
9+
* a system to allow listeners which have counts independent of the primary listener counts.
10+
*/
511
export default class LDEmitter {
612
private listeners: Map<EventName, Function[]> = new Map();
713

0 commit comments

Comments
 (0)