sia-reactor 0.0.22 → 0.0.24
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 +4 -4
- package/dist/{TimeTravelOverlay-eWjAy0yr.d.ts → TimeTravelOverlay-BdJMMcX9.d.ts} +2 -2
- package/dist/{TimeTravelOverlay-DiXUgbUU.d.cts → TimeTravelOverlay-XwZju4iS.d.cts} +2 -2
- package/dist/adapters/react.cjs +63 -42
- package/dist/adapters/react.d.cts +7 -7
- package/dist/adapters/react.d.ts +7 -7
- package/dist/adapters/react.js +3 -3
- package/dist/adapters/vanilla.cjs +63 -42
- 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-3SKLWTEA.js → chunk-4FES5IIH.js} +53 -36
- package/dist/{chunk-CS3FOV6J.js → chunk-6V5NR37Q.js} +6 -6
- package/dist/{chunk-BTA6MIQ6.js → chunk-EZ4VRGYI.js} +40 -26
- package/dist/{index-BgbbNXTW.d.cts → index-CDRimfvj.d.cts} +73 -49
- package/dist/{index-BgbbNXTW.d.ts → index-CDRimfvj.d.ts} +73 -49
- package/dist/index.cjs +66 -45
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/modules.cjs +110 -88
- package/dist/modules.d.cts +16 -17
- package/dist/modules.d.ts +16 -17
- package/dist/modules.js +33 -39
- package/dist/super.d.ts +113 -87
- package/dist/super.global.js +125 -101
- package/dist/{timeTravel-YUxRHRgh.d.ts → timeTravel-CVgE6N0I.d.cts} +20 -20
- package/dist/{timeTravel-CraHdbXZ.d.cts → timeTravel-Cb8MHdYz.d.ts} +20 -20
- package/dist/utils.cjs +43 -26
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,7 +102,7 @@ import { setAny, getAny, mergeObjs } from "sia-reactor/utils";
|
|
|
102
102
|
|
|
103
103
|
```javascript
|
|
104
104
|
import { reactive, Reactor } from "sia-reactor";
|
|
105
|
-
import "sia-reactor/utils"; // deep object helpers (setAny/getAny/deleteAny/inAny/parseAnyObj/fanout/mergeObjs/deepClone/nuke...)
|
|
105
|
+
import "sia-reactor/utils"; // deep object helpers (setAny/getAny/deleteAny/inAny/parseAnyObj/fanout/mergeObjs/deepClone/nuke...) take note of `fanout`!
|
|
106
106
|
import "sia-reactor/modules"; // built-in modules + storage adapters
|
|
107
107
|
import "sia-reactor/adapters/vanilla"; // Autotracker + effect API + TimeTravelOverlay class
|
|
108
108
|
import "sia-reactor/adapters/react"; // useReactor/useSelector/usePath hooks
|
|
@@ -245,7 +245,7 @@ const persist = new PersistModule({ // Plug it in. State is now automatically hy
|
|
|
245
245
|
key: "APP_PREFS",
|
|
246
246
|
paths: ["theme", "settings.brightness"],
|
|
247
247
|
throttle: 5000,
|
|
248
|
-
fanout: true, // async hydration should use leaf writes
|
|
248
|
+
fanout: true, // async hydration should use leaf writes to sync already initialized listeners.
|
|
249
249
|
adapter: new IndexedDBAdapter({ dbName: "Session", version: 1, onversionchange: () => location.reload(), useSnapshot: true }) // or `LocalStorageAdapter` (instance or signature)
|
|
250
250
|
};
|
|
251
251
|
state.use(persist, getReactor(state))); // Put `Reactor` as second constructor arg if you want type inference, e.g. for the paths in the array.
|
|
@@ -346,7 +346,7 @@ player.on("intent.playing", (e) => {
|
|
|
346
346
|
### Troubleshooting
|
|
347
347
|
|
|
348
348
|
- Listener timing feels late: `on(path, ...)` is microtask-batched by design; use `watch(path, ...)` only for strict immediate engine sync on leaf paths preferably.
|
|
349
|
-
- Listeners don't react to changes: use `fanout(
|
|
349
|
+
- Listeners don't react to changes: use `fanout(target, object, { depth: n })` instead of direct object sets to keep immutable semantics.
|
|
350
350
|
- `reject()` appears ignored: call it in capture phase and ensure branch is wrapped in `intent(...)`, also remember it's the listener's choice to comply.
|
|
351
351
|
- Snapshot behavior feels stale: enable `referenceTracking: true` with `smartCloning: true`, also use these when persisting to environments that don't take proxies, e.g. IndexedDB.
|
|
352
352
|
- Cross-frame data is skipped: enable `crossRealms: true` for iframe/other realm objects.
|
|
@@ -475,7 +475,7 @@ rtr.on("todos", ({ type, target: { path, key } }) => {
|
|
|
475
475
|
if (type === "update") console.log(path, key);
|
|
476
476
|
}, { depth: 1 });
|
|
477
477
|
// Better: narrow first, then destructure inside
|
|
478
|
-
rtr.on("todos", (e: REvent<
|
|
478
|
+
rtr.on("todos", (e: REvent<User, "todos", 1>) => {
|
|
479
479
|
if (e.type === "update") {
|
|
480
480
|
const { path, key } = e.target;
|
|
481
481
|
console.log(path, key); // or e.target.path, e.target.key
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as Reactive } from './index-
|
|
2
|
-
import { m as TimeTravelModule } from './timeTravel-
|
|
1
|
+
import { d as Reactive } from './index-CDRimfvj.js';
|
|
2
|
+
import { m as TimeTravelModule } from './timeTravel-Cb8MHdYz.js';
|
|
3
3
|
|
|
4
4
|
/** Reactive options for the TimeTravel overlay instance. */
|
|
5
5
|
interface TimeTravelConfig {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as Reactive } from './index-
|
|
2
|
-
import { m as TimeTravelModule } from './timeTravel-
|
|
1
|
+
import { d as Reactive } from './index-CDRimfvj.cjs';
|
|
2
|
+
import { m as TimeTravelModule } from './timeTravel-CVgE6N0I.cjs';
|
|
3
3
|
|
|
4
4
|
/** Reactive options for the TimeTravel overlay instance. */
|
|
5
5
|
interface TimeTravelConfig {
|
package/dist/adapters/react.cjs
CHANGED
|
@@ -63,7 +63,7 @@ var NOOP = () => {
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
// src/ts/utils/obj.ts
|
|
66
|
-
var
|
|
66
|
+
var arrRegex = /^([^\[\]]+)\[(\d+)\]$/;
|
|
67
67
|
function isObj(obj, arraycheck = true) {
|
|
68
68
|
return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
|
|
69
69
|
}
|
|
@@ -71,9 +71,9 @@ function isPOJO(obj, config = NIL, typecheck = true) {
|
|
|
71
71
|
return (typecheck ? isObj(obj, false) : true) && (config.crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
|
|
72
72
|
}
|
|
73
73
|
function canHandle(obj, config = NIL, typecheck = true) {
|
|
74
|
-
if (typecheck && !isObj(obj, false)) return false;
|
|
74
|
+
if (typecheck && !isObj(obj, false) || obj[INERTIA]) return false;
|
|
75
75
|
if (Array.isArray(obj) || !config.preserveContext && isPOJO(obj, config, false)) return true;
|
|
76
|
-
if (config.preserveContext) return !(obj instanceof
|
|
76
|
+
if (config.preserveContext) return !(obj instanceof String) && !(obj instanceof Number) && !(obj instanceof Function) && !(obj instanceof Date) && !(obj instanceof Error) && !(obj instanceof RegExp) && !(obj instanceof Promise) && !(obj instanceof Map) && !(obj instanceof WeakMap) && !(obj instanceof Set) && !(obj instanceof WeakSet) && !(obj instanceof EventTarget);
|
|
77
77
|
return false;
|
|
78
78
|
}
|
|
79
79
|
function getAny(source, key, separator = ".", keyFunc) {
|
|
@@ -82,7 +82,7 @@ function getAny(source, key, separator = ".", keyFunc) {
|
|
|
82
82
|
const keys2 = key.split(separator);
|
|
83
83
|
let currObj = source;
|
|
84
84
|
for (let i = 0, len = keys2.length; i < len; i++) {
|
|
85
|
-
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(
|
|
85
|
+
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
86
86
|
if (match) {
|
|
87
87
|
const [, key3, iStr] = match;
|
|
88
88
|
if (!Array.isArray(currObj[key3]) || !(key3 in currObj)) return void 0;
|
|
@@ -99,7 +99,7 @@ function setAny(target, key, value, separator = ".", keyFunc) {
|
|
|
99
99
|
if (!key.includes(separator)) return void (target[keyFunc ? keyFunc(key) : key] = value);
|
|
100
100
|
const keys2 = key.split(separator);
|
|
101
101
|
for (let currObj = target, i = 0, len = keys2.length; i < len; i++) {
|
|
102
|
-
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(
|
|
102
|
+
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
103
103
|
if (match) {
|
|
104
104
|
const [, key3, iStr] = match;
|
|
105
105
|
if (!Array.isArray(currObj[key3])) currObj[key3] = [];
|
|
@@ -120,7 +120,7 @@ function deleteAny(target, key, separator = ".", keyFunc) {
|
|
|
120
120
|
if (!key.includes(separator)) return void delete target[keyFunc ? keyFunc(key) : key];
|
|
121
121
|
const keys2 = key.split(separator);
|
|
122
122
|
for (let currObj = target, i = 0, len = keys2.length; i < len; i++) {
|
|
123
|
-
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(
|
|
123
|
+
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
124
124
|
if (match) {
|
|
125
125
|
const [, key3, iStr] = match;
|
|
126
126
|
if (!Array.isArray(currObj[key3]) || !(key3 in currObj)) return;
|
|
@@ -138,7 +138,7 @@ function inAny(source, key, separator = ".", keyFunc) {
|
|
|
138
138
|
if (!key.includes(separator)) return key in source;
|
|
139
139
|
const keys2 = key.split(separator);
|
|
140
140
|
for (let currObj = source, i = 0, len = keys2.length; i < len; i++) {
|
|
141
|
-
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(
|
|
141
|
+
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
142
142
|
if (match) {
|
|
143
143
|
const [, key3, iStr] = match;
|
|
144
144
|
if (!Array.isArray(currObj[key3]) || !(key3 in currObj)) return false;
|
|
@@ -157,7 +157,10 @@ function parseEvtOpts(options, opts, boolOpt = opts[0], result = {}) {
|
|
|
157
157
|
}
|
|
158
158
|
function getTrailRecords(obj, path, reverse = false) {
|
|
159
159
|
const parts = path.split("."), chain = [["*", obj, obj]];
|
|
160
|
-
for (let acc = "", currObj = obj, i = 0, len = parts.length; i < len; i++)
|
|
160
|
+
for (let acc = "", currObj = obj, i = 0, len = parts.length; i < len; i++) {
|
|
161
|
+
const part = parts[i];
|
|
162
|
+
chain.push([acc += (i ? "." : "") + part, currObj, currObj = currObj?.[part]]);
|
|
163
|
+
}
|
|
161
164
|
return reverse ? chain.reverse() : chain;
|
|
162
165
|
}
|
|
163
166
|
function nuke(target) {
|
|
@@ -165,10 +168,11 @@ function nuke(target) {
|
|
|
165
168
|
while (proto && proto !== Object.prototype) {
|
|
166
169
|
const keys2 = Object.getOwnPropertyNames(proto);
|
|
167
170
|
for (let i = 0, len = keys2.length; i < len; i++) {
|
|
168
|
-
|
|
171
|
+
const key = keys2[i];
|
|
172
|
+
if (key === "constructor") continue;
|
|
169
173
|
const desc = Object.getOwnPropertyDescriptor(proto, keys2[i]);
|
|
170
174
|
if (desc && ("function" === typeof desc.value || desc.get || desc.set)) continue;
|
|
171
|
-
proto[
|
|
175
|
+
proto[key] = null;
|
|
172
176
|
}
|
|
173
177
|
proto = Object.getPrototypeOf(proto);
|
|
174
178
|
}
|
|
@@ -339,7 +343,7 @@ var Reactor = class {
|
|
|
339
343
|
if (this.config.referenceTracking && parent && key && !this.link(target, parent, key, false)) return target;
|
|
340
344
|
const cached = this.proxyCache.get(target);
|
|
341
345
|
if (cached) return cached;
|
|
342
|
-
if (
|
|
346
|
+
if (!canHandle(target, this.config, false)) return target;
|
|
343
347
|
rejectable ||= target[REJECTABLE];
|
|
344
348
|
indiffable ||= target[INDIFFABLE];
|
|
345
349
|
const proxy = new Proxy(target, {
|
|
@@ -463,7 +467,10 @@ var Reactor = class {
|
|
|
463
467
|
seen.add(target);
|
|
464
468
|
const es = (this.lineage ??= /* @__PURE__ */ new WeakMap()).get(target);
|
|
465
469
|
if (!es) return paths;
|
|
466
|
-
for (let i = 0, len = es.length; i < len; i += 2)
|
|
470
|
+
for (let i = 0, len = es.length; i < len; i += 2) {
|
|
471
|
+
const prev = es[i + 1];
|
|
472
|
+
this.trace(es[i], prev ? prev + "." + path : path, paths, seen);
|
|
473
|
+
}
|
|
467
474
|
return paths;
|
|
468
475
|
}
|
|
469
476
|
// won't be called without `.config.referenceTracking` so internal guard avoided
|
|
@@ -493,9 +500,9 @@ var Reactor = class {
|
|
|
493
500
|
let terminated = false, value = payload.target.value;
|
|
494
501
|
const isGet = type === "get", isSet = type === "set", mediators = isGet ? this.getters : isSet ? this.setters : this.deleters;
|
|
495
502
|
for (let i = !isGet ? 0 : cords.length - 1, len = !isGet ? cords.length : -1; i !== len; i += !isGet ? 1 : -1) {
|
|
496
|
-
const response = isGet ?
|
|
503
|
+
const cord = cords[i], response = isGet ? cord.cb(value, payload) : isSet ? cord.cb(value, terminated, payload) : cord.cb(terminated, payload);
|
|
497
504
|
if (isGet || !(terminated ||= payload.terminated = response === TERMINATOR)) value = response;
|
|
498
|
-
if (
|
|
505
|
+
if (cord.once) cords.splice((len--, i--), 1), !cords.length && mediators.delete(path);
|
|
499
506
|
}
|
|
500
507
|
return value;
|
|
501
508
|
}
|
|
@@ -504,13 +511,15 @@ var Reactor = class {
|
|
|
504
511
|
const wildcords = this.watchers.get("*"), cords = this.watchers.get(path);
|
|
505
512
|
if (cords)
|
|
506
513
|
for (let i = 0, len = cords.length; i < len; i++) {
|
|
507
|
-
cords[i]
|
|
508
|
-
|
|
514
|
+
const cord = cords[i];
|
|
515
|
+
cord.cb(payload.target.value, payload);
|
|
516
|
+
if (cord.once) cords.splice((len--, i--), 1), !cords.length && this.watchers.delete(path);
|
|
509
517
|
}
|
|
510
518
|
if (wildcords)
|
|
511
519
|
for (let i = 0, len = wildcords.length; i < len; i++) {
|
|
512
|
-
wildcords[i]
|
|
513
|
-
|
|
520
|
+
const wildcord = wildcords[i];
|
|
521
|
+
wildcord.cb(payload.target.value, payload);
|
|
522
|
+
if (wildcord.once) wildcords.splice((len--, i--), 1), !wildcords.length && this.watchers.delete("*");
|
|
514
523
|
}
|
|
515
524
|
}
|
|
516
525
|
this.listeners && this.schedule(path, payload);
|
|
@@ -549,14 +558,15 @@ var Reactor = class {
|
|
|
549
558
|
e.type = path !== e.target.path ? "update" : e.staticType;
|
|
550
559
|
e.currentTarget = { path, value, oldValue: e.type !== "update" ? e.target.oldValue : void 0, key: e.type !== "update" ? path : path.slice(path.lastIndexOf(".") + 1) || "", hadKey: e.type !== "update" ? e.target.hadKey : true, object };
|
|
551
560
|
for (let i = 0, len = cords.length, tDepth; i < len; i++) {
|
|
561
|
+
const cord = cords[i];
|
|
552
562
|
if (e.immediatePropagationStopped) break;
|
|
553
|
-
if (
|
|
554
|
-
if (
|
|
563
|
+
if (cord.capture !== isCapture) continue;
|
|
564
|
+
if (cord.depth !== void 0) {
|
|
555
565
|
tDepth ??= this.getDepth(e.target.path);
|
|
556
|
-
if (tDepth >
|
|
566
|
+
if (tDepth > cord.lDepth + cord.depth) continue;
|
|
557
567
|
}
|
|
558
|
-
|
|
559
|
-
if (
|
|
568
|
+
cord.cb(e);
|
|
569
|
+
if (cord.once) cords.splice((len--, i--), 1), !cords.length && this.listeners.delete(path);
|
|
560
570
|
}
|
|
561
571
|
}
|
|
562
572
|
/**
|
|
@@ -618,24 +628,28 @@ var Reactor = class {
|
|
|
618
628
|
const clone = !raw ? this.config.preserveContext ? Object.create(Object.getPrototypeOf(obj)) : Array.isArray(obj) ? [] : {} : obj;
|
|
619
629
|
seen.set(obj, clone);
|
|
620
630
|
const keys2 = this.config.preserveContext ? Reflect.ownKeys(obj) : Object.keys(obj);
|
|
621
|
-
for (let i = 0, len = keys2.length; i < len; i++)
|
|
631
|
+
for (let i = 0, len = keys2.length; i < len; i++) {
|
|
632
|
+
const key = keys2[i];
|
|
622
633
|
try {
|
|
623
|
-
clone[
|
|
624
|
-
} catch {
|
|
634
|
+
clone[key] = this.cloned(obj[key], raw, seen);
|
|
635
|
+
} catch (e) {
|
|
636
|
+
if (e instanceof RangeError) throw e;
|
|
625
637
|
}
|
|
638
|
+
}
|
|
626
639
|
if (!raw && this.config.smartCloning) this.snapCache.set(obj, clone), obj[SSVERSION] = version;
|
|
627
640
|
return clone;
|
|
628
641
|
}
|
|
629
642
|
syncAdd(key, path, cb, opts, onImmediate = NOOP) {
|
|
630
643
|
const { lazy = false, once = false, signal, immediate = false } = parseEvtOpts(opts, EVT_OPTS.MEDIATOR), store = this[`${key}${key.endsWith("t") ? "t" : ""}ers`] ??= /* @__PURE__ */ new Map();
|
|
631
644
|
let cords = store.get(path), cord;
|
|
632
|
-
if (cords)
|
|
633
|
-
for (let i = 0, len = cords.length; i < len; i++)
|
|
634
|
-
|
|
635
|
-
|
|
645
|
+
if (cords)
|
|
646
|
+
for (let i = 0, len = cords.length; i < len; i++) {
|
|
647
|
+
const excord = cords[i];
|
|
648
|
+
if (Object.is(excord.cb, cb)) {
|
|
649
|
+
cord = excord;
|
|
636
650
|
break;
|
|
637
651
|
}
|
|
638
|
-
|
|
652
|
+
}
|
|
639
653
|
if (cord) return cord.clup;
|
|
640
654
|
let task;
|
|
641
655
|
cord = { cb, once, clup: () => (lazy && this.nostall(task), this[`no${key}`](path, cb)) };
|
|
@@ -647,7 +661,10 @@ var Reactor = class {
|
|
|
647
661
|
syncDrop(store, path, cb) {
|
|
648
662
|
const cords = store?.get(path);
|
|
649
663
|
if (!cords) return void 0;
|
|
650
|
-
for (let i = 0, len = cords.length; i < len; i++)
|
|
664
|
+
for (let i = 0, len = cords.length; i < len; i++) {
|
|
665
|
+
const cord = cords[i];
|
|
666
|
+
if (Object.is(cord.cb, cb)) return cord.sclup(), cords.splice((len--, i--), 1), !cords.length && store.delete(path), true;
|
|
667
|
+
}
|
|
651
668
|
return false;
|
|
652
669
|
}
|
|
653
670
|
/**
|
|
@@ -765,13 +782,14 @@ var Reactor = class {
|
|
|
765
782
|
this.listeners ??= /* @__PURE__ */ new Map();
|
|
766
783
|
const { capture = false, once = false, signal, immediate = false, depth } = parseEvtOpts(options, EVT_OPTS.LISTENER);
|
|
767
784
|
let cords = this.listeners.get(path), cord;
|
|
768
|
-
if (cords)
|
|
769
|
-
for (let i = 0, len = cords.length; i < len; i++)
|
|
770
|
-
|
|
771
|
-
|
|
785
|
+
if (cords)
|
|
786
|
+
for (let i = 0, len = cords.length; i < len; i++) {
|
|
787
|
+
const excord = cords[i];
|
|
788
|
+
if (Object.is(excord.cb, callback) && capture === excord.capture) {
|
|
789
|
+
cord = excord;
|
|
772
790
|
break;
|
|
773
791
|
}
|
|
774
|
-
|
|
792
|
+
}
|
|
775
793
|
if (cord) return cord.clup;
|
|
776
794
|
cord = { cb: callback, capture, depth, once, clup: () => this.off(path, callback, options), lDepth: depth !== void 0 ? this.getDepth(path) : depth };
|
|
777
795
|
if (immediate && (immediate !== "auto" || inAny(this.core, path))) {
|
|
@@ -800,7 +818,10 @@ var Reactor = class {
|
|
|
800
818
|
const cords = this.listeners?.get(path);
|
|
801
819
|
if (!cords) return void 0;
|
|
802
820
|
const { capture } = parseEvtOpts(options, EVT_OPTS.LISTENER);
|
|
803
|
-
for (let i = 0, len = cords.length; i < len; i++)
|
|
821
|
+
for (let i = 0, len = cords.length; i < len; i++) {
|
|
822
|
+
const cord = cords[i];
|
|
823
|
+
if (Object.is(cord.cb, callback) && cord.capture === capture) return cord.sclup(), cords.splice((len--, i--), 1), !cords.length && this.listeners.delete(path), true;
|
|
824
|
+
}
|
|
804
825
|
return false;
|
|
805
826
|
}
|
|
806
827
|
snapshot(raw = !this.config.smartCloning, branch) {
|
|
@@ -872,19 +893,19 @@ var Autotracker = class {
|
|
|
872
893
|
this.autortr = this.rtr = rtr;
|
|
873
894
|
}
|
|
874
895
|
/**
|
|
875
|
-
* Starts a new tracking pass and returns a tracking proxy for `target` if `this` was instantiated with a `Reactor`.
|
|
896
|
+
* Starts a new tracking pass and returns a readonly tracking proxy for `target` if `this` was instantiated with a `Reactor`.
|
|
876
897
|
* @param target Snapshot (or state branch) to track reads from.
|
|
877
|
-
* @returns Read-tracking proxy.
|
|
898
|
+
* @returns Read-tracking readonly proxy.
|
|
878
899
|
* @example
|
|
879
900
|
* const atrkr = new Autotracker(rtr);
|
|
880
901
|
* const state = atrkr.tracked(rtr.snapshot());
|
|
881
902
|
* const name = state.user.profile.name;
|
|
882
903
|
*/
|
|
883
904
|
tracked(target) {
|
|
884
|
-
return this.unblock(), this.
|
|
905
|
+
return this.unblock(), this.proxy = this.proxied(target, "");
|
|
885
906
|
}
|
|
886
907
|
proxied(obj, path) {
|
|
887
|
-
if (!obj || "object" !== typeof obj) return obj;
|
|
908
|
+
if (!this.rtr || !obj || "object" !== typeof obj) return obj;
|
|
888
909
|
const cached = this.proxyCache.get(obj);
|
|
889
910
|
if (cached) return cached;
|
|
890
911
|
if (!canHandle(obj, this.rtr.config, false)) return obj;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { E as EffectOptions, R as Reactor, d as Reactive,
|
|
1
|
+
import { E as EffectOptions, R as Reactor, d as Reactive, v as ReactorBuild, D as DeepReadonly, W as WildPaths, e as PathValue } from '../index-CDRimfvj.cjs';
|
|
2
2
|
import { useLayoutEffect } from 'react';
|
|
3
|
-
import { m as TimeTravelModule } from '../timeTravel-
|
|
4
|
-
import { T as TimeTravelConfig } from '../TimeTravelOverlay-
|
|
3
|
+
import { m as TimeTravelModule } from '../timeTravel-CVgE6N0I.cjs';
|
|
4
|
+
import { T as TimeTravelConfig } from '../TimeTravelOverlay-XwZju4iS.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Subscribes a component to desired Reactor state and returns it.
|
|
@@ -30,7 +30,7 @@ declare function useReactor<T extends object>(target: T | Reactor<T> | Reactive<
|
|
|
30
30
|
*/
|
|
31
31
|
declare function useAnyReactor(options?: EffectOptions): void;
|
|
32
32
|
/**
|
|
33
|
-
* Subscribes a component to Reactor state and returns a tracked snapshot.
|
|
33
|
+
* Subscribes a component to Reactor state and returns a readonly tracked snapshot.
|
|
34
34
|
* Rule of thumb: read from snapshots, mutate the source.
|
|
35
35
|
* The hook uses access tracking so re-renders occur only when accessed fields change.
|
|
36
36
|
* @typeParam T Root state object type.
|
|
@@ -47,7 +47,7 @@ declare function useAnyReactor(options?: EffectOptions): void;
|
|
|
47
47
|
* const rtr = new Reactor({ user: { name: "Kosi" } });
|
|
48
48
|
* const c = useReactorSnapshot(rtr);
|
|
49
49
|
*/
|
|
50
|
-
declare function useReactorSnapshot<T extends object>(target: T | Reactor<T> | Reactive<T>, options?: EffectOptions, build?: ReactorBuild<T>): T
|
|
50
|
+
declare function useReactorSnapshot<T extends object>(target: T | Reactor<T> | Reactive<T>, options?: EffectOptions, build?: ReactorBuild<T>): DeepReadonly<T>;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Subscribes to a derived slice of Reactor state.
|
|
@@ -84,7 +84,7 @@ declare function useSelector<T extends object, R>(target: T | Reactor<T> | React
|
|
|
84
84
|
declare function useAnySelector<R>(sel: () => R, eq?: (value1: any, value2: any) => boolean, options?: EffectOptions): R;
|
|
85
85
|
/**
|
|
86
86
|
* Subscribes to a derived slice of Reactor state.
|
|
87
|
-
* The selector runs against a tracked snapshot and uses the provided equality function
|
|
87
|
+
* The selector runs against a readonly tracked snapshot and uses the provided equality function
|
|
88
88
|
* to suppress unchanged results.
|
|
89
89
|
* @typeParam T Root state object type.
|
|
90
90
|
* @typeParam R Selector return type.
|
|
@@ -103,7 +103,7 @@ declare function useAnySelector<R>(sel: () => R, eq?: (value1: any, value2: any)
|
|
|
103
103
|
* const rtr = new Reactor({ user: { name: "Kosi" } });
|
|
104
104
|
* const c = useSelectorSnapshot(rtr, (s) => s.user.name);
|
|
105
105
|
*/
|
|
106
|
-
declare function useSelectorSnapshot<T extends object, R>(target: T | Reactor<T> | Reactive<T>, sel: (state: T) => R, eq?: (value1: any, value2: any) => boolean, options?: EffectOptions, build?: ReactorBuild<T>): R;
|
|
106
|
+
declare function useSelectorSnapshot<T extends object, R>(target: T | Reactor<T> | Reactive<T>, sel: (state: DeepReadonly<T>) => R, eq?: (value1: any, value2: any) => boolean, options?: EffectOptions, build?: ReactorBuild<T>): R;
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Subscribes to a single path in Reactor state.
|
package/dist/adapters/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { E as EffectOptions, R as Reactor, d as Reactive,
|
|
1
|
+
import { E as EffectOptions, R as Reactor, d as Reactive, v as ReactorBuild, D as DeepReadonly, W as WildPaths, e as PathValue } from '../index-CDRimfvj.js';
|
|
2
2
|
import { useLayoutEffect } from 'react';
|
|
3
|
-
import { m as TimeTravelModule } from '../timeTravel-
|
|
4
|
-
import { T as TimeTravelConfig } from '../TimeTravelOverlay-
|
|
3
|
+
import { m as TimeTravelModule } from '../timeTravel-Cb8MHdYz.js';
|
|
4
|
+
import { T as TimeTravelConfig } from '../TimeTravelOverlay-BdJMMcX9.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Subscribes a component to desired Reactor state and returns it.
|
|
@@ -30,7 +30,7 @@ declare function useReactor<T extends object>(target: T | Reactor<T> | Reactive<
|
|
|
30
30
|
*/
|
|
31
31
|
declare function useAnyReactor(options?: EffectOptions): void;
|
|
32
32
|
/**
|
|
33
|
-
* Subscribes a component to Reactor state and returns a tracked snapshot.
|
|
33
|
+
* Subscribes a component to Reactor state and returns a readonly tracked snapshot.
|
|
34
34
|
* Rule of thumb: read from snapshots, mutate the source.
|
|
35
35
|
* The hook uses access tracking so re-renders occur only when accessed fields change.
|
|
36
36
|
* @typeParam T Root state object type.
|
|
@@ -47,7 +47,7 @@ declare function useAnyReactor(options?: EffectOptions): void;
|
|
|
47
47
|
* const rtr = new Reactor({ user: { name: "Kosi" } });
|
|
48
48
|
* const c = useReactorSnapshot(rtr);
|
|
49
49
|
*/
|
|
50
|
-
declare function useReactorSnapshot<T extends object>(target: T | Reactor<T> | Reactive<T>, options?: EffectOptions, build?: ReactorBuild<T>): T
|
|
50
|
+
declare function useReactorSnapshot<T extends object>(target: T | Reactor<T> | Reactive<T>, options?: EffectOptions, build?: ReactorBuild<T>): DeepReadonly<T>;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Subscribes to a derived slice of Reactor state.
|
|
@@ -84,7 +84,7 @@ declare function useSelector<T extends object, R>(target: T | Reactor<T> | React
|
|
|
84
84
|
declare function useAnySelector<R>(sel: () => R, eq?: (value1: any, value2: any) => boolean, options?: EffectOptions): R;
|
|
85
85
|
/**
|
|
86
86
|
* Subscribes to a derived slice of Reactor state.
|
|
87
|
-
* The selector runs against a tracked snapshot and uses the provided equality function
|
|
87
|
+
* The selector runs against a readonly tracked snapshot and uses the provided equality function
|
|
88
88
|
* to suppress unchanged results.
|
|
89
89
|
* @typeParam T Root state object type.
|
|
90
90
|
* @typeParam R Selector return type.
|
|
@@ -103,7 +103,7 @@ declare function useAnySelector<R>(sel: () => R, eq?: (value1: any, value2: any)
|
|
|
103
103
|
* const rtr = new Reactor({ user: { name: "Kosi" } });
|
|
104
104
|
* const c = useSelectorSnapshot(rtr, (s) => s.user.name);
|
|
105
105
|
*/
|
|
106
|
-
declare function useSelectorSnapshot<T extends object, R>(target: T | Reactor<T> | Reactive<T>, sel: (state: T) => R, eq?: (value1: any, value2: any) => boolean, options?: EffectOptions, build?: ReactorBuild<T>): R;
|
|
106
|
+
declare function useSelectorSnapshot<T extends object, R>(target: T | Reactor<T> | Reactive<T>, sel: (state: DeepReadonly<T>) => R, eq?: (value1: any, value2: any) => boolean, options?: EffectOptions, build?: ReactorBuild<T>): R;
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Subscribes to a single path in Reactor state.
|
package/dist/adapters/react.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
Autotracker,
|
|
3
3
|
TimeTravelOverlay,
|
|
4
4
|
withTracker
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-6V5NR37Q.js";
|
|
6
6
|
import {
|
|
7
7
|
getReactor
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-4FES5IIH.js";
|
|
9
9
|
import "../chunk-5A44QFT6.js";
|
|
10
10
|
import "../chunk-P37ADJMM.js";
|
|
11
11
|
import {
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
NIL,
|
|
14
14
|
NOOP,
|
|
15
15
|
getAny
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-EZ4VRGYI.js";
|
|
17
17
|
|
|
18
18
|
// src/ts/adapters/react/hooks/useReactor.ts
|
|
19
19
|
import { useRef, useCallback, useSyncExternalStore, useMemo } from "react";
|