@launchdarkly/js-client-sdk-common 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/api/LDEmitter.d.ts +4 -21
- package/dist/api/LDEmitter.d.ts.map +1 -1
- package/dist/api/LDEmitter.js +16 -40
- package/dist/api/LDEmitter.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.4.0](https://github.com/launchdarkly/js-core/compare/js-client-sdk-common-v1.3.0...js-client-sdk-common-v1.4.0) (2024-08-15)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* Remove event target shim. ([#545](https://github.com/launchdarkly/js-core/issues/545)) ([448ad67](https://github.com/launchdarkly/js-core/commit/448ad67815b9ec29abd322ed8483b2367147b146)), closes [#412](https://github.com/launchdarkly/js-core/issues/412)
|
|
9
|
+
|
|
3
10
|
## [1.3.0](https://github.com/launchdarkly/js-core/compare/js-client-sdk-common-v1.2.0...js-client-sdk-common-v1.3.0) (2024-08-12)
|
|
4
11
|
|
|
5
12
|
|
package/dist/api/LDEmitter.d.ts
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
|
+
import { LDLogger } from '@launchdarkly/js-sdk-common';
|
|
1
2
|
export type EventName = 'error' | 'change';
|
|
2
|
-
/**
|
|
3
|
-
* Native api usage: EventTarget.
|
|
4
|
-
*
|
|
5
|
-
* This is an event emitter using the standard built-in EventTarget web api.
|
|
6
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
|
|
7
|
-
*
|
|
8
|
-
* In react-native use event-target-shim to polyfill EventTarget. This is safe
|
|
9
|
-
* because the react-native repo uses it too.
|
|
10
|
-
* https://github.com/mysticatea/event-target-shim
|
|
11
|
-
*/
|
|
12
3
|
export default class LDEmitter {
|
|
13
|
-
private
|
|
4
|
+
private logger?;
|
|
14
5
|
private listeners;
|
|
15
|
-
|
|
16
|
-
* Cache all listeners in a Map so we can remove them later
|
|
17
|
-
* @param name string event name
|
|
18
|
-
* @param originalListener pointer to the original function as specified by
|
|
19
|
-
* the consumer
|
|
20
|
-
* @param customListener pointer to the custom function based on original
|
|
21
|
-
* listener. This is needed to allow for CustomEvents.
|
|
22
|
-
* @private
|
|
23
|
-
*/
|
|
24
|
-
private saveListener;
|
|
6
|
+
constructor(logger?: LDLogger | undefined);
|
|
25
7
|
on(name: EventName, listener: Function): void;
|
|
26
8
|
/**
|
|
27
9
|
* Unsubscribe one or all events.
|
|
@@ -30,6 +12,7 @@ export default class LDEmitter {
|
|
|
30
12
|
* @param listener Optional. If unspecified, all listeners for the event will be removed.
|
|
31
13
|
*/
|
|
32
14
|
off(name: EventName, listener?: Function): void;
|
|
15
|
+
private invokeListener;
|
|
33
16
|
emit(name: EventName, ...detail: any[]): void;
|
|
34
17
|
eventNames(): string[];
|
|
35
18
|
listenerCount(name: EventName): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LDEmitter.d.ts","sourceRoot":"","sources":["../../src/api/LDEmitter.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"LDEmitter.d.ts","sourceRoot":"","sources":["../../src/api/LDEmitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,SAAS;IAGhB,OAAO,CAAC,MAAM,CAAC;IAF3B,OAAO,CAAC,SAAS,CAAyC;gBAEtC,MAAM,CAAC,sBAAU;IAErC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ;IAQtC;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,QAAQ;IAqBxC,OAAO,CAAC,cAAc;IAQtB,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE;IAKtC,UAAU,IAAI,MAAM,EAAE;IAItB,aAAa,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM;CAGvC"}
|
package/dist/api/LDEmitter.js
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Native api usage: EventTarget.
|
|
5
|
-
*
|
|
6
|
-
* This is an event emitter using the standard built-in EventTarget web api.
|
|
7
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
|
|
8
|
-
*
|
|
9
|
-
* In react-native use event-target-shim to polyfill EventTarget. This is safe
|
|
10
|
-
* because the react-native repo uses it too.
|
|
11
|
-
* https://github.com/mysticatea/event-target-shim
|
|
12
|
-
*/
|
|
13
3
|
class LDEmitter {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.
|
|
4
|
+
constructor(logger) {
|
|
5
|
+
this.logger = logger;
|
|
16
6
|
this.listeners = new Map();
|
|
17
7
|
}
|
|
18
|
-
|
|
19
|
-
* Cache all listeners in a Map so we can remove them later
|
|
20
|
-
* @param name string event name
|
|
21
|
-
* @param originalListener pointer to the original function as specified by
|
|
22
|
-
* the consumer
|
|
23
|
-
* @param customListener pointer to the custom function based on original
|
|
24
|
-
* listener. This is needed to allow for CustomEvents.
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
saveListener(name, originalListener, customListener) {
|
|
8
|
+
on(name, listener) {
|
|
28
9
|
var _a;
|
|
29
|
-
const listener = { original: originalListener, custom: customListener };
|
|
30
10
|
if (!this.listeners.has(name)) {
|
|
31
11
|
this.listeners.set(name, [listener]);
|
|
32
12
|
}
|
|
@@ -34,15 +14,6 @@ class LDEmitter {
|
|
|
34
14
|
(_a = this.listeners.get(name)) === null || _a === void 0 ? void 0 : _a.push(listener);
|
|
35
15
|
}
|
|
36
16
|
}
|
|
37
|
-
on(name, listener) {
|
|
38
|
-
const customListener = (e) => {
|
|
39
|
-
const { detail } = e;
|
|
40
|
-
// invoke listener with args from CustomEvent
|
|
41
|
-
listener(...detail);
|
|
42
|
-
};
|
|
43
|
-
this.saveListener(name, listener, customListener);
|
|
44
|
-
this.et.addEventListener(name, customListener);
|
|
45
|
-
}
|
|
46
17
|
/**
|
|
47
18
|
* Unsubscribe one or all events.
|
|
48
19
|
*
|
|
@@ -55,10 +26,8 @@ class LDEmitter {
|
|
|
55
26
|
return;
|
|
56
27
|
}
|
|
57
28
|
if (listener) {
|
|
58
|
-
const toBeRemoved = existingListeners.find((c) => c.original === listener);
|
|
59
|
-
this.et.removeEventListener(name, toBeRemoved === null || toBeRemoved === void 0 ? void 0 : toBeRemoved.custom);
|
|
60
29
|
// remove from internal cache
|
|
61
|
-
const updated = existingListeners.filter((
|
|
30
|
+
const updated = existingListeners.filter((fn) => fn !== listener);
|
|
62
31
|
if (updated.length === 0) {
|
|
63
32
|
this.listeners.delete(name);
|
|
64
33
|
}
|
|
@@ -67,14 +36,21 @@ class LDEmitter {
|
|
|
67
36
|
}
|
|
68
37
|
return;
|
|
69
38
|
}
|
|
70
|
-
// remove all
|
|
71
|
-
existingListeners.forEach((l) => {
|
|
72
|
-
this.et.removeEventListener(name, l.custom);
|
|
73
|
-
});
|
|
39
|
+
// listener was not specified, so remove them all for that event
|
|
74
40
|
this.listeners.delete(name);
|
|
75
41
|
}
|
|
42
|
+
invokeListener(listener, name, ...detail) {
|
|
43
|
+
var _a;
|
|
44
|
+
try {
|
|
45
|
+
listener(...detail);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(`Encountered error invoking handler for "${name}", detail: "${err}"`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
76
51
|
emit(name, ...detail) {
|
|
77
|
-
this.
|
|
52
|
+
const listeners = this.listeners.get(name);
|
|
53
|
+
listeners === null || listeners === void 0 ? void 0 : listeners.forEach((listener) => this.invokeListener(listener, name, ...detail));
|
|
78
54
|
}
|
|
79
55
|
eventNames() {
|
|
80
56
|
return [...this.listeners.keys()];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LDEmitter.js","sourceRoot":"","sources":["../../src/api/LDEmitter.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"LDEmitter.js","sourceRoot":"","sources":["../../src/api/LDEmitter.ts"],"names":[],"mappings":";;AAIA,MAAqB,SAAS;IAG5B,YAAoB,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;QAF7B,cAAS,GAA+B,IAAI,GAAG,EAAE,CAAC;IAElB,CAAC;IAEzC,EAAE,CAAC,IAAe,EAAE,QAAkB;;QACpC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YAC7B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;SACtC;aAAM;YACL,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,0CAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC1C;IACH,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,IAAe,EAAE,QAAmB;QACtC,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,iBAAiB,EAAE;YACtB,OAAO;SACR;QAED,IAAI,QAAQ,EAAE;YACZ,6BAA6B;YAC7B,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC;YAClE,IAAI,OAAO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