@plitzi/sdk-event-bridge 0.37.2 → 0.37.3
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 +1149 -0
- package/dist/EventBridge.d.ts +11 -1
- package/dist/EventBridge.mjs +13 -10
- package/dist/hooks/useEventBridge.mjs +12 -12
- package/package.json +7 -4
package/dist/EventBridge.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ export type Event<T = unknown> = {
|
|
|
9
9
|
filter?: EventBridgeParams<T>['filter'];
|
|
10
10
|
};
|
|
11
11
|
export type EventBridgeProps<T = unknown> = {
|
|
12
|
-
|
|
12
|
+
/** What the bridge starts with — as it holds them: only the modules, and the events, that have a listener. */
|
|
13
|
+
events?: Partial<Record<EventBridgeModule, Partial<Record<EventBridgeEvent, Event<T>[]>>>>;
|
|
13
14
|
debugMode?: boolean;
|
|
14
15
|
};
|
|
15
16
|
type EventBridgeUpdateListener = (events: Record<EventBridgeEvent, unknown>) => void;
|
|
@@ -17,6 +18,15 @@ declare class EventBridge<T = unknown> {
|
|
|
17
18
|
debugMode: boolean;
|
|
18
19
|
events: Partial<Record<EventBridgeModule, Partial<Record<EventBridgeEvent, Event<T>[]>>>>;
|
|
19
20
|
private listeners;
|
|
21
|
+
/**
|
|
22
|
+
* How many events each module holds, kept beside `events` so emptying one is a count and not a walk.
|
|
23
|
+
*
|
|
24
|
+
* A module holds one event per element (`interaction`, `element`), and every element that unmounts removes its own.
|
|
25
|
+
* Asking the object whether it had keys left was a walk over all of them — `for…in` still enumerates every key of an
|
|
26
|
+
* object that constant deletions have turned into a dictionary — so tearing down, or re-subscribing, a page of N
|
|
27
|
+
* elements cost N × N: a third of a busy frame on a board with a few hundred elements.
|
|
28
|
+
*/
|
|
29
|
+
private counts;
|
|
20
30
|
constructor({ events, debugMode }?: EventBridgeProps<T> | undefined);
|
|
21
31
|
has(module: EventBridgeModule, event: EventBridgeEvent): Event<T>[] | undefined;
|
|
22
32
|
on(module: EventBridgeModule, event: EventBridgeEvent, callback?: EventBridgeCallback<T>, params?: EventBridgeParams<T>): void;
|
package/dist/EventBridge.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { pConsole as e } from "@plitzi/sdk-shared/devTools/utils/PlitziConsole";
|
|
2
2
|
//#region src/EventBridge.ts
|
|
3
|
-
var t =
|
|
4
|
-
for (let t in e) if (Object.hasOwn(e, t)) return !0;
|
|
5
|
-
return !1;
|
|
6
|
-
}, n = class {
|
|
3
|
+
var t = class {
|
|
7
4
|
debugMode = !1;
|
|
8
5
|
events;
|
|
9
6
|
listeners = /* @__PURE__ */ new Map();
|
|
7
|
+
counts = /* @__PURE__ */ new Map();
|
|
10
8
|
constructor({ events: e, debugMode: t = !1 } = {}) {
|
|
11
9
|
this.events = e ?? {}, this.debugMode = t;
|
|
10
|
+
for (let [e, t] of Object.entries(this.events)) this.counts.set(e, Object.keys(t).length);
|
|
12
11
|
}
|
|
13
12
|
has(e, t) {
|
|
14
13
|
if (!e) throw Error("Module name is required");
|
|
@@ -18,7 +17,7 @@ var t = (e) => {
|
|
|
18
17
|
let { filter: i, override: a = !1 } = r;
|
|
19
18
|
if (!e) throw Error("Module name is required");
|
|
20
19
|
if (!n || typeof n != "function") throw Error("Callback must be a function");
|
|
21
|
-
this.events[e] || (this.events[e] = {}), (!this.events[e][t] || a && this.events[e][t].length > 0) && (this.events[e][t] = []), this.events[e][t].push({
|
|
20
|
+
this.events[e] || (this.events[e] = {}), this.events[e][t] || this.counts.set(e, (this.counts.get(e) ?? 0) + 1), (!this.events[e][t] || a && this.events[e][t].length > 0) && (this.events[e][t] = []), this.events[e][t].push({
|
|
22
21
|
callback: n,
|
|
23
22
|
filter: i
|
|
24
23
|
});
|
|
@@ -26,8 +25,12 @@ var t = (e) => {
|
|
|
26
25
|
get(e, t) {
|
|
27
26
|
return this.has(e, t) ? this.events[e]?.[t] : [];
|
|
28
27
|
}
|
|
29
|
-
off(e,
|
|
30
|
-
this.has(e,
|
|
28
|
+
off(e, t, n) {
|
|
29
|
+
if (this.has(e, t) && this.events[e] && (n ? this.events[e][t] = this.events[e][t]?.filter((e) => e.callback !== n) : this.events[e][t] = [], this.events[e][t]?.length === 0)) {
|
|
30
|
+
delete this.events[e][t];
|
|
31
|
+
let n = (this.counts.get(e) ?? 1) - 1;
|
|
32
|
+
n > 0 ? this.counts.set(e, n) : (this.counts.delete(e), delete this.events[e]);
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
async emit(t, n = [], ...r) {
|
|
33
36
|
this.debugMode && e.info("eventBridge", "Event Triggered", {
|
|
@@ -68,10 +71,10 @@ var t = (e) => {
|
|
|
68
71
|
}
|
|
69
72
|
clear(e) {
|
|
70
73
|
if (!e) {
|
|
71
|
-
this.events = {};
|
|
74
|
+
this.events = {}, this.counts.clear();
|
|
72
75
|
return;
|
|
73
76
|
}
|
|
74
|
-
this.events[e] && delete this.events[e];
|
|
77
|
+
this.events[e] && (delete this.events[e], this.counts.delete(e));
|
|
75
78
|
}
|
|
76
79
|
getEvents(e) {
|
|
77
80
|
return e ? this.events[e] ? this.events[e] : {} : this.events;
|
|
@@ -101,4 +104,4 @@ var t = (e) => {
|
|
|
101
104
|
}
|
|
102
105
|
};
|
|
103
106
|
//#endregion
|
|
104
|
-
export {
|
|
107
|
+
export { t as default };
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import e from "../EventBridgeContext.mjs";
|
|
2
2
|
import { use as t, useEffect as n } from "react";
|
|
3
3
|
//#region src/hooks/useEventBridge.ts
|
|
4
|
-
var r = (
|
|
5
|
-
let { eventBridge:
|
|
4
|
+
var r = Object.freeze({}), i = Object.freeze({}), a = (a, o = r, s = i, c = e, l = !1) => {
|
|
5
|
+
let { eventBridge: u } = t(c);
|
|
6
6
|
return n(() => {
|
|
7
|
-
if (
|
|
8
|
-
let e = Object.entries(
|
|
9
|
-
for (let [t, n] of e) typeof n == "function" &&
|
|
7
|
+
if (l || !u || !a) return;
|
|
8
|
+
let e = Object.entries(o);
|
|
9
|
+
for (let [t, n] of e) typeof n == "function" && u.on(a, t, n, s);
|
|
10
10
|
return () => {
|
|
11
|
-
for (let [t, n] of e) typeof n == "function" &&
|
|
11
|
+
for (let [t, n] of e) typeof n == "function" && u.off(a, t, n);
|
|
12
12
|
};
|
|
13
13
|
}, [
|
|
14
|
-
r,
|
|
15
|
-
i,
|
|
16
|
-
c,
|
|
17
14
|
a,
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
o,
|
|
16
|
+
u,
|
|
17
|
+
s,
|
|
18
|
+
l
|
|
19
|
+
]), u;
|
|
20
20
|
};
|
|
21
21
|
//#endregion
|
|
22
|
-
export {
|
|
22
|
+
export { a as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-event-bridge",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.3",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -40,17 +40,20 @@
|
|
|
40
40
|
"typecheck": "tsc -p tsconfig.app.json --noEmit",
|
|
41
41
|
"build:dev": "vite build --mode development --minify false && node ../sdk-shared/scripts/generate-exports.mjs",
|
|
42
42
|
"build:dev-watch": "vite build --mode development --watch --minify false",
|
|
43
|
-
"build:prod": "vite build && node ../sdk-shared/scripts/generate-exports.mjs"
|
|
43
|
+
"build:prod": "vite build && node ../sdk-shared/scripts/generate-exports.mjs",
|
|
44
|
+
"test": "vitest run"
|
|
44
45
|
},
|
|
45
46
|
"type": "module",
|
|
46
47
|
"sideEffects": false,
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"@plitzi/sdk-shared": "0.37.
|
|
49
|
+
"@plitzi/sdk-shared": "0.37.3",
|
|
49
50
|
"prop-types": "^15.8.1"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
53
|
+
"@testing-library/react": "^16.3.3",
|
|
52
54
|
"eslint": "^9.39.5",
|
|
53
55
|
"typescript": "^6.0.3",
|
|
54
|
-
"vite": "^8.3.
|
|
56
|
+
"vite": "^8.3.1",
|
|
57
|
+
"vitest": "^5.0.1"
|
|
55
58
|
}
|
|
56
59
|
}
|