sia-reactor 0.0.21 → 0.0.23
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/README.md +115 -89
- package/dist/{TimeTravelOverlay-DxqJL0Zk.d.ts → TimeTravelOverlay-Dglcwpg-.d.ts} +9 -8
- package/dist/{TimeTravelOverlay-CJv-S_Km.d.cts → TimeTravelOverlay-OjklzuCD.d.cts} +9 -8
- package/dist/adapters/react.cjs +74 -91
- package/dist/adapters/react.d.cts +23 -22
- package/dist/adapters/react.d.ts +23 -22
- package/dist/adapters/react.js +3 -3
- package/dist/adapters/vanilla.cjs +74 -91
- package/dist/adapters/vanilla.d.cts +4 -4
- package/dist/adapters/vanilla.d.ts +4 -4
- package/dist/adapters/vanilla.js +3 -3
- package/dist/{chunk-TFLYCXK4.js → chunk-5JNWC7Z4.js} +14 -13
- package/dist/{chunk-DP74DVRT.js → chunk-MKL3JUPO.js} +55 -15
- package/dist/{chunk-2WBPGSRL.js → chunk-MSTHQVNK.js} +61 -78
- package/dist/{index-Oie9hhE8.d.cts → index-m0aAWxhX.d.cts} +330 -218
- package/dist/{index-Oie9hhE8.d.ts → index-m0aAWxhX.d.ts} +330 -218
- package/dist/index.cjs +69 -89
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -4
- package/dist/{plugins.cjs → modules.cjs} +464 -195
- package/dist/modules.d.cts +52 -0
- package/dist/modules.d.ts +52 -0
- package/dist/modules.js +619 -0
- package/dist/super.d.ts +642 -298
- package/dist/super.global.js +481 -210
- package/dist/timeTravel-DExvNb04.d.ts +352 -0
- package/dist/timeTravel-DctvcHVt.d.cts +352 -0
- package/dist/utils.cjs +59 -14
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +7 -1
- package/package.json +6 -6
- package/dist/plugins.d.cts +0 -112
- package/dist/plugins.d.ts +0 -112
- package/dist/plugins.js +0 -370
- package/dist/timeTravel-B1vedDQc.d.ts +0 -76
- package/dist/timeTravel-WpgWmKu-.d.cts +0 -76
package/dist/index.cjs
CHANGED
|
@@ -22,7 +22,6 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
CTX: () => CTX,
|
|
24
24
|
EVT_OPTS: () => EVT_OPTS,
|
|
25
|
-
EVT_WARN: () => EVT_WARN,
|
|
26
25
|
INDIFFABLE: () => INDIFFABLE,
|
|
27
26
|
INERTIA: () => INERTIA,
|
|
28
27
|
NIL: () => NIL,
|
|
@@ -57,7 +56,9 @@ module.exports = __toCommonJS(index_exports);
|
|
|
57
56
|
var CTX = {
|
|
58
57
|
/** Flag indicating whether the application is running in development mode. */
|
|
59
58
|
isDevEnv: "undefined" !== typeof process ? process.env.NODE_ENV !== "production" : true,
|
|
60
|
-
/**
|
|
59
|
+
/** Flag indicating whether a cascade is currently ongoing so reactors can allow all writes. */
|
|
60
|
+
isCascading: false,
|
|
61
|
+
/** Active `Autotracker` instance, override for automatic dependency collection on `Reactor` traps. */
|
|
61
62
|
autotracker: null
|
|
62
63
|
};
|
|
63
64
|
var RAW = /* @__PURE__ */ Symbol.for("S.I.A_RAW");
|
|
@@ -69,14 +70,13 @@ var VERSION = /* @__PURE__ */ Symbol.for("S.I.A_VERSION");
|
|
|
69
70
|
var SSVERSION = /* @__PURE__ */ Symbol.for("S.I.A_SNAPSHOT_VERSION");
|
|
70
71
|
var RTR_BATCH = "undefined" !== typeof window ? ("undefined" !== typeof queueMicrotask ? queueMicrotask : setTimeout).bind(window) : "undefined" !== typeof process && process.nextTick ? process.nextTick : setTimeout;
|
|
71
72
|
var RTR_LOG = console.log.bind(console, "[S.I.A Reactor]");
|
|
72
|
-
var EVT_WARN = console.warn.bind(console, "[S.I.A Event]");
|
|
73
73
|
var EVT_OPTS = { LISTENER: ["capture", "depth", "once", "signal", "immediate"], MEDIATOR: ["lazy", "signal", "immediate"] };
|
|
74
74
|
var NIL = Object.freeze({});
|
|
75
75
|
var NOOP = () => {
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
// src/ts/utils/obj.ts
|
|
79
|
-
var
|
|
79
|
+
var arrRegex = /^([^\[\]]+)\[(\d+)\]$/;
|
|
80
80
|
function isObj(obj, arraycheck = true) {
|
|
81
81
|
return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
|
|
82
82
|
}
|
|
@@ -84,7 +84,7 @@ function isPOJO(obj, config = NIL, typecheck = true) {
|
|
|
84
84
|
return (typecheck ? isObj(obj, false) : true) && (config.crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
|
|
85
85
|
}
|
|
86
86
|
function canHandle(obj, config = NIL, typecheck = true) {
|
|
87
|
-
if (typecheck && !isObj(obj, false)) return false;
|
|
87
|
+
if (typecheck && !isObj(obj, false) || obj[INERTIA]) return false;
|
|
88
88
|
if (Array.isArray(obj) || !config.preserveContext && isPOJO(obj, config, false)) return true;
|
|
89
89
|
if (config.preserveContext) return !(obj instanceof Map) && !(obj instanceof Set) && !(obj instanceof WeakMap) && !(obj instanceof WeakSet) && !(obj instanceof Error) && !(obj instanceof Number) && !(obj instanceof Date) && !(obj instanceof String) && !(obj instanceof RegExp) && !(obj instanceof ArrayBuffer) && !(obj instanceof Promise);
|
|
90
90
|
return false;
|
|
@@ -95,7 +95,7 @@ function getAny(source, key, separator = ".", keyFunc) {
|
|
|
95
95
|
const keys = key.split(separator);
|
|
96
96
|
let currObj = source;
|
|
97
97
|
for (let i = 0, len = keys.length; i < len; i++) {
|
|
98
|
-
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(
|
|
98
|
+
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
99
99
|
if (match) {
|
|
100
100
|
const [, key3, iStr] = match;
|
|
101
101
|
if (!Array.isArray(currObj[key3]) || !(key3 in currObj)) return void 0;
|
|
@@ -112,7 +112,7 @@ function setAny(target, key, value, separator = ".", keyFunc) {
|
|
|
112
112
|
if (!key.includes(separator)) return void (target[keyFunc ? keyFunc(key) : key] = value);
|
|
113
113
|
const keys = key.split(separator);
|
|
114
114
|
for (let currObj = target, i = 0, len = keys.length; i < len; i++) {
|
|
115
|
-
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(
|
|
115
|
+
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
116
116
|
if (match) {
|
|
117
117
|
const [, key3, iStr] = match;
|
|
118
118
|
if (!Array.isArray(currObj[key3])) currObj[key3] = [];
|
|
@@ -133,7 +133,7 @@ function deleteAny(target, key, separator = ".", keyFunc) {
|
|
|
133
133
|
if (!key.includes(separator)) return void delete target[keyFunc ? keyFunc(key) : key];
|
|
134
134
|
const keys = key.split(separator);
|
|
135
135
|
for (let currObj = target, i = 0, len = keys.length; i < len; i++) {
|
|
136
|
-
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(
|
|
136
|
+
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
137
137
|
if (match) {
|
|
138
138
|
const [, key3, iStr] = match;
|
|
139
139
|
if (!Array.isArray(currObj[key3]) || !(key3 in currObj)) return;
|
|
@@ -151,7 +151,7 @@ function inAny(source, key, separator = ".", keyFunc) {
|
|
|
151
151
|
if (!key.includes(separator)) return key in source;
|
|
152
152
|
const keys = key.split(separator);
|
|
153
153
|
for (let currObj = source, i = 0, len = keys.length; i < len; i++) {
|
|
154
|
-
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(
|
|
154
|
+
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
155
155
|
if (match) {
|
|
156
156
|
const [, key3, iStr] = match;
|
|
157
157
|
if (!Array.isArray(currObj[key3]) || !(key3 in currObj)) return false;
|
|
@@ -168,10 +168,6 @@ function inAny(source, key, separator = ".", keyFunc) {
|
|
|
168
168
|
function parseEvtOpts(options, opts, boolOpt = opts[0], result = {}) {
|
|
169
169
|
return Object.assign(result, "boolean" === typeof options ? { [boolOpt]: options } : options), result;
|
|
170
170
|
}
|
|
171
|
-
function mergeObjs(o1 = {}, o2 = {}) {
|
|
172
|
-
const merged = { ...o1 || {}, ...o2 || {} };
|
|
173
|
-
return Object.keys(merged).forEach((k) => isObj(o1?.[k]) && isObj(o2?.[k]) && (merged[k] = mergeObjs(o1[k], o2[k]))), merged;
|
|
174
|
-
}
|
|
175
171
|
function getTrailRecords(obj, path, reverse = false) {
|
|
176
172
|
const parts = path.split("."), chain = [["*", obj, obj]];
|
|
177
173
|
for (let acc = "", currObj = obj, i = 0, len = parts.length; i < len; i++) chain.push([acc += (i ? "." : "") + parts[i], currObj, currObj = currObj?.[parts[i]]]);
|
|
@@ -214,35 +210,34 @@ var ReactorEvent = class _ReactorEvent {
|
|
|
214
210
|
staticType;
|
|
215
211
|
/** Original event target context. */
|
|
216
212
|
target;
|
|
217
|
-
/** Root reactive object for this event wave. */
|
|
213
|
+
/** Root reactive object for this event instance wave. */
|
|
218
214
|
root;
|
|
219
|
-
/** Original target path for this event wave. */
|
|
215
|
+
/** Original target path for this event instance wave. */
|
|
220
216
|
path;
|
|
221
217
|
/** Current value at the event target path. */
|
|
222
218
|
value;
|
|
223
219
|
/** Previous value at the event target path. */
|
|
224
220
|
oldValue;
|
|
225
|
-
/** Whether resolve/reject intent semantics are allowed for this event. */
|
|
221
|
+
/** Whether resolve/reject intent semantics are allowed for this event instance. */
|
|
226
222
|
rejectable;
|
|
227
|
-
/** Whether this event wave can bubble back up to ancestors or just capture down. */
|
|
223
|
+
/** Whether this event instance wave can bubble back up to ancestors or just capture down. */
|
|
228
224
|
bubbles;
|
|
229
225
|
/**
|
|
230
|
-
* `DOMHighResTimeStamp` for this event payload for native event parity and accuracy.
|
|
226
|
+
* `DOMHighResTimeStamp` for this event instance payload for native event parity and accuracy.
|
|
231
227
|
* Enable `eventTimeStamps` option, then use this over custom timestamps in listeners for accuracy.
|
|
232
228
|
* */
|
|
233
229
|
timestamp;
|
|
234
|
-
|
|
230
|
+
/** The `Reactor` instance that dispatched this event instance. */
|
|
231
|
+
reactor;
|
|
235
232
|
_resolved = "";
|
|
236
233
|
_rejected = "";
|
|
237
234
|
_propagationStopped = false;
|
|
238
235
|
_immediatePropagationStopped = false;
|
|
239
236
|
/**
|
|
240
237
|
* @param payload Source payload for this event instance.
|
|
241
|
-
* @param
|
|
242
|
-
* @param canWarn Whether warning output is enabled.
|
|
243
|
-
* @param canStamp Whether timestamping is enabled.
|
|
238
|
+
* @param reactor The `Reactor` instance creating this event instance.
|
|
244
239
|
*/
|
|
245
|
-
constructor(payload,
|
|
240
|
+
constructor(payload, reactor) {
|
|
246
241
|
this.staticType = this.type = payload.type;
|
|
247
242
|
this.target = payload.target;
|
|
248
243
|
this.currentTarget = payload.currentTarget;
|
|
@@ -251,9 +246,9 @@ var ReactorEvent = class _ReactorEvent {
|
|
|
251
246
|
this.value = payload.target.value;
|
|
252
247
|
this.oldValue = payload.target.oldValue;
|
|
253
248
|
this.rejectable = payload.rejectable;
|
|
254
|
-
this.bubbles =
|
|
255
|
-
if (
|
|
256
|
-
|
|
249
|
+
this.bubbles = !!reactor.config.eventBubbling;
|
|
250
|
+
if (reactor.config.eventTimeStamps) this.timestamp = performance.now();
|
|
251
|
+
this.reactor = reactor;
|
|
257
252
|
}
|
|
258
253
|
/** Whether propagation has been stopped. */
|
|
259
254
|
get propagationStopped() {
|
|
@@ -283,9 +278,9 @@ var ReactorEvent = class _ReactorEvent {
|
|
|
283
278
|
* @example e.resolve("API Load successful"); // message
|
|
284
279
|
*/
|
|
285
280
|
resolve(message) {
|
|
286
|
-
if (!this.rejectable) return this.
|
|
287
|
-
if (this.eventPhase !== _ReactorEvent.CAPTURING_PHASE) this.
|
|
288
|
-
if (this.rejectable) this._resolved = message || `Could ${this.staticType} intended value at "${this.path}"
|
|
281
|
+
if (!this.rejectable) return this.reactor.log(`[ReactorEvent] Ignored \`resolve()\` call on a non-rejectable ${this.staticType} at "${this.path}"`);
|
|
282
|
+
if (this.eventPhase !== _ReactorEvent.CAPTURING_PHASE) this.reactor.log(`[ReactorEvent] Resolving an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`);
|
|
283
|
+
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._resolved = message || `Could ${this.staticType} intended value at "${this.path}"`}`);
|
|
289
284
|
}
|
|
290
285
|
/** Rejection reason for rejectable events. */
|
|
291
286
|
get rejected() {
|
|
@@ -298,9 +293,9 @@ var ReactorEvent = class _ReactorEvent {
|
|
|
298
293
|
* @example e.resolve("User is not logged in"); // reason
|
|
299
294
|
*/
|
|
300
295
|
reject(reason) {
|
|
301
|
-
if (!this.rejectable) return this.
|
|
302
|
-
if (this.eventPhase !== _ReactorEvent.CAPTURING_PHASE) this.
|
|
303
|
-
if (this.rejectable) this._rejected = reason || `Couldn't ${this.staticType} intended value at "${this.path}"
|
|
296
|
+
if (!this.rejectable) return this.reactor.log(`[ReactorEvent] Ignored \`reject()\` call on a non-rejectable ${this.staticType} at "${this.path}"`);
|
|
297
|
+
if (this.eventPhase !== _ReactorEvent.CAPTURING_PHASE) this.reactor.log(`[ReactorEvent] Rejecting an intent on ${this.staticType} at "${this.path}" outside of the capture phase is unadvised.`);
|
|
298
|
+
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._rejected = reason || `Couldn't ${this.staticType} intended value at "${this.path}"`}`);
|
|
304
299
|
}
|
|
305
300
|
/**
|
|
306
301
|
* Returns event path values from target to root.
|
|
@@ -309,24 +304,22 @@ var ReactorEvent = class _ReactorEvent {
|
|
|
309
304
|
composedPath() {
|
|
310
305
|
return getTrailRecords(this.root, this.path, true).map((r) => r[2]);
|
|
311
306
|
}
|
|
312
|
-
get canWarn() {
|
|
313
|
-
return this._warn !== NOOP;
|
|
314
|
-
}
|
|
315
307
|
};
|
|
316
308
|
|
|
317
309
|
// src/ts/core/reactor.ts
|
|
318
310
|
var Reactor = class {
|
|
311
|
+
/** Logger function for this reactor instance, override if desired, `this.canLog = false` resets. */
|
|
319
312
|
log = NOOP;
|
|
313
|
+
/** The core state object for this reactor instance. */
|
|
320
314
|
core;
|
|
321
315
|
// `?:`s | pay the ~800 byte price upfront for what u might never use
|
|
322
|
-
|
|
316
|
+
/** The modules being used by this reactor. */
|
|
317
|
+
modules;
|
|
318
|
+
/** Configuration options for this reactor instance. */
|
|
323
319
|
config;
|
|
320
|
+
/** Whether this reactor instance is currently batching updates, a window view into the engine timing */
|
|
324
321
|
isBatching = false;
|
|
325
322
|
// Async Batching
|
|
326
|
-
isCascading = false;
|
|
327
|
-
// Setter Cascading
|
|
328
|
-
isLogging = false;
|
|
329
|
-
// keeping track so API getter doesn't slow down internal iterations in any way
|
|
330
323
|
queue;
|
|
331
324
|
// Tasks to run after flush
|
|
332
325
|
batch;
|
|
@@ -359,7 +352,7 @@ var Reactor = class {
|
|
|
359
352
|
if (this.config.referenceTracking && parent && key && !this.link(target, parent, key, false)) return target;
|
|
360
353
|
const cached = this.proxyCache.get(target);
|
|
361
354
|
if (cached) return cached;
|
|
362
|
-
if (
|
|
355
|
+
if (!canHandle(target, this.config, false)) return target;
|
|
363
356
|
rejectable ||= target[REJECTABLE];
|
|
364
357
|
indiffable ||= target[INDIFFABLE];
|
|
365
358
|
const proxy = new Proxy(target, {
|
|
@@ -393,7 +386,7 @@ var Reactor = class {
|
|
|
393
386
|
safeValue = value?.[RAW] || value;
|
|
394
387
|
unchanged = this.config.equalityFunction(safeValue, safeOldValue);
|
|
395
388
|
}
|
|
396
|
-
if (!indiffable && unchanged && !
|
|
389
|
+
if (!indiffable && unchanged && !CTX.isCascading) return this.log(`\u{1F504} [Reactor \`set\` Trap] Unchanged for "${keyStr}" on "${paths}"`), true;
|
|
397
390
|
if (this.config.set) terminated = (value = this.config.set(object, key2, value, oldValue, receiver, paths)) === TERMINATOR;
|
|
398
391
|
if (this.setters) {
|
|
399
392
|
const wildcords = this.setters.get("*");
|
|
@@ -547,7 +540,7 @@ var Reactor = class {
|
|
|
547
540
|
if (this.queue?.size) for (const task of this.queue) task(), this.queue.delete(task);
|
|
548
541
|
}
|
|
549
542
|
wave(path, payload) {
|
|
550
|
-
const e = new ReactorEvent(payload, this
|
|
543
|
+
const e = new ReactorEvent(payload, this), chain = getTrailRecords(this.core, path);
|
|
551
544
|
e.eventPhase = ReactorEvent.CAPTURING_PHASE;
|
|
552
545
|
for (let i = 0; i <= chain.length - 2; i++) {
|
|
553
546
|
if (e.propagationStopped) break;
|
|
@@ -621,8 +614,8 @@ var Reactor = class {
|
|
|
621
614
|
return depth;
|
|
622
615
|
}
|
|
623
616
|
getContext(path) {
|
|
624
|
-
const
|
|
625
|
-
return { path, value, key: path.slice(
|
|
617
|
+
const last = path.lastIndexOf("."), value = getAny(this.core, path), object = last === -1 ? this.core : getAny(this.core, path.slice(0, last));
|
|
618
|
+
return { path, value, key: path.slice(last + 1) || "", hadKey: true, object };
|
|
626
619
|
}
|
|
627
620
|
bindSignal(cord, sig) {
|
|
628
621
|
if (sig) sig.aborted ? cord.clup() : sig.addEventListener("abort", cord.clup, { once: true });
|
|
@@ -638,7 +631,12 @@ var Reactor = class {
|
|
|
638
631
|
const clone = !raw ? this.config.preserveContext ? Object.create(Object.getPrototypeOf(obj)) : Array.isArray(obj) ? [] : {} : obj;
|
|
639
632
|
seen.set(obj, clone);
|
|
640
633
|
const keys = this.config.preserveContext ? Reflect.ownKeys(obj) : Object.keys(obj);
|
|
641
|
-
for (let i = 0, len = keys.length; i < len; i++)
|
|
634
|
+
for (let i = 0, len = keys.length; i < len; i++)
|
|
635
|
+
try {
|
|
636
|
+
clone[keys[i]] = this.cloned(obj[keys[i]], raw, seen);
|
|
637
|
+
} catch (e) {
|
|
638
|
+
if (e instanceof RangeError) throw e;
|
|
639
|
+
}
|
|
642
640
|
if (!raw && this.config.smartCloning) this.snapCache.set(obj, clone), obj[SSVERSION] = version;
|
|
643
641
|
return clone;
|
|
644
642
|
}
|
|
@@ -726,7 +724,7 @@ var Reactor = class {
|
|
|
726
724
|
* rtr.delete("cache.temp", () => TERMINATOR);
|
|
727
725
|
*/
|
|
728
726
|
delete(path, callback, options) {
|
|
729
|
-
return this.syncAdd("delete", path, callback, options, (imm) => (imm !== "auto" || inAny(this.core, path)) && deleteAny(this.core, path
|
|
727
|
+
return this.syncAdd("delete", path, callback, options, (imm) => (imm !== "auto" || inAny(this.core, path)) && deleteAny(this.core, path));
|
|
730
728
|
}
|
|
731
729
|
/** Registers a delete mediator for a path that only triggers once. */
|
|
732
730
|
donce(path, callback, options) {
|
|
@@ -743,7 +741,7 @@ var Reactor = class {
|
|
|
743
741
|
}
|
|
744
742
|
/**
|
|
745
743
|
* Registers a watcher for a path.
|
|
746
|
-
* Watch callbacks run synchronously with the operation.
|
|
744
|
+
* Watch callbacks run synchronously with the operation, use leaf paths for reliability as it sees exact sets; no bubbling here.
|
|
747
745
|
* @param path Path or wildcard path.
|
|
748
746
|
* @param callback Watch callback.
|
|
749
747
|
* @param options Sync options.
|
|
@@ -792,7 +790,7 @@ var Reactor = class {
|
|
|
792
790
|
cord = { cb: callback, capture, depth, once, clup: () => this.off(path, callback, options), lDepth: depth !== void 0 ? this.getDepth(path) : depth };
|
|
793
791
|
if (immediate && (immediate !== "auto" || inAny(this.core, path))) {
|
|
794
792
|
const target = this.getContext(path);
|
|
795
|
-
callback(new ReactorEvent({ type: "init", target, currentTarget: target, root: this.core, rejectable: false }, this
|
|
793
|
+
callback(new ReactorEvent({ type: "init", target, currentTarget: target, root: this.core, rejectable: false }, this));
|
|
796
794
|
}
|
|
797
795
|
(cords ?? (this.listeners.set(path, cords = []), cords)).push(cord);
|
|
798
796
|
return this.bindSignal(cord, signal);
|
|
@@ -823,56 +821,39 @@ var Reactor = class {
|
|
|
823
821
|
return this.cloned(arguments.length < 2 ? this.core : branch, raw);
|
|
824
822
|
}
|
|
825
823
|
/**
|
|
826
|
-
*
|
|
827
|
-
* @param
|
|
828
|
-
* @param
|
|
829
|
-
* @
|
|
830
|
-
* rtr.on("user", (event) => rtr.cascade(event));
|
|
831
|
-
* @example
|
|
832
|
-
* rtr.watch("user", (_value, payload) => rtr.cascade(payload));
|
|
833
|
-
*/
|
|
834
|
-
cascade({ type, currentTarget: { path, value: news, oldValue: olds } }, objectSafe = true) {
|
|
835
|
-
if (type !== "set" && type !== "delete" || !canHandle(news, this.config) || (objectSafe ? !canHandle(olds, this.config) : false)) return;
|
|
836
|
-
const obj = objectSafe ? mergeObjs(olds, news) : news, keys = Object.keys(obj);
|
|
837
|
-
this.isCascading = true;
|
|
838
|
-
for (let i = 0, len = keys.length; i < len; i++) setAny(this.core, path === "*" ? keys[i] : path + "." + keys[i], obj[keys[i]]);
|
|
839
|
-
this.isCascading = false;
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* Installs a plugin instance.
|
|
843
|
-
* @param plugin Plugin instance.
|
|
844
|
-
* @returns Current reactor for fluent chaining.
|
|
824
|
+
* Installs a module instance.
|
|
825
|
+
* @param target Module instance.
|
|
826
|
+
* @param id Optional identification tag for this instance in the module.
|
|
827
|
+
* @returns Current `Reactor` instance for fluent chaining.
|
|
845
828
|
*/
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
this.plugins?.get(name)?.destroy();
|
|
849
|
-
return (this.plugins ??= /* @__PURE__ */ new Map()).set(name, (plugin.setup(this), plugin)), this;
|
|
829
|
+
use(target, id) {
|
|
830
|
+
return (this.modules ??= /* @__PURE__ */ new Set()).add(target.setup(this, id)), this;
|
|
850
831
|
}
|
|
851
|
-
/** Resets
|
|
832
|
+
/** Resets this reactor instance to its initial state. */
|
|
852
833
|
reset() {
|
|
853
834
|
this.getters?.clear(), this.setters?.clear(), this.deleters?.clear(), this.watchers?.clear(), this.listeners?.clear();
|
|
854
835
|
this.batch?.clear(), this.queue?.clear(), this.isBatching = false;
|
|
855
836
|
}
|
|
856
837
|
destroy() {
|
|
857
|
-
if (this.
|
|
838
|
+
if (this.modules) for (const mdle of this.modules) mdle.destroy();
|
|
858
839
|
this.reset(), nuke(this);
|
|
859
840
|
}
|
|
860
841
|
get canLog() {
|
|
861
|
-
return this.
|
|
842
|
+
return this.log !== NOOP;
|
|
862
843
|
}
|
|
863
844
|
set canLog(value) {
|
|
864
|
-
this.log =
|
|
845
|
+
this.log = value ? RTR_LOG : NOOP;
|
|
865
846
|
}
|
|
866
|
-
get
|
|
867
|
-
return this.config.
|
|
847
|
+
get canLineageTrace() {
|
|
848
|
+
return this.config.lineageTracing && this.config.referenceTracking;
|
|
868
849
|
}
|
|
869
850
|
get canSmartClone() {
|
|
870
|
-
return this.config.
|
|
851
|
+
return this.config.smartCloning && this.config.referenceTracking;
|
|
871
852
|
}
|
|
872
853
|
};
|
|
873
854
|
|
|
874
855
|
// src/ts/core/mixins.ts
|
|
875
|
-
var methods = ["tick", "stall", "nostall", "get", "gonce", "noget", "set", "sonce", "noset", "delete", "donce", "nodelete", "watch", "wonce", "nowatch", "on", "once", "off", "snapshot", "
|
|
856
|
+
var methods = ["tick", "stall", "nostall", "get", "gonce", "noget", "set", "sonce", "noset", "delete", "donce", "nodelete", "watch", "wonce", "nowatch", "on", "once", "off", "snapshot", "use", "reset", "destroy"];
|
|
876
857
|
function reactive(target, build, preferences = NIL) {
|
|
877
858
|
if ("__Reactor__" in target) return target;
|
|
878
859
|
const descriptors = {}, rtr = getReactor(target, true, build), locks = { enumerable: false, configurable: true, writable: false }, hasAffix = !!(preferences.prefix || preferences.suffix);
|
|
@@ -880,7 +861,7 @@ function reactive(target, build, preferences = NIL) {
|
|
|
880
861
|
let key = methods[i];
|
|
881
862
|
if (hasAffix) (preferences.whitelist?.includes(key) ?? true) && (key = `${preferences.prefix || ""}${key}${preferences.suffix || ""}`);
|
|
882
863
|
else if (preferences.whitelist?.includes(key)) continue;
|
|
883
|
-
descriptors[key] = { value: rtr[
|
|
864
|
+
descriptors[key] = { value: rtr[methods[i]].bind(rtr), ...locks };
|
|
884
865
|
}
|
|
885
866
|
descriptors["__Reactor__"] = { value: rtr, ...locks };
|
|
886
867
|
return Object.defineProperties(rtr.core, descriptors), rtr.core;
|
|
@@ -891,7 +872,7 @@ function inert(target) {
|
|
|
891
872
|
function live(target) {
|
|
892
873
|
return delete getRaw(target)[INERTIA], target;
|
|
893
874
|
}
|
|
894
|
-
function isInert(target) {
|
|
875
|
+
function isInert(target = NIL) {
|
|
895
876
|
return !!getRaw(target)[INERTIA];
|
|
896
877
|
}
|
|
897
878
|
function intent(target) {
|
|
@@ -900,7 +881,7 @@ function intent(target) {
|
|
|
900
881
|
function state(target) {
|
|
901
882
|
return delete getRaw(target)[REJECTABLE], target;
|
|
902
883
|
}
|
|
903
|
-
function isIntent(target) {
|
|
884
|
+
function isIntent(target = NIL) {
|
|
904
885
|
return !!getRaw(target)[REJECTABLE];
|
|
905
886
|
}
|
|
906
887
|
function volatile(target) {
|
|
@@ -909,26 +890,25 @@ function volatile(target) {
|
|
|
909
890
|
function stable(target) {
|
|
910
891
|
return delete getRaw(target)[INDIFFABLE], target;
|
|
911
892
|
}
|
|
912
|
-
function isVolatile(target) {
|
|
893
|
+
function isVolatile(target = NIL) {
|
|
913
894
|
return !!getRaw(target)[INDIFFABLE];
|
|
914
895
|
}
|
|
915
896
|
function getReactor(target, create = false, build) {
|
|
916
897
|
return (target instanceof Reactor ? target : target.__Reactor__) || (create ? new Reactor(target, build) : void 0);
|
|
917
898
|
}
|
|
918
|
-
function getRaw(target) {
|
|
919
|
-
return target
|
|
899
|
+
function getRaw(target = NIL) {
|
|
900
|
+
return target[RAW] || target;
|
|
920
901
|
}
|
|
921
|
-
function getVersion(target) {
|
|
902
|
+
function getVersion(target = NIL) {
|
|
922
903
|
return getRaw(target)[VERSION] || 0;
|
|
923
904
|
}
|
|
924
|
-
function getSnapshotVersion(target) {
|
|
905
|
+
function getSnapshotVersion(target = NIL) {
|
|
925
906
|
return getRaw(target)[SSVERSION] || 0;
|
|
926
907
|
}
|
|
927
908
|
// Annotate the CommonJS export names for ESM import in node:
|
|
928
909
|
0 && (module.exports = {
|
|
929
910
|
CTX,
|
|
930
911
|
EVT_OPTS,
|
|
931
|
-
EVT_WARN,
|
|
932
912
|
INDIFFABLE,
|
|
933
913
|
INERTIA,
|
|
934
914
|
NIL,
|
package/dist/index.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as CTX,
|
|
1
|
+
export { x as AddDepth, y as AllDepth, C as CTX, z as ChildPaths, D as DeepKeys, G as DeepMerge, H as DeepPartial, J as DeepRequired, K as Deleter, L as DeleterRecord, M as DepthConfig, N as DirectPayload, O as EVT_OPTS, E as EffectOptions, Q as Getter, S as GetterRecord, T as INDIFFABLE, U as INERTIA, I as Inert, V as Intent, X as Listener, Y as ListenerOptions, Z as ListenerOptionsTuple, _ as ListenerRecord, $ as Live, a0 as MaxDepth, a1 as NIL, a2 as NOOP, a3 as NextDepth, a4 as NoTraverse, a5 as PathBranch, a6 as PathBranchValue, a7 as PathDepth, a8 as PathKey, a9 as PathLeaf, v as PathValue, P as Paths, aa as Payload, ab as PrevDepth, ac as Primitive, ad as RAW, ae as REJECTABLE, a as REvent, af as RTR_BATCH, ag as RTR_LOG, d as Reactive, ah as ReactivePreferences, R as Reactor, u as ReactorBuild, ai as ReactorEvent, aj as SSVERSION, ak as Setter, al as SetterRecord, am as Stable, an as State, ao as StrictPathKey, ap as SubtractDepth, aq as SyncOptions, ar as SyncOptionsTuple, as as TERMINATOR, at as Target, au as Unflatten, av as UnionToIntersection, aw as UpdatePayload, ax as VERSION, ay as Volatile, az as Watcher, aA as WatcherRecord, W as WildPaths, aB as getRaw, aC as getSnapshotVersion, aD as getVersion, aE as inert, aF as intent, aG as isInert, aH as isIntent, aI as isVolatile, aJ as live, aK as methods, aL as reactive, aM as stable, aN as state, aO as volatile } from './index-m0aAWxhX.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { C as CTX,
|
|
1
|
+
export { x as AddDepth, y as AllDepth, C as CTX, z as ChildPaths, D as DeepKeys, G as DeepMerge, H as DeepPartial, J as DeepRequired, K as Deleter, L as DeleterRecord, M as DepthConfig, N as DirectPayload, O as EVT_OPTS, E as EffectOptions, Q as Getter, S as GetterRecord, T as INDIFFABLE, U as INERTIA, I as Inert, V as Intent, X as Listener, Y as ListenerOptions, Z as ListenerOptionsTuple, _ as ListenerRecord, $ as Live, a0 as MaxDepth, a1 as NIL, a2 as NOOP, a3 as NextDepth, a4 as NoTraverse, a5 as PathBranch, a6 as PathBranchValue, a7 as PathDepth, a8 as PathKey, a9 as PathLeaf, v as PathValue, P as Paths, aa as Payload, ab as PrevDepth, ac as Primitive, ad as RAW, ae as REJECTABLE, a as REvent, af as RTR_BATCH, ag as RTR_LOG, d as Reactive, ah as ReactivePreferences, R as Reactor, u as ReactorBuild, ai as ReactorEvent, aj as SSVERSION, ak as Setter, al as SetterRecord, am as Stable, an as State, ao as StrictPathKey, ap as SubtractDepth, aq as SyncOptions, ar as SyncOptionsTuple, as as TERMINATOR, at as Target, au as Unflatten, av as UnionToIntersection, aw as UpdatePayload, ax as VERSION, ay as Volatile, az as Watcher, aA as WatcherRecord, W as WildPaths, aB as getRaw, aC as getSnapshotVersion, aD as getVersion, aE as inert, aF as intent, aG as isInert, aH as isIntent, aI as isVolatile, aJ as live, aK as methods, aL as reactive, aM as stable, aN as state, aO as volatile } from './index-m0aAWxhX.js';
|
package/dist/index.js
CHANGED
|
@@ -15,11 +15,10 @@ import {
|
|
|
15
15
|
stable,
|
|
16
16
|
state,
|
|
17
17
|
volatile
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-MSTHQVNK.js";
|
|
19
19
|
import {
|
|
20
20
|
CTX,
|
|
21
21
|
EVT_OPTS,
|
|
22
|
-
EVT_WARN,
|
|
23
22
|
INDIFFABLE,
|
|
24
23
|
INERTIA,
|
|
25
24
|
NIL,
|
|
@@ -31,11 +30,10 @@ import {
|
|
|
31
30
|
SSVERSION,
|
|
32
31
|
TERMINATOR,
|
|
33
32
|
VERSION
|
|
34
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-MKL3JUPO.js";
|
|
35
34
|
export {
|
|
36
35
|
CTX,
|
|
37
36
|
EVT_OPTS,
|
|
38
|
-
EVT_WARN,
|
|
39
37
|
INDIFFABLE,
|
|
40
38
|
INERTIA,
|
|
41
39
|
NIL,
|