@signaldb/core 1.2.4 → 1.3.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/dist/.vite/manifest.json +28 -47
- package/dist/index.cjs.js +12 -18
- package/dist/index.cjs10.js +6 -27
- package/dist/index.cjs11.js +3 -6
- package/dist/index.cjs12.js +136 -3
- package/dist/index.cjs13.js +40 -134
- package/dist/index.cjs14.js +5 -38
- package/dist/index.cjs15.js +42 -2
- package/dist/index.cjs16.js +11 -5
- package/dist/index.cjs17.js +17 -40
- package/dist/index.cjs18.js +262 -11
- package/dist/index.cjs19.js +66 -16
- package/dist/index.cjs2.js +688 -96
- package/dist/index.cjs20.js +71 -247
- package/dist/index.cjs21.js +8 -68
- package/dist/index.cjs22.js +22 -83
- package/dist/index.cjs23.js +144 -8
- package/dist/index.cjs24.js +5 -25
- package/dist/index.cjs25.js +16 -144
- package/dist/index.cjs26.js +27 -5
- package/dist/index.cjs27.js +39 -15
- package/dist/index.cjs28.js +25 -24
- package/dist/index.cjs29.js +7 -40
- package/dist/index.cjs3.js +139 -664
- package/dist/index.cjs4.js +62 -166
- package/dist/index.cjs5.js +3 -67
- package/dist/index.cjs6.js +2 -2
- package/dist/index.cjs7.js +2 -2
- package/dist/index.cjs8.js +2 -2
- package/dist/index.cjs9.js +27 -3
- package/dist/index.d.ts +0 -1
- package/dist/index.mjs +12 -18
- package/dist/index10.mjs +6 -27
- package/dist/index11.mjs +3 -6
- package/dist/index12.mjs +136 -3
- package/dist/index13.mjs +39 -134
- package/dist/index14.mjs +5 -37
- package/dist/index15.mjs +41 -2
- package/dist/index16.mjs +11 -5
- package/dist/index17.mjs +17 -39
- package/dist/index18.mjs +261 -11
- package/dist/index19.mjs +65 -16
- package/dist/index2.mjs +688 -94
- package/dist/index20.mjs +71 -247
- package/dist/index21.mjs +8 -67
- package/dist/index22.mjs +22 -82
- package/dist/index23.mjs +144 -8
- package/dist/index24.mjs +5 -25
- package/dist/index25.mjs +16 -144
- package/dist/index26.mjs +27 -5
- package/dist/index27.mjs +39 -15
- package/dist/index28.mjs +25 -24
- package/dist/index29.mjs +7 -40
- package/dist/index3.mjs +139 -664
- package/dist/index4.mjs +61 -166
- package/dist/index5.mjs +3 -66
- package/dist/index6.mjs +2 -2
- package/dist/index7.mjs +2 -2
- package/dist/index8.mjs +2 -2
- package/dist/index9.mjs +27 -3
- package/dist/utils/getMatchingKeys.d.ts +11 -6
- package/package.json +1 -1
- package/dist/devtools.d.ts +0 -4
- package/dist/index.cjs30.js +0 -29
- package/dist/index.cjs31.js +0 -9
- package/dist/index30.mjs +0 -30
- package/dist/index31.mjs +0 -10
package/dist/index.cjs4.js
CHANGED
|
@@ -1,173 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let triggerRemoteChange;
|
|
16
|
-
super({
|
|
17
|
-
...options,
|
|
18
|
-
pull: () => Promise.resolve({
|
|
19
|
-
items: [...this.itemsCache.values()].reduce((memo, items) => {
|
|
20
|
-
const newItems = [...memo];
|
|
21
|
-
items.forEach((item) => {
|
|
22
|
-
const index = newItems.findIndex((i) => i.id === item.id);
|
|
23
|
-
if (index === -1) {
|
|
24
|
-
newItems.push(item);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
newItems[index] = this.mergeItems(newItems[index], item);
|
|
28
|
-
});
|
|
29
|
-
return newItems;
|
|
30
|
-
}, [])
|
|
31
|
-
}),
|
|
32
|
-
registerRemoteChange: async (onChange) => {
|
|
33
|
-
triggerRemoteChange = onChange;
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const createPersistenceAdapter = require("./index.cjs7.js");
|
|
4
|
+
function createTemporaryFallbackExecutor(firstResolvingPromiseFunction, secondResolvingPromiseFunction, options) {
|
|
5
|
+
const cacheTimeout = options == null ? void 0 : options.cacheTimeout;
|
|
6
|
+
let isResolved = false;
|
|
7
|
+
let resolvedValue = null;
|
|
8
|
+
let timeout = null;
|
|
9
|
+
let secondaryPromise = null;
|
|
10
|
+
return (...args) => {
|
|
11
|
+
if (secondaryPromise == null) {
|
|
12
|
+
if (timeout) {
|
|
13
|
+
clearTimeout(timeout);
|
|
14
|
+
timeout = null;
|
|
34
15
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.purgeDelay = options.purgeDelay ?? 1e4;
|
|
49
|
-
this.isFetchingSignal = createSignal((_a = options.reactivity) == null ? void 0 : _a.create(), false);
|
|
50
|
-
if (!triggerRemoteChange)
|
|
51
|
-
throw new Error("No triggerRemoteChange method found. Looks like your persistence adapter was not registered");
|
|
52
|
-
this.triggerReload = triggerRemoteChange;
|
|
53
|
-
this.reactivityAdapter = options.reactivity ?? null;
|
|
54
|
-
this.fetchQueryItems = options.fetchQueryItems;
|
|
55
|
-
this.on("observer.created", (selector) => this.handleObserverCreation(selector ?? {}));
|
|
56
|
-
this.on("observer.disposed", (selector) => setTimeout(() => this.handleObserverDisposal(selector ?? {}), 100));
|
|
57
|
-
if (options.registerRemoteChange) {
|
|
58
|
-
void options.registerRemoteChange(() => this.forceRefetch());
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Registers a query manually that items should be fetched for it
|
|
63
|
-
* @param selector {Object} Selector of the query
|
|
64
|
-
*/
|
|
65
|
-
registerQuery(selector) {
|
|
66
|
-
this.handleObserverCreation(selector);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Unregisters a query manually that items are not fetched anymore for it
|
|
70
|
-
* @param selector {Object} Selector of the query
|
|
71
|
-
*/
|
|
72
|
-
unregisterQuery(selector) {
|
|
73
|
-
this.handleObserverDisposal(selector);
|
|
74
|
-
}
|
|
75
|
-
getKeyForSelector(selector) {
|
|
76
|
-
return JSON.stringify(selector);
|
|
77
|
-
}
|
|
78
|
-
async forceRefetch() {
|
|
79
|
-
return Promise.all([...this.activeObservers.values()].map(({ selector }) => this.fetchSelector(selector))).then(() => {
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
fetchSelector(selector) {
|
|
83
|
-
this.isFetchingSignal.set(true);
|
|
84
|
-
return this.fetchQueryItems(selector).then((response) => {
|
|
85
|
-
if (!response.items)
|
|
86
|
-
throw new Error("AutoFetchCollection currently only works with a full item response");
|
|
87
|
-
this.itemsCache.set(this.getKeyForSelector(selector), response.items);
|
|
88
|
-
response.items.forEach((item) => {
|
|
89
|
-
const queries = this.idQueryCache.get(item.id) ?? [];
|
|
90
|
-
queries.push(selector);
|
|
91
|
-
this.idQueryCache.set(item.id, queries);
|
|
92
|
-
});
|
|
93
|
-
this.setLoading(selector, true);
|
|
94
|
-
this.once("persistence.received", () => {
|
|
95
|
-
this.setLoading(selector, false);
|
|
96
|
-
});
|
|
97
|
-
if (!this.triggerReload)
|
|
98
|
-
throw new Error("No triggerReload method found. Looks like your persistence adapter was not registered");
|
|
99
|
-
void this.triggerReload();
|
|
100
|
-
}).catch((error) => {
|
|
101
|
-
this.emit("persistence.error", error);
|
|
102
|
-
}).finally(() => {
|
|
103
|
-
this.isFetchingSignal.set(false);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
handleObserverCreation(selector) {
|
|
107
|
-
var _a;
|
|
108
|
-
const activeObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
|
|
109
|
-
this.activeObservers.set(this.getKeyForSelector(selector), {
|
|
110
|
-
selector,
|
|
111
|
-
count: activeObservers + 1
|
|
112
|
-
});
|
|
113
|
-
const timeout = this.observerTimeouts.get(this.getKeyForSelector(selector));
|
|
114
|
-
if (timeout)
|
|
115
|
-
clearTimeout(timeout);
|
|
116
|
-
if (activeObservers === 0)
|
|
117
|
-
void this.fetchSelector(selector);
|
|
118
|
-
}
|
|
119
|
-
handleObserverDisposal(selector) {
|
|
120
|
-
var _a;
|
|
121
|
-
const currentObservers = ((_a = this.activeObservers.get(this.getKeyForSelector(selector))) == null ? void 0 : _a.count) ?? 0;
|
|
122
|
-
const activeObservers = currentObservers - 1;
|
|
123
|
-
if (activeObservers > 0) {
|
|
124
|
-
this.activeObservers.set(this.getKeyForSelector(selector), {
|
|
125
|
-
selector,
|
|
126
|
-
count: activeObservers
|
|
16
|
+
secondaryPromise = secondResolvingPromiseFunction(...args).then((result) => {
|
|
17
|
+
{
|
|
18
|
+
timeout = setTimeout(() => {
|
|
19
|
+
isResolved = false;
|
|
20
|
+
resolvedValue = null;
|
|
21
|
+
secondaryPromise = null;
|
|
22
|
+
}, cacheTimeout);
|
|
23
|
+
}
|
|
24
|
+
isResolved = true;
|
|
25
|
+
resolvedValue = result;
|
|
26
|
+
if (options == null ? void 0 : options.onResolve)
|
|
27
|
+
options.onResolve(resolvedValue);
|
|
28
|
+
return result;
|
|
127
29
|
});
|
|
128
|
-
|
|
30
|
+
} else if (isResolved) {
|
|
31
|
+
return secondaryPromise;
|
|
129
32
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
ensureSignal(selector) {
|
|
147
|
-
if (!this.reactivityAdapter)
|
|
148
|
-
throw new Error("No reactivity adapter found");
|
|
149
|
-
if (!this.loadingSignals.has(this.getKeyForSelector(selector))) {
|
|
150
|
-
this.loadingSignals.set(this.getKeyForSelector(selector), createSignal(this.reactivityAdapter.create(), false));
|
|
33
|
+
return firstResolvingPromiseFunction(...args);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function combinePersistenceAdapters(slowAdapter, fastAdapter) {
|
|
37
|
+
let handleChange = null;
|
|
38
|
+
const readExecutor = createTemporaryFallbackExecutor(() => fastAdapter.load(), () => slowAdapter.load(), {
|
|
39
|
+
cacheTimeout: 100,
|
|
40
|
+
onResolve: (result) => {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
if (handleChange)
|
|
43
|
+
void handleChange();
|
|
44
|
+
void fastAdapter.save(result.items || [], {
|
|
45
|
+
added: ((_a = result.changes) == null ? void 0 : _a.added) || [],
|
|
46
|
+
modified: ((_b = result.changes) == null ? void 0 : _b.modified) || [],
|
|
47
|
+
removed: ((_c = result.changes) == null ? void 0 : _c.removed) || []
|
|
48
|
+
});
|
|
151
49
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return this.isFetchingSignal.get() || isPushing;
|
|
50
|
+
});
|
|
51
|
+
return createPersistenceAdapter({
|
|
52
|
+
async register(onChange) {
|
|
53
|
+
handleChange = onChange;
|
|
54
|
+
await Promise.all([slowAdapter.register(onChange), fastAdapter.register(onChange)]);
|
|
55
|
+
},
|
|
56
|
+
async load() {
|
|
57
|
+
const promise = readExecutor();
|
|
58
|
+
return promise;
|
|
59
|
+
},
|
|
60
|
+
async save(items, changes) {
|
|
61
|
+
await Promise.all([
|
|
62
|
+
fastAdapter.save(items, changes),
|
|
63
|
+
slowAdapter.save(items, changes)
|
|
64
|
+
]);
|
|
168
65
|
}
|
|
169
|
-
|
|
170
|
-
return signal.get() || isPushing;
|
|
171
|
-
}
|
|
66
|
+
});
|
|
172
67
|
}
|
|
173
|
-
|
|
68
|
+
exports.createTemporaryFallbackExecutor = createTemporaryFallbackExecutor;
|
|
69
|
+
exports.default = combinePersistenceAdapters;
|
package/dist/index.cjs5.js
CHANGED
|
@@ -1,69 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function createTemporaryFallbackExecutor(firstResolvingPromiseFunction, secondResolvingPromiseFunction, options) {
|
|
5
|
-
const cacheTimeout = options == null ? void 0 : options.cacheTimeout;
|
|
6
|
-
let isResolved = false;
|
|
7
|
-
let resolvedValue = null;
|
|
8
|
-
let timeout = null;
|
|
9
|
-
let secondaryPromise = null;
|
|
10
|
-
return (...args) => {
|
|
11
|
-
if (secondaryPromise == null) {
|
|
12
|
-
if (timeout) {
|
|
13
|
-
clearTimeout(timeout);
|
|
14
|
-
timeout = null;
|
|
15
|
-
}
|
|
16
|
-
secondaryPromise = secondResolvingPromiseFunction(...args).then((result) => {
|
|
17
|
-
{
|
|
18
|
-
timeout = setTimeout(() => {
|
|
19
|
-
isResolved = false;
|
|
20
|
-
resolvedValue = null;
|
|
21
|
-
secondaryPromise = null;
|
|
22
|
-
}, cacheTimeout);
|
|
23
|
-
}
|
|
24
|
-
isResolved = true;
|
|
25
|
-
resolvedValue = result;
|
|
26
|
-
if (options == null ? void 0 : options.onResolve)
|
|
27
|
-
options.onResolve(resolvedValue);
|
|
28
|
-
return result;
|
|
29
|
-
});
|
|
30
|
-
} else if (isResolved) {
|
|
31
|
-
return secondaryPromise;
|
|
32
|
-
}
|
|
33
|
-
return firstResolvingPromiseFunction(...args);
|
|
34
|
-
};
|
|
2
|
+
function createIndexProvider(definition) {
|
|
3
|
+
return definition;
|
|
35
4
|
}
|
|
36
|
-
|
|
37
|
-
let handleChange = null;
|
|
38
|
-
const readExecutor = createTemporaryFallbackExecutor(() => fastAdapter.load(), () => slowAdapter.load(), {
|
|
39
|
-
cacheTimeout: 100,
|
|
40
|
-
onResolve: (result) => {
|
|
41
|
-
var _a, _b, _c;
|
|
42
|
-
if (handleChange)
|
|
43
|
-
void handleChange();
|
|
44
|
-
void fastAdapter.save(result.items || [], {
|
|
45
|
-
added: ((_a = result.changes) == null ? void 0 : _a.added) || [],
|
|
46
|
-
modified: ((_b = result.changes) == null ? void 0 : _b.modified) || [],
|
|
47
|
-
removed: ((_c = result.changes) == null ? void 0 : _c.removed) || []
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
return createPersistenceAdapter({
|
|
52
|
-
async register(onChange) {
|
|
53
|
-
handleChange = onChange;
|
|
54
|
-
await Promise.all([slowAdapter.register(onChange), fastAdapter.register(onChange)]);
|
|
55
|
-
},
|
|
56
|
-
async load() {
|
|
57
|
-
const promise = readExecutor();
|
|
58
|
-
return promise;
|
|
59
|
-
},
|
|
60
|
-
async save(items, changes) {
|
|
61
|
-
await Promise.all([
|
|
62
|
-
fastAdapter.save(items, changes),
|
|
63
|
-
slowAdapter.save(items, changes)
|
|
64
|
-
]);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
exports.createTemporaryFallbackExecutor = createTemporaryFallbackExecutor;
|
|
69
|
-
exports.default = combinePersistenceAdapters;
|
|
5
|
+
module.exports = createIndexProvider;
|
package/dist/index.cjs6.js
CHANGED
package/dist/index.cjs7.js
CHANGED
package/dist/index.cjs8.js
CHANGED
package/dist/index.cjs9.js
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
2
|
+
function isEqual(a, b) {
|
|
3
|
+
if (Object.is(a, b))
|
|
4
|
+
return true;
|
|
5
|
+
if (a instanceof RegExp && b instanceof RegExp)
|
|
6
|
+
return a.toString() === b.toString();
|
|
7
|
+
if (a instanceof Date && b instanceof Date)
|
|
8
|
+
return a.getTime() === b.getTime();
|
|
9
|
+
if (typeof a !== "object")
|
|
10
|
+
return false;
|
|
11
|
+
if (typeof b !== "object")
|
|
12
|
+
return false;
|
|
13
|
+
if (a === null)
|
|
14
|
+
return false;
|
|
15
|
+
if (b === null)
|
|
16
|
+
return false;
|
|
17
|
+
const aKeys = Object.keys(a);
|
|
18
|
+
const bKeys = Object.keys(b);
|
|
19
|
+
if (aKeys.length !== bKeys.length)
|
|
20
|
+
return false;
|
|
21
|
+
for (const key of aKeys) {
|
|
22
|
+
if (!bKeys.includes(key))
|
|
23
|
+
return false;
|
|
24
|
+
if (!isEqual(a[key], b[key]))
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
4
28
|
}
|
|
5
|
-
module.exports =
|
|
29
|
+
module.exports = isEqual;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,4 +15,3 @@ export { default as isEqual } from './utils/isEqual';
|
|
|
15
15
|
export { default as modify } from './utils/modify';
|
|
16
16
|
export { default as randomId } from './utils/randomId';
|
|
17
17
|
export { default as EventEmitter } from './utils/EventEmitter';
|
|
18
|
-
export { default as loadDeveloperTools } from './devtools';
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { default as
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { default as
|
|
6
|
-
import { default as
|
|
7
|
-
import { default as
|
|
8
|
-
import { default as
|
|
9
|
-
import { default as
|
|
10
|
-
import { default as
|
|
11
|
-
import { default as
|
|
12
|
-
import { default as
|
|
13
|
-
import { default as default13 } from "./index14.mjs";
|
|
14
|
-
/* istanbul ignore if -- @preserve */
|
|
15
|
-
if (process.env.NODE_ENV !== "production") {
|
|
16
|
-
loadDeveloperTools();
|
|
17
|
-
}
|
|
1
|
+
import { default as default2 } from "./index2.mjs";
|
|
2
|
+
import { default as default3 } from "./index3.mjs";
|
|
3
|
+
import { default as default4 } from "./index4.mjs";
|
|
4
|
+
import { default as default5 } from "./index5.mjs";
|
|
5
|
+
import { default as default6 } from "./index6.mjs";
|
|
6
|
+
import { default as default7 } from "./index7.mjs";
|
|
7
|
+
import { default as default8 } from "./index8.mjs";
|
|
8
|
+
import { default as default9 } from "./index9.mjs";
|
|
9
|
+
import { default as default10 } from "./index10.mjs";
|
|
10
|
+
import { default as default11 } from "./index11.mjs";
|
|
11
|
+
import { default as default12 } from "./index12.mjs";
|
|
12
|
+
import { default as default13 } from "./index13.mjs";
|
|
18
13
|
export {
|
|
19
14
|
default3 as AutoFetchCollection,
|
|
20
15
|
default2 as Collection,
|
|
@@ -26,7 +21,6 @@ export {
|
|
|
26
21
|
default7 as createPersistenceAdapter,
|
|
27
22
|
default8 as createReactivityAdapter,
|
|
28
23
|
default9 as isEqual,
|
|
29
|
-
loadDeveloperTools,
|
|
30
24
|
default10 as modify,
|
|
31
25
|
default11 as randomId
|
|
32
26
|
};
|
package/dist/index10.mjs
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (a instanceof Date && b instanceof Date)
|
|
7
|
-
return a.getTime() === b.getTime();
|
|
8
|
-
if (typeof a !== "object")
|
|
9
|
-
return false;
|
|
10
|
-
if (typeof b !== "object")
|
|
11
|
-
return false;
|
|
12
|
-
if (a === null)
|
|
13
|
-
return false;
|
|
14
|
-
if (b === null)
|
|
15
|
-
return false;
|
|
16
|
-
const aKeys = Object.keys(a);
|
|
17
|
-
const bKeys = Object.keys(b);
|
|
18
|
-
if (aKeys.length !== bKeys.length)
|
|
19
|
-
return false;
|
|
20
|
-
for (const key of aKeys) {
|
|
21
|
-
if (!bKeys.includes(key))
|
|
22
|
-
return false;
|
|
23
|
-
if (!isEqual(a[key], b[key]))
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
1
|
+
import { update } from "mingo";
|
|
2
|
+
function modify(item, modifier) {
|
|
3
|
+
const clonedItem = { ...item };
|
|
4
|
+
update(clonedItem, modifier);
|
|
5
|
+
return clonedItem;
|
|
27
6
|
}
|
|
28
7
|
export {
|
|
29
|
-
|
|
8
|
+
modify as default
|
|
30
9
|
};
|
package/dist/index11.mjs
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const clonedItem = { ...item };
|
|
4
|
-
update(clonedItem, modifier);
|
|
5
|
-
return clonedItem;
|
|
1
|
+
function randomId() {
|
|
2
|
+
return Math.floor(Math.random() * 1e17).toString(16);
|
|
6
3
|
}
|
|
7
4
|
export {
|
|
8
|
-
|
|
5
|
+
randomId as default
|
|
9
6
|
};
|
package/dist/index12.mjs
CHANGED
|
@@ -1,6 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
class EventEmitter {
|
|
5
|
+
constructor() {
|
|
6
|
+
__publicField(this, "_maxListeners", 100);
|
|
7
|
+
/**
|
|
8
|
+
* We store a set of the listeners for each event.
|
|
9
|
+
*/
|
|
10
|
+
__publicField(this, "_listenerStore", /* @__PURE__ */ new Map());
|
|
11
|
+
}
|
|
12
|
+
setMaxListeners(max) {
|
|
13
|
+
this._maxListeners = max;
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Subscribe to an event with a listener function.
|
|
18
|
+
* @param eventName The event name (key of E).
|
|
19
|
+
* @param listener A function that receives the emitted arguments.
|
|
20
|
+
* @returns The emitter instance (for chaining).
|
|
21
|
+
*/
|
|
22
|
+
on(eventName, listener) {
|
|
23
|
+
let listenersSet = this._listenerStore.get(eventName);
|
|
24
|
+
if (!listenersSet) {
|
|
25
|
+
listenersSet = /* @__PURE__ */ new Set();
|
|
26
|
+
this._listenerStore.set(eventName, listenersSet);
|
|
27
|
+
}
|
|
28
|
+
listenersSet.add(listener);
|
|
29
|
+
if (listenersSet.size > this._maxListeners) {
|
|
30
|
+
console.warn(`Possible EventEmitter memory leak detected. ${listenersSet.size} ${String(eventName)} listeners added. Use emitter.setMaxListeners() to increase limit.`);
|
|
31
|
+
}
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Subscribe to an event with a listener function.
|
|
36
|
+
* @param eventName The event name (key of E).
|
|
37
|
+
* @param listener A function that receives the emitted arguments.
|
|
38
|
+
* @returns The emitter instance (for chaining).
|
|
39
|
+
*/
|
|
40
|
+
addListener(eventName, listener) {
|
|
41
|
+
return this.on(eventName, listener);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Subscribe to an event, handling it only once. Automatically removes
|
|
45
|
+
* the listener after it fires the first time.
|
|
46
|
+
* @param eventName The event name (key of E).
|
|
47
|
+
* @param listener A function that receives the emitted arguments.
|
|
48
|
+
* @returns The emitter instance (for chaining).
|
|
49
|
+
*/
|
|
50
|
+
once(eventName, listener) {
|
|
51
|
+
const onceWrapper = (...args) => {
|
|
52
|
+
listener(...args);
|
|
53
|
+
this.off(eventName, onceWrapper);
|
|
54
|
+
};
|
|
55
|
+
return this.on(eventName, onceWrapper);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Unsubscribe a previously subscribed listener.
|
|
59
|
+
* @param eventName The event name (key of E).
|
|
60
|
+
* @param listener The original function passed to `on` or `once`.
|
|
61
|
+
* @returns The emitter instance (for chaining).
|
|
62
|
+
*/
|
|
63
|
+
off(eventName, listener) {
|
|
64
|
+
const listenersSet = this._listenerStore.get(eventName);
|
|
65
|
+
if (!listenersSet)
|
|
66
|
+
return this;
|
|
67
|
+
listenersSet.delete(listener);
|
|
68
|
+
if (listenersSet.size === 0) {
|
|
69
|
+
this._listenerStore.delete(eventName);
|
|
70
|
+
}
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Unsubscribe a previously subscribed listener.
|
|
75
|
+
* @param eventName The event name (key of E).
|
|
76
|
+
* @param listener The original function passed to `on` or `once`.
|
|
77
|
+
* @returns The emitter instance (for chaining).
|
|
78
|
+
*/
|
|
79
|
+
removeListener(eventName, listener) {
|
|
80
|
+
return this.off(eventName, listener);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Emit (dispatch) an event with a variable number of arguments.
|
|
84
|
+
* @param eventName The event name (key of E).
|
|
85
|
+
* @param args The arguments to pass to subscribed listeners.
|
|
86
|
+
*/
|
|
87
|
+
emit(eventName, ...args) {
|
|
88
|
+
this.listeners(eventName).forEach((listener) => {
|
|
89
|
+
listener(...args);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns the array of listener functions currently registered for a given event.
|
|
94
|
+
* @param eventName The event name (key of E).
|
|
95
|
+
* @returns An array of listener functions.
|
|
96
|
+
*/
|
|
97
|
+
listeners(eventName) {
|
|
98
|
+
const listenersSet = this._listenerStore.get(eventName);
|
|
99
|
+
if (!listenersSet)
|
|
100
|
+
return [];
|
|
101
|
+
return [...listenersSet.values()];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns the number of listeners for a given event.
|
|
105
|
+
* @param eventName The event name (key of E).
|
|
106
|
+
* @returns The number of listeners.
|
|
107
|
+
*/
|
|
108
|
+
listenerCount(eventName) {
|
|
109
|
+
const listenersSet = this._listenerStore.get(eventName);
|
|
110
|
+
return listenersSet ? listenersSet.size : 0;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Removes all listeners for a given event, or all events if none is specified.
|
|
114
|
+
* @param eventName Optional. If omitted, clears all events’ listeners.
|
|
115
|
+
* @returns The emitter instance (for chaining).
|
|
116
|
+
*/
|
|
117
|
+
removeAllListeners(eventName) {
|
|
118
|
+
if (eventName === void 0) {
|
|
119
|
+
for (const [eventName_, listenersSet] of this._listenerStore.entries()) {
|
|
120
|
+
for (const listener of listenersSet.values()) {
|
|
121
|
+
this.off(eventName_, listener);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this._listenerStore.clear();
|
|
125
|
+
} else {
|
|
126
|
+
const listenersSet = this._listenerStore.get(eventName);
|
|
127
|
+
if (listenersSet) {
|
|
128
|
+
for (const listener of listenersSet.values()) {
|
|
129
|
+
this.off(eventName, listener);
|
|
130
|
+
}
|
|
131
|
+
this._listenerStore.delete(eventName);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
3
136
|
}
|
|
4
137
|
export {
|
|
5
|
-
|
|
138
|
+
EventEmitter as default
|
|
6
139
|
};
|