wenay-common2 1.0.48 → 1.0.49

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.
@@ -0,0 +1,381 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStore = createStore;
4
+ exports.exposeStore = exposeStore;
5
+ exports.createStoreMirror = createStoreMirror;
6
+ const reactive2_1 = require("./reactive2");
7
+ const hasSetImmediate = typeof setImmediate == "function";
8
+ function pathKey(path) {
9
+ return path.map(String).join(".");
10
+ }
11
+ function schedule(drain, flush) {
12
+ if (drain == null) {
13
+ flush();
14
+ return;
15
+ }
16
+ if (drain == "micro") {
17
+ queueMicrotask(flush);
18
+ return;
19
+ }
20
+ if (drain == "immediate") {
21
+ (hasSetImmediate ? setImmediate : setTimeout)(flush, 0);
22
+ return;
23
+ }
24
+ if (typeof drain == "number") {
25
+ setTimeout(flush, drain);
26
+ return;
27
+ }
28
+ drain(flush);
29
+ }
30
+ function createDrained(fn, drain) {
31
+ let scheduled = false;
32
+ let latest = null;
33
+ let closed = false;
34
+ return {
35
+ push(...a) {
36
+ if (closed)
37
+ return;
38
+ if (drain == null) {
39
+ fn(...a);
40
+ return;
41
+ }
42
+ latest = a;
43
+ if (scheduled)
44
+ return;
45
+ scheduled = true;
46
+ schedule(drain, () => {
47
+ scheduled = false;
48
+ const x = latest;
49
+ latest = null;
50
+ if (!closed && x)
51
+ fn(...x);
52
+ });
53
+ },
54
+ close() { closed = true; latest = null; },
55
+ };
56
+ }
57
+ function isObj(v) {
58
+ return v != null && typeof v == "object";
59
+ }
60
+ function getAt(root, path) {
61
+ let cur = root;
62
+ for (const k of path) {
63
+ if (!isObj(cur))
64
+ return undefined;
65
+ cur = cur[k];
66
+ }
67
+ return cur;
68
+ }
69
+ function hasAt(root, path) {
70
+ let cur = root;
71
+ for (const k of path) {
72
+ if (!isObj(cur) || !(k in cur))
73
+ return false;
74
+ cur = cur[k];
75
+ }
76
+ return true;
77
+ }
78
+ function ensureParent(root, path) {
79
+ let cur = root;
80
+ for (let i = 0; i < path.length - 1; i++) {
81
+ const k = path[i];
82
+ if (!isObj(cur[k]))
83
+ cur[k] = {};
84
+ cur = cur[k];
85
+ }
86
+ return cur;
87
+ }
88
+ function replaceRoot(root, value) {
89
+ for (const k of Reflect.ownKeys(root))
90
+ if (!isObj(value) || !(k in value))
91
+ delete root[k];
92
+ if (isObj(value))
93
+ for (const k of Reflect.ownKeys(value))
94
+ root[k] = value[k];
95
+ }
96
+ function setAt(root, path, value) {
97
+ if (path.length == 0) {
98
+ replaceRoot(root, value);
99
+ return;
100
+ }
101
+ const p = ensureParent(root, path);
102
+ p[path[path.length - 1]] = value;
103
+ }
104
+ function snapshotValue(value, seen = new WeakMap()) {
105
+ if (!isObj(value))
106
+ return value;
107
+ if (value instanceof Date)
108
+ return new Date(value.valueOf());
109
+ if (value instanceof RegExp)
110
+ return new RegExp(value.source, value.flags);
111
+ if (value instanceof Map) {
112
+ const out = new Map();
113
+ seen.set(value, out);
114
+ value.forEach((v, k) => out.set(snapshotValue(k, seen), snapshotValue(v, seen)));
115
+ return out;
116
+ }
117
+ if (value instanceof Set) {
118
+ const out = new Set();
119
+ seen.set(value, out);
120
+ value.forEach(v => out.add(snapshotValue(v, seen)));
121
+ return out;
122
+ }
123
+ const old = seen.get(value);
124
+ if (old)
125
+ return old;
126
+ const out = Array.isArray(value) ? [] : {};
127
+ seen.set(value, out);
128
+ for (const k of Reflect.ownKeys(value))
129
+ out[k] = snapshotValue(value[k], seen);
130
+ return out;
131
+ }
132
+ function maskPaths(mask, base = []) {
133
+ if (mask === true || mask == null)
134
+ return [base];
135
+ if (!isObj(mask))
136
+ return [base];
137
+ const out = [];
138
+ for (const k of Object.keys(mask))
139
+ out.push(...maskPaths(mask[k], [...base, k]));
140
+ return out;
141
+ }
142
+ function pickSnapshot(root, mask, base = []) {
143
+ if (mask === true || mask == null)
144
+ return snapshotValue(getAt(root, base));
145
+ const out = {};
146
+ for (const k of Object.keys(mask))
147
+ out[k] = pickSnapshot(root, mask[k], [...base, k]);
148
+ return out;
149
+ }
150
+ function applyMask(root, mask, data, base = []) {
151
+ if (mask === true || mask == null) {
152
+ setAt(root, base, snapshotValue(data));
153
+ return;
154
+ }
155
+ for (const k of Object.keys(mask))
156
+ applyMask(root, mask[k], data?.[k], [...base, k]);
157
+ }
158
+ function watchTarget(root, path) {
159
+ let cur = root;
160
+ let lastReactive = root;
161
+ for (const k of path) {
162
+ if (!isObj(cur) || !(k in cur))
163
+ return lastReactive;
164
+ const next = cur[k];
165
+ if ((0, reactive2_1.isReactive)(next)) {
166
+ cur = next;
167
+ lastReactive = next;
168
+ }
169
+ else
170
+ return lastReactive;
171
+ }
172
+ return lastReactive;
173
+ }
174
+ function sameLeaf(a, b, ae, be) {
175
+ if (ae !== be)
176
+ return false;
177
+ if (!ae && !be)
178
+ return true;
179
+ return Object.is(a, b);
180
+ }
181
+ function makeCtx(store, path) {
182
+ return {
183
+ store,
184
+ node: getNode(store, path),
185
+ path: [...path],
186
+ pathString: pathKey(path),
187
+ exists: hasAt(store._state, path),
188
+ };
189
+ }
190
+ function incCount(store, path) {
191
+ const k = pathKey(path);
192
+ store._counts.set(k, (store._counts.get(k) ?? 0) + 1);
193
+ }
194
+ function decCount(store, path) {
195
+ const k = pathKey(path);
196
+ const n = (store._counts.get(k) ?? 0) - 1;
197
+ if (n > 0)
198
+ store._counts.set(k, n);
199
+ else
200
+ store._counts.delete(k);
201
+ }
202
+ function subscribePath(store, path, cb, opts = {}, once = false) {
203
+ let done = false;
204
+ let offUpdate = null;
205
+ let lastExists = hasAt(store._state, path);
206
+ let lastValue = getAt(store._state, path);
207
+ const drained = createDrained((value, ctx) => {
208
+ if (done)
209
+ return;
210
+ cb(value, ctx);
211
+ if (once)
212
+ off();
213
+ }, opts.drain);
214
+ function emitNow() {
215
+ drained.push(getAt(store._state, path), makeCtx(store, path));
216
+ }
217
+ function attach() {
218
+ offUpdate?.();
219
+ const target = watchTarget(store._state, path);
220
+ offUpdate = (0, reactive2_1.onUpdate)(target, () => {
221
+ const exists = hasAt(store._state, path);
222
+ const value = getAt(store._state, path);
223
+ const valueIsObject = (0, reactive2_1.isReactive)(value);
224
+ const watchedSelf = target === value;
225
+ if (!valueIsObject && !watchedSelf && sameLeaf(lastValue, value, lastExists, exists))
226
+ return;
227
+ lastExists = exists;
228
+ lastValue = value;
229
+ const nextTarget = watchTarget(store._state, path);
230
+ if (nextTarget !== target && !done)
231
+ attach();
232
+ emitNow();
233
+ });
234
+ }
235
+ function off() {
236
+ if (done)
237
+ return;
238
+ done = true;
239
+ drained.close();
240
+ offUpdate?.();
241
+ offUpdate = null;
242
+ decCount(store, path);
243
+ }
244
+ incCount(store, path);
245
+ if (opts.current && lastExists) {
246
+ cb(lastValue, makeCtx(store, path));
247
+ if (once) {
248
+ off();
249
+ return off;
250
+ }
251
+ }
252
+ attach();
253
+ return off;
254
+ }
255
+ function getNode(store, path) {
256
+ const k = pathKey(path);
257
+ const cached = store._nodeCache.get(k);
258
+ if (cached)
259
+ return cached;
260
+ const api = {
261
+ get path() { return [...path]; },
262
+ get pathString() { return pathKey(path); },
263
+ get: () => getAt(store._state, path),
264
+ has: () => hasAt(store._state, path),
265
+ snapshot: () => snapshotValue(getAt(store._state, path)),
266
+ set: (value) => setAt(store._state, path, value),
267
+ replace: (value) => setAt(store._state, path, value),
268
+ on: (cb, opts) => subscribePath(store, path, cb, opts, false),
269
+ once: (cb, opts) => subscribePath(store, path, cb, opts, true),
270
+ update: (mask, opts) => createSelection(store, path, mask, opts),
271
+ at: (key) => getNode(store, [...path, key]),
272
+ count: () => store._counts.get(pathKey(path)) ?? 0,
273
+ };
274
+ const proxy = new Proxy(api, {
275
+ get(target, p) {
276
+ if (p === "then")
277
+ return undefined;
278
+ if (p in target)
279
+ return target[p];
280
+ if (typeof p == "symbol")
281
+ return undefined;
282
+ return getNode(store, [...path, p]);
283
+ },
284
+ ownKeys() {
285
+ const v = getAt(store._state, path);
286
+ return isObj(v) ? Reflect.ownKeys(v) : [];
287
+ },
288
+ getOwnPropertyDescriptor() { return { enumerable: true, configurable: true }; },
289
+ });
290
+ store._nodeCache.set(k, proxy);
291
+ return proxy;
292
+ }
293
+ function createSelection(store, base, mask, defaults = {}) {
294
+ const fullPaths = maskPaths(mask, base);
295
+ const rootNode = getNode(store, base);
296
+ const ctx = () => ({ store, node: rootNode, mask, paths: fullPaths.map(p => [...p]) });
297
+ const get = () => pickSnapshot(store._state, mask, base);
298
+ return {
299
+ mask,
300
+ paths: fullPaths.map(p => [...p]),
301
+ get,
302
+ on(cb, opts = {}) {
303
+ const o = { ...defaults, ...opts, current: false };
304
+ const drained = createDrained(() => cb(get(), ctx()), opts.drain ?? defaults.drain ?? "micro");
305
+ const offs = fullPaths.map(p => subscribePath(store, p, () => drained.push(), o, false));
306
+ if ((opts.current ?? defaults.current))
307
+ cb(get(), ctx());
308
+ return () => { drained.close(); for (const off of offs)
309
+ off(); };
310
+ },
311
+ once(cb, opts = {}) {
312
+ let off = () => { };
313
+ off = this.on((v, c) => { off(); cb(v, c); }, { ...opts, current: opts.current ?? defaults.current });
314
+ return off;
315
+ },
316
+ onEach(cb, opts = {}) {
317
+ const o = { ...defaults, ...opts };
318
+ const offs = fullPaths.map(p => subscribePath(store, p, cb, o, false));
319
+ return () => { for (const off of offs)
320
+ off(); };
321
+ },
322
+ };
323
+ }
324
+ function createStore(initial, opts = {}) {
325
+ const state = (0, reactive2_1.reactive)(initial, opts);
326
+ let store;
327
+ store = {
328
+ _state: state,
329
+ _nodeCache: new Map(),
330
+ _counts: new Map(),
331
+ state,
332
+ get node() { return getNode(store, []); },
333
+ get: () => state,
334
+ snapshot: () => snapshotValue(state),
335
+ replace: (value) => replaceRoot(state, value),
336
+ on: (cb, opts) => getNode(store, []).on(cb, opts),
337
+ once: (cb, opts) => getNode(store, []).once(cb, opts),
338
+ update: (mask, opts) => createSelection(store, [], mask, opts),
339
+ listen: () => (0, reactive2_1.listenUpdate)(state),
340
+ count: () => Array.from(store._counts.values()).reduce((a, b) => a + b, 0),
341
+ };
342
+ return store;
343
+ }
344
+ function exposeStore(store) {
345
+ return {
346
+ get: (mask) => mask ? store.update(mask).get() : store.snapshot(),
347
+ set: (path, value) => {
348
+ let node = store.node;
349
+ for (const k of path)
350
+ node = node.at(k);
351
+ node.replace(value);
352
+ },
353
+ replace: (path, value) => {
354
+ let node = store.node;
355
+ for (const k of path)
356
+ node = node.at(k);
357
+ node.replace(value);
358
+ },
359
+ changed: store.listen(),
360
+ };
361
+ }
362
+ function createStoreMirror(remote, initial = {}, opts = {}) {
363
+ const store = createStore(initial, opts);
364
+ async function sync(mask, subOpts = { current: true }) {
365
+ async function pull() {
366
+ const snap = await remote.get(mask);
367
+ applyMask(store.state, mask, snap);
368
+ }
369
+ if (subOpts.current !== false)
370
+ await pull();
371
+ const drained = createDrained(() => { void pull(); }, subOpts.drain);
372
+ const changed = remote.changed;
373
+ const off = typeof changed?.on == "function"
374
+ ? changed.on(() => drained.push())
375
+ : typeof changed?.addListen == "function"
376
+ ? changed.addListen(() => drained.push())
377
+ : (() => { });
378
+ return () => { drained.close(); off?.(); };
379
+ }
380
+ return Object.assign(store, { sync });
381
+ }
@@ -1,88 +1 @@
1
- export type Listener<T extends any[]> = (...r: T) => void;
2
- export type NormalizeTuple<T> = T extends any[] ? T : [T];
3
- type key = string | symbol;
4
- declare const LISTEN_ON_BRAND: unique symbol;
5
- export type ListenOn<Z extends any[] = any[]> = ((cb: Listener<Z>, opts?: {
6
- cbClose?: () => void;
7
- key?: string;
8
- }) => (() => void)) & {
9
- readonly [LISTEN_ON_BRAND]: Z;
10
- };
11
- export declare function getListenByOn(fn: any): any;
12
- export declare function isListenOn(fn: any): boolean;
13
- export declare function funcListenCallbackBase<T>(b: (e: Listener<NormalizeTuple<T>>) => (void | (() => void)), { fast, event, addListenClose }?: {
14
- event?: (type: "add" | "remove", count: number, api: ReturnType<typeof funcListenCallbackBase<T>>) => void;
15
- fast?: boolean;
16
- addListenClose?: ReturnType<typeof funcListenCallbackBase<any>>;
17
- }): {
18
- func: Listener<NormalizeTuple<T>>;
19
- isRun: () => boolean;
20
- run: () => void;
21
- close: () => void;
22
- eventClose: (cb: () => void) => () => void;
23
- onClose: (cb: () => void) => () => void;
24
- removeEventClose: (cb: (() => void)) => void;
25
- addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
26
- cbClose?: () => void;
27
- key?: key;
28
- }) => () => void;
29
- removeListen: (k: Listener<NormalizeTuple<T>> | null | key) => void;
30
- on: ListenOn<NormalizeTuple<T>>;
31
- once: (cb: Listener<NormalizeTuple<T>>, opts?: {
32
- key?: key;
33
- }) => () => void;
34
- count: () => number;
35
- readonly getAllKeys: (Listener<NormalizeTuple<T>> | key)[];
36
- };
37
- export declare function funcListenCallbackFast<T>(a: (e: (Listener<NormalizeTuple<T>> | null)) => (void | (() => void))): {
38
- func: Listener<NormalizeTuple<T>>;
39
- isRun: () => boolean;
40
- run: () => void;
41
- close: () => void;
42
- eventClose: (cb: () => void) => () => void;
43
- onClose: (cb: () => void) => () => void;
44
- removeEventClose: (cb: () => void) => void;
45
- addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
46
- cbClose?: (() => void) | undefined;
47
- key?: key;
48
- }) => () => void;
49
- removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
50
- on: ListenOn<NormalizeTuple<T>>;
51
- once: (cb: Listener<NormalizeTuple<T>>, opts?: {
52
- key?: key;
53
- }) => () => void;
54
- count: () => number;
55
- readonly getAllKeys: (key | Listener<NormalizeTuple<T>>)[];
56
- };
57
- export declare const funcListenCallback: typeof funcListenCallbackBase;
58
- export declare function UseListen<T>(data?: Parameters<typeof funcListenCallbackBase<T>>[1]): readonly [(...a: NormalizeTuple<T>) => void, {
59
- func: Listener<NormalizeTuple<T>>;
60
- isRun: () => boolean;
61
- run: () => void;
62
- close: () => void;
63
- eventClose: (cb: () => void) => () => void;
64
- onClose: (cb: () => void) => () => void;
65
- removeEventClose: (cb: () => void) => void;
66
- addListen: (cb: Listener<NormalizeTuple<T>>, { cbClose, key }?: {
67
- cbClose?: (() => void) | undefined;
68
- key?: key;
69
- }) => () => void;
70
- removeListen: (k: key | Listener<NormalizeTuple<T>> | null) => void;
71
- on: ListenOn<NormalizeTuple<T>>;
72
- once: (cb: Listener<NormalizeTuple<T>>, opts?: {
73
- key?: key;
74
- }) => () => void;
75
- count: () => number;
76
- readonly getAllKeys: (key | Listener<NormalizeTuple<T>>)[];
77
- }];
78
- export type Listen2<T> = {
79
- on: (cb: Listener<NormalizeTuple<T>>, opts?: {
80
- key?: string;
81
- }) => (() => void);
82
- close: () => void;
83
- count: () => number;
84
- };
85
- export declare function toListen2<T>(full: ReturnType<typeof funcListenCallbackBase<T>>): Listen2<T>;
86
- export declare function UseListen2<T>(data?: Parameters<typeof funcListenCallbackBase<T>>[1]): readonly [(...a: NormalizeTuple<T>) => void, Listen2<T>];
87
- export declare function isListenCallback(obj: any): obj is ReturnType<typeof funcListenCallbackBase>;
88
- export {};
1
+ export * from "./Listen3";
@@ -1,191 +1,17 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.funcListenCallback = void 0;
4
- exports.getListenByOn = getListenByOn;
5
- exports.isListenOn = isListenOn;
6
- exports.funcListenCallbackBase = funcListenCallbackBase;
7
- exports.funcListenCallbackFast = funcListenCallbackFast;
8
- exports.UseListen = UseListen;
9
- exports.toListen2 = toListen2;
10
- exports.UseListen2 = UseListen2;
11
- exports.isListenCallback = isListenCallback;
12
- const listenByOn = new WeakMap();
13
- function getListenByOn(fn) { return typeof fn == "function" ? listenByOn.get(fn) : undefined; }
14
- function isListenOn(fn) { return typeof fn == "function" && listenByOn.has(fn); }
15
- function funcListenCallbackBase(b, { fast = true, event, addListenClose } = {}) {
16
- const obj = new Map();
17
- const cbKeys = new Map();
18
- let evClose = null;
19
- let sinh = null;
20
- let a = (...e) => { obj.forEach(z => z(...e)); };
21
- let close = null;
22
- let cached = null;
23
- let closeUnsubscribe = null;
24
- const getArr = () => cached ?? (cached = Array.from(obj.values()));
25
- const rebuild = () => {
26
- cached = null;
27
- const size = obj.size;
28
- if (size === 0) {
29
- a = null;
30
- return;
31
- }
32
- if (size === 1) {
33
- a = obj.values().next().value;
34
- return;
35
- }
36
- if (size === 2) {
37
- const [a0, a1] = getArr();
38
- a = ((...e) => { a0(...e); a1(...e); });
39
- return;
40
- }
41
- a = ((...e) => {
42
- const ar = getArr();
43
- for (let i = 0, len = ar.length; i < len; i++)
44
- ar[i](...e);
45
- });
46
- };
47
- const func = (...e) => { a?.(...e); };
48
- function forgetKey(k) {
49
- const removed = obj.get(k);
50
- if (typeof removed == "function") {
51
- const keys = cbKeys.get(removed);
52
- if (keys) {
53
- const i = keys.indexOf(k);
54
- if (i >= 0)
55
- keys.splice(i, 1);
56
- if (keys.length == 0)
57
- cbKeys.delete(removed);
58
- }
59
- }
60
- const e = evClose?.get(k);
61
- evClose?.delete(k);
62
- if (e) {
63
- evClose?.delete(e);
64
- sinh?.delete(e);
65
- }
66
- }
67
- function removeKey(k) {
68
- if (!obj.has(k))
69
- return;
70
- obj.delete(k);
71
- forgetKey(k);
72
- if (fast)
73
- rebuild();
74
- event?.("remove", obj.size, api);
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
75
7
  }
76
- const run = () => {
77
- close = (b(func) ?? (() => { }));
78
- if (addListenClose && !closeUnsubscribe) {
79
- closeUnsubscribe = addListenClose.addListen(() => {
80
- api.close();
81
- });
82
- }
83
- };
84
- const api = {
85
- func,
86
- isRun: () => close !== null,
87
- run,
88
- close: () => {
89
- close?.();
90
- close = null;
91
- obj.clear();
92
- cbKeys.clear();
93
- if (fast)
94
- rebuild();
95
- sinh = null;
96
- if (evClose) {
97
- evClose.forEach(cb => cb());
98
- evClose = null;
99
- }
100
- if (closeUnsubscribe) {
101
- closeUnsubscribe();
102
- closeUnsubscribe = null;
103
- }
104
- },
105
- eventClose: (cb) => {
106
- evClose = evClose ?? new Map();
107
- evClose.set(cb, cb);
108
- return () => { evClose?.delete(cb); };
109
- },
110
- onClose: (cb) => api.eventClose(cb),
111
- removeEventClose: (cb) => {
112
- const e = sinh?.get(cb);
113
- if (e)
114
- evClose?.delete(e);
115
- sinh?.delete(cb);
116
- evClose?.delete(cb);
117
- },
118
- addListen: (cb, { cbClose, key } = {}) => {
119
- const k = key ?? Symbol();
120
- if (obj.has(k))
121
- forgetKey(k);
122
- obj.set(k, cb);
123
- let keys = cbKeys.get(cb);
124
- if (!keys)
125
- cbKeys.set(cb, keys = []);
126
- keys.push(k);
127
- if (cbClose) {
128
- evClose = evClose ?? new Map();
129
- evClose.set(k, cbClose);
130
- sinh = sinh ?? new Map();
131
- sinh.set(cbClose, cb);
132
- }
133
- if (fast)
134
- rebuild();
135
- event?.("add", obj.size, api);
136
- return () => removeKey(k);
137
- },
138
- removeListen: (k) => {
139
- if (typeof k == "function" && !obj.has(k))
140
- for (const kk of [...(cbKeys.get(k) ?? [])])
141
- removeKey(kk);
142
- else
143
- removeKey(k);
144
- },
145
- on: ((cb, opts = {}) => api.addListen(cb, opts)),
146
- once: (cb, opts = {}) => {
147
- let off = () => { };
148
- off = api.addListen(((...e) => { off(); cb(...e); }), opts);
149
- return off;
150
- },
151
- count: () => obj.size,
152
- get getAllKeys() { return [...obj.keys()]; }
153
- };
154
- listenByOn.set(api.on, api);
155
- return api;
156
- }
157
- function funcListenCallbackFast(a) {
158
- return funcListenCallbackBase(a, { fast: true });
159
- }
160
- exports.funcListenCallback = funcListenCallbackBase;
161
- function UseListen(data = { fast: true }) {
162
- let t;
163
- const a = funcListenCallbackBase((e) => { t = e; }, { fast: true, ...data });
164
- a.run();
165
- t = a.func;
166
- return [t, a];
167
- }
168
- function toListen2(full) {
169
- return {
170
- on: (cb, opts) => full.addListen(cb, opts),
171
- close: () => full.close(),
172
- count: () => full.count(),
173
- };
174
- }
175
- function UseListen2(data = { fast: true }) {
176
- const [emit, full] = UseListen(data);
177
- return [emit, toListen2(full)];
178
- }
179
- const LISTEN_CORE = ["func", "addListen", "removeListen", "eventClose", "removeEventClose"];
180
- function isListenCallback(obj) {
181
- if (obj == null || typeof obj !== "object")
182
- return false;
183
- const ks = new Set(Object.keys(obj));
184
- for (const k of LISTEN_CORE)
185
- if (!ks.has(k))
186
- return false;
187
- for (const k of LISTEN_CORE)
188
- if (typeof obj[k] !== "function")
189
- return false;
190
- return true;
191
- }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Listen3"), exports);
@@ -0,0 +1 @@
1
+ export * from "./Listen3";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Listen3"), exports);