sia-reactor 0.0.33 → 0.0.34
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 +5 -4
- package/dist/{TimeTravelOverlay-BlVhj8n1.d.cts → TimeTravelOverlay-DTqM5uJB.d.cts} +2 -2
- package/dist/{TimeTravelOverlay-D8jAd_Fz.d.ts → TimeTravelOverlay-cSlHzoKB.d.ts} +2 -2
- package/dist/adapters/react.cjs +18 -20
- package/dist/adapters/react.d.cts +3 -3
- package/dist/adapters/react.d.ts +3 -3
- package/dist/adapters/react.js +6 -6
- package/dist/adapters/vanilla.cjs +17 -19
- package/dist/adapters/vanilla.d.cts +4 -4
- package/dist/adapters/vanilla.d.ts +4 -4
- package/dist/adapters/vanilla.js +4 -4
- package/dist/{chunk-EZ4VRGYI.js → chunk-4PLMBUCP.js} +13 -17
- package/dist/{chunk-UXQ5NJIO.js → chunk-CEPDD5XN.js} +3 -3
- package/dist/{chunk-6HZSS2TX.js → chunk-T2CAL5F4.js} +18 -16
- package/dist/{chunk-QPJNSYXT.js → chunk-VIDZLTP2.js} +2 -2
- package/dist/{index-CWbDYjby.d.cts → index-0TjDsae1.d.cts} +15 -15
- package/dist/{index-CWbDYjby.d.ts → index-0TjDsae1.d.ts} +15 -15
- package/dist/index.cjs +17 -19
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/modules.cjs +34 -32
- package/dist/modules.d.cts +4 -4
- package/dist/modules.d.ts +4 -4
- package/dist/modules.js +21 -17
- package/dist/super.d.ts +22 -22
- package/dist/super.global.js +41 -39
- package/dist/{timeTravel-BsVQ5z7v.d.ts → timeTravel-CX100S8f.d.ts} +3 -3
- package/dist/{timeTravel-DoWtLH_e.d.cts → timeTravel-wU23uudD.d.cts} +3 -3
- package/dist/utils.cjs +18 -22
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +11 -11
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -50,8 +50,9 @@ const player = reactive({
|
|
|
50
50
|
|
|
51
51
|
// Logic layer (capture phase)
|
|
52
52
|
player.on("intent.playing", (e) => {
|
|
53
|
-
if (!ready) return e.reject();
|
|
53
|
+
if (!ready) return e.reject(); // warning optimistic UI
|
|
54
54
|
player.state.playing = true;
|
|
55
|
+
e.resolve(); // claimed and handled
|
|
55
56
|
}, { capture: true });
|
|
56
57
|
|
|
57
58
|
// UI layer
|
|
@@ -92,7 +93,7 @@ pnpm add sia-reactor
|
|
|
92
93
|
import { reactive, Reactor, TERMINATOR } from "sia-reactor";
|
|
93
94
|
|
|
94
95
|
// 2. Deep Object Utilities
|
|
95
|
-
import {
|
|
96
|
+
import { setPath, getPath, mergeObjs } from "sia-reactor/utils";
|
|
96
97
|
```
|
|
97
98
|
|
|
98
99
|
---
|
|
@@ -103,7 +104,7 @@ import { setAny, getAny, mergeObjs } from "sia-reactor/utils";
|
|
|
103
104
|
|
|
104
105
|
```javascript
|
|
105
106
|
import { reactive, Reactor } from "sia-reactor";
|
|
106
|
-
import "sia-reactor/utils"; // deep object helpers (
|
|
107
|
+
import "sia-reactor/utils"; // deep object helpers (setPath/getPath/deletePath/hasPath/parsePathObj/fanout/mergeObjs/deepClone/nuke...) take note of `fanout`!
|
|
107
108
|
import "sia-reactor/modules"; // built-in modules + storage adapters
|
|
108
109
|
import "sia-reactor/adapters/vanilla"; // Autotracker + effect API + TimeTravelOverlay class
|
|
109
110
|
import "sia-reactor/adapters/react"; // useReactor/useSelector/usePath hooks
|
|
@@ -269,7 +270,7 @@ const time = new TimeTravelModule({ maxHistory: 300, loop: false, rate: 150, whi
|
|
|
269
270
|
store.use(time);
|
|
270
271
|
|
|
271
272
|
// If persist uses an async adapter (e.g. IndexedDB), wait till after hydration:
|
|
272
|
-
persist.state.once("hydrated", () => store.use(time)); // starts `false`, one-time stall until it flips
|
|
273
|
+
persist.state.once("hydrated", () => store.use(time)); // starts `false`, one-time stall until it flips. i.e, also escapes custom initialization
|
|
273
274
|
effect(() => persist.state.hydrated && store.use(time), { once: true }) // same logic, different look :)
|
|
274
275
|
|
|
275
276
|
const overlay = new TimeTravelOverlay(time, { color: "#e26e02", startOpen: false, devOnly: true, container: document.body }); // optional debug interface for visulazation
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as Reactive } from './index-
|
|
2
|
-
import { m as TimeTravelModule } from './timeTravel-
|
|
1
|
+
import { e as Reactive } from './index-0TjDsae1.cjs';
|
|
2
|
+
import { m as TimeTravelModule } from './timeTravel-wU23uudD.cjs';
|
|
3
3
|
|
|
4
4
|
/** Reactive options for the TimeTravel overlay instance. */
|
|
5
5
|
interface TimeTravelOverlayConfig {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as Reactive } from './index-
|
|
2
|
-
import { m as TimeTravelModule } from './timeTravel-
|
|
1
|
+
import { e as Reactive } from './index-0TjDsae1.js';
|
|
2
|
+
import { m as TimeTravelModule } from './timeTravel-CX100S8f.js';
|
|
3
3
|
|
|
4
4
|
/** Reactive options for the TimeTravel overlay instance. */
|
|
5
5
|
interface TimeTravelOverlayConfig {
|
package/dist/adapters/react.cjs
CHANGED
|
@@ -76,9 +76,8 @@ function canHandle(obj, config = NIL, typecheck = true) {
|
|
|
76
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
|
-
function
|
|
79
|
+
function getPath(source, key, separator = ".", keyFunc) {
|
|
80
80
|
if (key === "*") return source;
|
|
81
|
-
if (!key.includes(separator)) return source[keyFunc ? keyFunc(key) : key];
|
|
82
81
|
const keys2 = key.split(separator);
|
|
83
82
|
let currObj = source;
|
|
84
83
|
for (let i = 0, len = keys2.length; i < len; i++) {
|
|
@@ -94,9 +93,8 @@ function getAny(source, key, separator = ".", keyFunc) {
|
|
|
94
93
|
}
|
|
95
94
|
return currObj;
|
|
96
95
|
}
|
|
97
|
-
function
|
|
96
|
+
function setPath(target, key, value, separator = ".", keyFunc) {
|
|
98
97
|
if (key === "*") return Object.assign(target, value);
|
|
99
|
-
if (!key.includes(separator)) return void (target[keyFunc ? keyFunc(key) : key] = value);
|
|
100
98
|
const keys2 = key.split(separator);
|
|
101
99
|
for (let currObj = target, i = 0, len = keys2.length; i < len; i++) {
|
|
102
100
|
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
@@ -111,13 +109,12 @@ function setAny(target, key, value, separator = ".", keyFunc) {
|
|
|
111
109
|
}
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
|
-
function
|
|
112
|
+
function deletePath(target, key, separator = ".", keyFunc) {
|
|
115
113
|
if (key === "*") {
|
|
116
114
|
const keys3 = Object.keys(target);
|
|
117
115
|
for (let i = 0, len = keys3.length; i < len; i++) delete target[keys3[i]];
|
|
118
116
|
return;
|
|
119
117
|
}
|
|
120
|
-
if (!key.includes(separator)) return void delete target[keyFunc ? keyFunc(key) : key];
|
|
121
118
|
const keys2 = key.split(separator);
|
|
122
119
|
for (let currObj = target, i = 0, len = keys2.length; i < len; i++) {
|
|
123
120
|
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
@@ -133,9 +130,8 @@ function deleteAny(target, key, separator = ".", keyFunc) {
|
|
|
133
130
|
}
|
|
134
131
|
}
|
|
135
132
|
}
|
|
136
|
-
function
|
|
133
|
+
function hasPath(source, key, separator = ".", keyFunc) {
|
|
137
134
|
if (key === "*") return true;
|
|
138
|
-
if (!key.includes(separator)) return key in source;
|
|
139
135
|
const keys2 = key.split(separator);
|
|
140
136
|
for (let currObj = source, i = 0, len = keys2.length; i < len; i++) {
|
|
141
137
|
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
@@ -271,7 +267,7 @@ var ReactorEvent = class _ReactorEvent {
|
|
|
271
267
|
resolve(message) {
|
|
272
268
|
if (!this.rejectable) return this.reactor.log(`[ReactorEvent] Ignored \`resolve()\` call on a non-rejectable ${this.staticType} at "${this.path}"`);
|
|
273
269
|
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.`);
|
|
274
|
-
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._resolved = message ||
|
|
270
|
+
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._resolved = message || `${this.staticType} intent resolved at "${this.path}"`}`);
|
|
275
271
|
}
|
|
276
272
|
/** Rejection reason for rejectable events. */
|
|
277
273
|
get rejected() {
|
|
@@ -286,7 +282,7 @@ var ReactorEvent = class _ReactorEvent {
|
|
|
286
282
|
reject(reason) {
|
|
287
283
|
if (!this.rejectable) return this.reactor.log(`[ReactorEvent] Ignored \`reject()\` call on a non-rejectable ${this.staticType} at "${this.path}"`);
|
|
288
284
|
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.`);
|
|
289
|
-
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._rejected = reason ||
|
|
285
|
+
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._rejected = reason || `${this.staticType} intent rejected at "${this.path}"`}`);
|
|
290
286
|
}
|
|
291
287
|
/**
|
|
292
288
|
* Returns event path values from target to root.
|
|
@@ -624,7 +620,7 @@ var Reactor = class {
|
|
|
624
620
|
return depth;
|
|
625
621
|
}
|
|
626
622
|
getContext(path) {
|
|
627
|
-
const last = path.lastIndexOf("."), value =
|
|
623
|
+
const last = path.lastIndexOf("."), value = getPath(this.core, path), object = last === -1 ? this.core : getPath(this.core, path.slice(0, last));
|
|
628
624
|
return { path, value, key: path.slice(last + 1) || "", hadKey: true, object };
|
|
629
625
|
}
|
|
630
626
|
bindSignal(cord, sig) {
|
|
@@ -689,7 +685,7 @@ var Reactor = class {
|
|
|
689
685
|
* const cleanup = rtr.get("user.name", (value) => String(value).trim());
|
|
690
686
|
*/
|
|
691
687
|
get(path, callback, options) {
|
|
692
|
-
return this.addSync("get", path, callback, options, (imm) => (imm !== "auto" ||
|
|
688
|
+
return this.addSync("get", path, callback, options, (imm) => (imm !== "auto" || hasPath(this.core, path)) && getPath(this.core, path));
|
|
693
689
|
}
|
|
694
690
|
/** Registers a get mediator for a path that only triggers once. */
|
|
695
691
|
gonce(path, callback, options) {
|
|
@@ -714,7 +710,7 @@ var Reactor = class {
|
|
|
714
710
|
* rtr.set("user.name", (value) => String(value).trim());
|
|
715
711
|
*/
|
|
716
712
|
set(path, callback, options) {
|
|
717
|
-
return this.addSync("set", path, callback, options, (imm) => (imm !== "auto" ||
|
|
713
|
+
return this.addSync("set", path, callback, options, (imm) => (imm !== "auto" || hasPath(this.core, path)) && setPath(this.core, path, getPath(this.core, path)));
|
|
718
714
|
}
|
|
719
715
|
/** Registers a set mediator for a path that only triggers once. */
|
|
720
716
|
sonce(path, callback, options) {
|
|
@@ -739,7 +735,7 @@ var Reactor = class {
|
|
|
739
735
|
* rtr.delete("cache.temp", () => TERMINATOR);
|
|
740
736
|
*/
|
|
741
737
|
delete(path, callback, options) {
|
|
742
|
-
return this.addSync("delete", path, callback, options, (imm) => (imm !== "auto" ||
|
|
738
|
+
return this.addSync("delete", path, callback, options, (imm) => (imm !== "auto" || hasPath(this.core, path)) && deletePath(this.core, path));
|
|
743
739
|
}
|
|
744
740
|
/** Registers a delete mediator for a path that only triggers once. */
|
|
745
741
|
donce(path, callback, options) {
|
|
@@ -765,7 +761,7 @@ var Reactor = class {
|
|
|
765
761
|
* const cleanup = rtr.watch("user.name", (value) => console.log(value));
|
|
766
762
|
*/
|
|
767
763
|
watch(path, callback, options) {
|
|
768
|
-
return this.addSync("watch", path, callback, options, (imm) => (imm !== "auto" ||
|
|
764
|
+
return this.addSync("watch", path, callback, options, (imm) => (imm !== "auto" || hasPath(this.core, path)) && (imm === "strict" ? setPath(this.core, path, getPath(this.core, path)) : ((target) => callback(target.value, { type: "init", target, currentTarget: target, root: this.core, rejectable: false }))(this.getContext(path))));
|
|
769
765
|
}
|
|
770
766
|
/** Registers a watcher for a path that only triggers once. */
|
|
771
767
|
wonce(path, callback, options) {
|
|
@@ -804,10 +800,12 @@ var Reactor = class {
|
|
|
804
800
|
}
|
|
805
801
|
if (cord) return cord.clup;
|
|
806
802
|
cord = { cb: callback, capture, depth, once, clup: () => this.off(path, callback, options), lDepth: depth !== void 0 ? this.getDepth(path) : depth };
|
|
807
|
-
if (immediate && (immediate !== "auto" ||
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
803
|
+
if (immediate && (immediate !== "auto" || hasPath(this.core, path)))
|
|
804
|
+
if (immediate === "strict") setPath(this.core, path, getPath(this.core, path));
|
|
805
|
+
else {
|
|
806
|
+
const target = this.getContext(path);
|
|
807
|
+
callback(new ReactorEvent({ type: "init", target, currentTarget: target, root: this.core, rejectable: false }, this));
|
|
808
|
+
}
|
|
811
809
|
(cords ?? (this.listeners.set(path, cords = []), cords)).push(cord);
|
|
812
810
|
return this.bindSignal(cord, signal);
|
|
813
811
|
}
|
|
@@ -1106,7 +1104,7 @@ function usePath(target, path, options = NIL, build) {
|
|
|
1106
1104
|
const subscribe = (0, import_react4.useCallback)((notify) => rtr[optsRef.current.sync ? "watch" : "on"](path, () => (versionRef.current++, notify()), optsRef.current), [rtr, path]);
|
|
1107
1105
|
const getSnapshot = (0, import_react4.useCallback)(() => versionRef.current, []);
|
|
1108
1106
|
(0, import_react4.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
1109
|
-
return
|
|
1107
|
+
return getPath(rtr.core, path);
|
|
1110
1108
|
}
|
|
1111
1109
|
|
|
1112
1110
|
// src/ts/adapters/react/TimeTravelOverlay.tsx
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { E as EffectOptions, a as Reactor, e as Reactive, x as ReactorBuild, D as DeepReadonly, W as WildPaths, f as PathValue } from '../index-
|
|
1
|
+
import { E as EffectOptions, a as Reactor, e as Reactive, x as ReactorBuild, D as DeepReadonly, W as WildPaths, f as PathValue } from '../index-0TjDsae1.cjs';
|
|
2
2
|
import { useLayoutEffect } from 'react';
|
|
3
|
-
import { m as TimeTravelModule } from '../timeTravel-
|
|
4
|
-
import { a as TimeTravelOverlayConfig } from '../TimeTravelOverlay-
|
|
3
|
+
import { m as TimeTravelModule } from '../timeTravel-wU23uudD.cjs';
|
|
4
|
+
import { a as TimeTravelOverlayConfig } from '../TimeTravelOverlay-DTqM5uJB.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Subscribes a component to desired Reactor state and returns it.
|
package/dist/adapters/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { E as EffectOptions, a as Reactor, e as Reactive, x as ReactorBuild, D as DeepReadonly, W as WildPaths, f as PathValue } from '../index-
|
|
1
|
+
import { E as EffectOptions, a as Reactor, e as Reactive, x as ReactorBuild, D as DeepReadonly, W as WildPaths, f as PathValue } from '../index-0TjDsae1.js';
|
|
2
2
|
import { useLayoutEffect } from 'react';
|
|
3
|
-
import { m as TimeTravelModule } from '../timeTravel-
|
|
4
|
-
import { a as TimeTravelOverlayConfig } from '../TimeTravelOverlay-
|
|
3
|
+
import { m as TimeTravelModule } from '../timeTravel-CX100S8f.js';
|
|
4
|
+
import { a as TimeTravelOverlayConfig } from '../TimeTravelOverlay-cSlHzoKB.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Subscribes a component to desired Reactor state and returns it.
|
package/dist/adapters/react.js
CHANGED
|
@@ -2,20 +2,20 @@ import {
|
|
|
2
2
|
Autotracker,
|
|
3
3
|
TimeTravelOverlay,
|
|
4
4
|
withTracker
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-CEPDD5XN.js";
|
|
6
6
|
import "../chunk-PLYS4CVP.js";
|
|
7
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-VIDZLTP2.js";
|
|
8
8
|
import {
|
|
9
9
|
getReactor
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-T2CAL5F4.js";
|
|
11
11
|
import "../chunk-RI45W4O6.js";
|
|
12
12
|
import "../chunk-3OT72G7R.js";
|
|
13
13
|
import {
|
|
14
14
|
CTX,
|
|
15
15
|
NIL,
|
|
16
16
|
NOOP,
|
|
17
|
-
|
|
18
|
-
} from "../chunk-
|
|
17
|
+
getPath
|
|
18
|
+
} from "../chunk-4PLMBUCP.js";
|
|
19
19
|
|
|
20
20
|
// src/ts/adapters/react/hooks/useReactor.ts
|
|
21
21
|
import { useRef, useCallback, useSyncExternalStore, useMemo } from "react";
|
|
@@ -99,7 +99,7 @@ function usePath(target, path, options = NIL, build) {
|
|
|
99
99
|
const subscribe = useCallback3((notify) => rtr[optsRef.current.sync ? "watch" : "on"](path, () => (versionRef.current++, notify()), optsRef.current), [rtr, path]);
|
|
100
100
|
const getSnapshot = useCallback3(() => versionRef.current, []);
|
|
101
101
|
useSyncExternalStore3(subscribe, getSnapshot, getSnapshot);
|
|
102
|
-
return
|
|
102
|
+
return getPath(rtr.core, path);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
// src/ts/adapters/react/TimeTravelOverlay.tsx
|
|
@@ -64,9 +64,8 @@ function canHandle(obj, config = NIL, typecheck = true) {
|
|
|
64
64
|
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);
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
|
-
function
|
|
67
|
+
function getPath(source, key, separator = ".", keyFunc) {
|
|
68
68
|
if (key === "*") return source;
|
|
69
|
-
if (!key.includes(separator)) return source[keyFunc ? keyFunc(key) : key];
|
|
70
69
|
const keys2 = key.split(separator);
|
|
71
70
|
let currObj = source;
|
|
72
71
|
for (let i = 0, len = keys2.length; i < len; i++) {
|
|
@@ -82,9 +81,8 @@ function getAny(source, key, separator = ".", keyFunc) {
|
|
|
82
81
|
}
|
|
83
82
|
return currObj;
|
|
84
83
|
}
|
|
85
|
-
function
|
|
84
|
+
function setPath(target, key, value, separator = ".", keyFunc) {
|
|
86
85
|
if (key === "*") return Object.assign(target, value);
|
|
87
|
-
if (!key.includes(separator)) return void (target[keyFunc ? keyFunc(key) : key] = value);
|
|
88
86
|
const keys2 = key.split(separator);
|
|
89
87
|
for (let currObj = target, i = 0, len = keys2.length; i < len; i++) {
|
|
90
88
|
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
@@ -99,13 +97,12 @@ function setAny(target, key, value, separator = ".", keyFunc) {
|
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
|
-
function
|
|
100
|
+
function deletePath(target, key, separator = ".", keyFunc) {
|
|
103
101
|
if (key === "*") {
|
|
104
102
|
const keys3 = Object.keys(target);
|
|
105
103
|
for (let i = 0, len = keys3.length; i < len; i++) delete target[keys3[i]];
|
|
106
104
|
return;
|
|
107
105
|
}
|
|
108
|
-
if (!key.includes(separator)) return void delete target[keyFunc ? keyFunc(key) : key];
|
|
109
106
|
const keys2 = key.split(separator);
|
|
110
107
|
for (let currObj = target, i = 0, len = keys2.length; i < len; i++) {
|
|
111
108
|
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
@@ -121,9 +118,8 @@ function deleteAny(target, key, separator = ".", keyFunc) {
|
|
|
121
118
|
}
|
|
122
119
|
}
|
|
123
120
|
}
|
|
124
|
-
function
|
|
121
|
+
function hasPath(source, key, separator = ".", keyFunc) {
|
|
125
122
|
if (key === "*") return true;
|
|
126
|
-
if (!key.includes(separator)) return key in source;
|
|
127
123
|
const keys2 = key.split(separator);
|
|
128
124
|
for (let currObj = source, i = 0, len = keys2.length; i < len; i++) {
|
|
129
125
|
const key2 = keyFunc ? keyFunc(keys2[i]) : keys2[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
@@ -259,7 +255,7 @@ var ReactorEvent = class _ReactorEvent {
|
|
|
259
255
|
resolve(message) {
|
|
260
256
|
if (!this.rejectable) return this.reactor.log(`[ReactorEvent] Ignored \`resolve()\` call on a non-rejectable ${this.staticType} at "${this.path}"`);
|
|
261
257
|
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.`);
|
|
262
|
-
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._resolved = message ||
|
|
258
|
+
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._resolved = message || `${this.staticType} intent resolved at "${this.path}"`}`);
|
|
263
259
|
}
|
|
264
260
|
/** Rejection reason for rejectable events. */
|
|
265
261
|
get rejected() {
|
|
@@ -274,7 +270,7 @@ var ReactorEvent = class _ReactorEvent {
|
|
|
274
270
|
reject(reason) {
|
|
275
271
|
if (!this.rejectable) return this.reactor.log(`[ReactorEvent] Ignored \`reject()\` call on a non-rejectable ${this.staticType} at "${this.path}"`);
|
|
276
272
|
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.`);
|
|
277
|
-
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._rejected = reason ||
|
|
273
|
+
if (this.rejectable) this.reactor.log(`[ReactorEvent] ${this._rejected = reason || `${this.staticType} intent rejected at "${this.path}"`}`);
|
|
278
274
|
}
|
|
279
275
|
/**
|
|
280
276
|
* Returns event path values from target to root.
|
|
@@ -612,7 +608,7 @@ var Reactor = class {
|
|
|
612
608
|
return depth;
|
|
613
609
|
}
|
|
614
610
|
getContext(path) {
|
|
615
|
-
const last = path.lastIndexOf("."), value =
|
|
611
|
+
const last = path.lastIndexOf("."), value = getPath(this.core, path), object = last === -1 ? this.core : getPath(this.core, path.slice(0, last));
|
|
616
612
|
return { path, value, key: path.slice(last + 1) || "", hadKey: true, object };
|
|
617
613
|
}
|
|
618
614
|
bindSignal(cord, sig) {
|
|
@@ -677,7 +673,7 @@ var Reactor = class {
|
|
|
677
673
|
* const cleanup = rtr.get("user.name", (value) => String(value).trim());
|
|
678
674
|
*/
|
|
679
675
|
get(path, callback, options) {
|
|
680
|
-
return this.addSync("get", path, callback, options, (imm) => (imm !== "auto" ||
|
|
676
|
+
return this.addSync("get", path, callback, options, (imm) => (imm !== "auto" || hasPath(this.core, path)) && getPath(this.core, path));
|
|
681
677
|
}
|
|
682
678
|
/** Registers a get mediator for a path that only triggers once. */
|
|
683
679
|
gonce(path, callback, options) {
|
|
@@ -702,7 +698,7 @@ var Reactor = class {
|
|
|
702
698
|
* rtr.set("user.name", (value) => String(value).trim());
|
|
703
699
|
*/
|
|
704
700
|
set(path, callback, options) {
|
|
705
|
-
return this.addSync("set", path, callback, options, (imm) => (imm !== "auto" ||
|
|
701
|
+
return this.addSync("set", path, callback, options, (imm) => (imm !== "auto" || hasPath(this.core, path)) && setPath(this.core, path, getPath(this.core, path)));
|
|
706
702
|
}
|
|
707
703
|
/** Registers a set mediator for a path that only triggers once. */
|
|
708
704
|
sonce(path, callback, options) {
|
|
@@ -727,7 +723,7 @@ var Reactor = class {
|
|
|
727
723
|
* rtr.delete("cache.temp", () => TERMINATOR);
|
|
728
724
|
*/
|
|
729
725
|
delete(path, callback, options) {
|
|
730
|
-
return this.addSync("delete", path, callback, options, (imm) => (imm !== "auto" ||
|
|
726
|
+
return this.addSync("delete", path, callback, options, (imm) => (imm !== "auto" || hasPath(this.core, path)) && deletePath(this.core, path));
|
|
731
727
|
}
|
|
732
728
|
/** Registers a delete mediator for a path that only triggers once. */
|
|
733
729
|
donce(path, callback, options) {
|
|
@@ -753,7 +749,7 @@ var Reactor = class {
|
|
|
753
749
|
* const cleanup = rtr.watch("user.name", (value) => console.log(value));
|
|
754
750
|
*/
|
|
755
751
|
watch(path, callback, options) {
|
|
756
|
-
return this.addSync("watch", path, callback, options, (imm) => (imm !== "auto" ||
|
|
752
|
+
return this.addSync("watch", path, callback, options, (imm) => (imm !== "auto" || hasPath(this.core, path)) && (imm === "strict" ? setPath(this.core, path, getPath(this.core, path)) : ((target) => callback(target.value, { type: "init", target, currentTarget: target, root: this.core, rejectable: false }))(this.getContext(path))));
|
|
757
753
|
}
|
|
758
754
|
/** Registers a watcher for a path that only triggers once. */
|
|
759
755
|
wonce(path, callback, options) {
|
|
@@ -792,10 +788,12 @@ var Reactor = class {
|
|
|
792
788
|
}
|
|
793
789
|
if (cord) return cord.clup;
|
|
794
790
|
cord = { cb: callback, capture, depth, once, clup: () => this.off(path, callback, options), lDepth: depth !== void 0 ? this.getDepth(path) : depth };
|
|
795
|
-
if (immediate && (immediate !== "auto" ||
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
791
|
+
if (immediate && (immediate !== "auto" || hasPath(this.core, path)))
|
|
792
|
+
if (immediate === "strict") setPath(this.core, path, getPath(this.core, path));
|
|
793
|
+
else {
|
|
794
|
+
const target = this.getContext(path);
|
|
795
|
+
callback(new ReactorEvent({ type: "init", target, currentTarget: target, root: this.core, rejectable: false }, this));
|
|
796
|
+
}
|
|
799
797
|
(cords ?? (this.listeners.set(path, cords = []), cords)).push(cord);
|
|
800
798
|
return this.bindSignal(cord, signal);
|
|
801
799
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { E as EffectOptions } from '../index-
|
|
2
|
-
export { A as Autotracker, w as withTracker } from '../index-
|
|
3
|
-
export { T as TimeTravelOverlay, a as TimeTravelOverlayConfig } from '../TimeTravelOverlay-
|
|
4
|
-
import '../timeTravel-
|
|
1
|
+
import { E as EffectOptions } from '../index-0TjDsae1.cjs';
|
|
2
|
+
export { A as Autotracker, w as withTracker } from '../index-0TjDsae1.cjs';
|
|
3
|
+
export { T as TimeTravelOverlay, a as TimeTravelOverlayConfig } from '../TimeTravelOverlay-DTqM5uJB.cjs';
|
|
4
|
+
import '../timeTravel-wU23uudD.cjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Runs a reactive side effect in vanilla JavaScript.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { E as EffectOptions } from '../index-
|
|
2
|
-
export { A as Autotracker, w as withTracker } from '../index-
|
|
3
|
-
export { T as TimeTravelOverlay, a as TimeTravelOverlayConfig } from '../TimeTravelOverlay-
|
|
4
|
-
import '../timeTravel-
|
|
1
|
+
import { E as EffectOptions } from '../index-0TjDsae1.js';
|
|
2
|
+
export { A as Autotracker, w as withTracker } from '../index-0TjDsae1.js';
|
|
3
|
+
export { T as TimeTravelOverlay, a as TimeTravelOverlayConfig } from '../TimeTravelOverlay-cSlHzoKB.js';
|
|
4
|
+
import '../timeTravel-CX100S8f.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Runs a reactive side effect in vanilla JavaScript.
|
package/dist/adapters/vanilla.js
CHANGED
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
TimeTravelOverlay,
|
|
4
4
|
effect,
|
|
5
5
|
withTracker
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-CEPDD5XN.js";
|
|
7
7
|
import "../chunk-PLYS4CVP.js";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-VIDZLTP2.js";
|
|
9
|
+
import "../chunk-T2CAL5F4.js";
|
|
10
10
|
import "../chunk-RI45W4O6.js";
|
|
11
11
|
import "../chunk-3OT72G7R.js";
|
|
12
|
-
import "../chunk-
|
|
12
|
+
import "../chunk-4PLMBUCP.js";
|
|
13
13
|
export {
|
|
14
14
|
Autotracker,
|
|
15
15
|
TimeTravelOverlay,
|
|
@@ -35,9 +35,8 @@ function canHandle(obj, config = NIL, typecheck = true) {
|
|
|
35
35
|
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);
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function getPath(source, key, separator = ".", keyFunc) {
|
|
39
39
|
if (key === "*") return source;
|
|
40
|
-
if (!key.includes(separator)) return source[keyFunc ? keyFunc(key) : key];
|
|
41
40
|
const keys = key.split(separator);
|
|
42
41
|
let currObj = source;
|
|
43
42
|
for (let i = 0, len = keys.length; i < len; i++) {
|
|
@@ -53,9 +52,8 @@ function getAny(source, key, separator = ".", keyFunc) {
|
|
|
53
52
|
}
|
|
54
53
|
return currObj;
|
|
55
54
|
}
|
|
56
|
-
function
|
|
55
|
+
function setPath(target, key, value, separator = ".", keyFunc) {
|
|
57
56
|
if (key === "*") return Object.assign(target, value);
|
|
58
|
-
if (!key.includes(separator)) return void (target[keyFunc ? keyFunc(key) : key] = value);
|
|
59
57
|
const keys = key.split(separator);
|
|
60
58
|
for (let currObj = target, i = 0, len = keys.length; i < len; i++) {
|
|
61
59
|
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
@@ -70,13 +68,12 @@ function setAny(target, key, value, separator = ".", keyFunc) {
|
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
|
-
function
|
|
71
|
+
function deletePath(target, key, separator = ".", keyFunc) {
|
|
74
72
|
if (key === "*") {
|
|
75
73
|
const keys2 = Object.keys(target);
|
|
76
74
|
for (let i = 0, len = keys2.length; i < len; i++) delete target[keys2[i]];
|
|
77
75
|
return;
|
|
78
76
|
}
|
|
79
|
-
if (!key.includes(separator)) return void delete target[keyFunc ? keyFunc(key) : key];
|
|
80
77
|
const keys = key.split(separator);
|
|
81
78
|
for (let currObj = target, i = 0, len = keys.length; i < len; i++) {
|
|
82
79
|
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
@@ -92,9 +89,8 @@ function deleteAny(target, key, separator = ".", keyFunc) {
|
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
|
-
function
|
|
92
|
+
function hasPath(source, key, separator = ".", keyFunc) {
|
|
96
93
|
if (key === "*") return true;
|
|
97
|
-
if (!key.includes(separator)) return key in source;
|
|
98
94
|
const keys = key.split(separator);
|
|
99
95
|
for (let currObj = source, i = 0, len = keys.length; i < len; i++) {
|
|
100
96
|
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
@@ -111,13 +107,13 @@ function inAny(source, key, separator = ".", keyFunc) {
|
|
|
111
107
|
}
|
|
112
108
|
return true;
|
|
113
109
|
}
|
|
114
|
-
function
|
|
110
|
+
function parsePathObj(obj, separator = ".", keyFunc = (p) => p, seen = /* @__PURE__ */ new WeakSet()) {
|
|
115
111
|
if (!isObj(obj) || seen.has(obj)) return obj;
|
|
116
112
|
seen.add(obj);
|
|
117
113
|
const result = {}, keys = Object.keys(obj);
|
|
118
114
|
for (let i = 0, len = keys.length; i < len; i++) {
|
|
119
115
|
const key = keys[i], val = obj[key];
|
|
120
|
-
key === "*" || key.includes(separator) ?
|
|
116
|
+
key === "*" || key.includes(separator) ? setPath(result, key, parsePathObj(val, separator, keyFunc, seen), separator, keyFunc) : result[key] = isObj(val) ? parsePathObj(val, separator, keyFunc, seen) : val;
|
|
121
117
|
}
|
|
122
118
|
return result;
|
|
123
119
|
}
|
|
@@ -125,7 +121,7 @@ function parseEvtOpts(options, opts, boolOpt = opts[0], result = {}) {
|
|
|
125
121
|
return Object.assign(result, "boolean" === typeof options ? { [boolOpt]: options } : options), result;
|
|
126
122
|
}
|
|
127
123
|
function fanout(a, b, c, d) {
|
|
128
|
-
const isEvPd = !!a?.target, isPath = !isEvPd && "string" === typeof b, [state, path, olds, news, opts, type] = isEvPd ? [a.root, a.currentTarget.path, a.currentTarget.oldValue, a.currentTarget.value, b || NIL, a.type] : isPath ? [a, b,
|
|
124
|
+
const isEvPd = !!a?.target, isPath = !isEvPd && "string" === typeof b, [state, path, olds, news, opts, type] = isEvPd ? [a.root, a.currentTarget.path, a.currentTarget.oldValue, a.currentTarget.value, b || NIL, a.type] : isPath ? [a, b, getPath(a, b), c, d || NIL, void 0] : [void 0, void 0, a, b, c || NIL, void 0], target = isEvPd ? getPath(a.root, a.currentTarget.path) : isPath ? getPath(state, path) : olds;
|
|
129
125
|
if (isEvPd && type !== "set" && type !== "delete" || !target || !canHandle(news, opts)) return;
|
|
130
126
|
const prev = CTX.isCascading;
|
|
131
127
|
CTX.isCascading = isEvPd;
|
|
@@ -141,7 +137,7 @@ function fanout(a, b, c, d) {
|
|
|
141
137
|
}
|
|
142
138
|
}
|
|
143
139
|
};
|
|
144
|
-
if ((opts.atomic ?? true) && Array.isArray(news) && isPath)
|
|
140
|
+
if ((opts.atomic ?? true) && Array.isArray(news) && isPath) setPath(state, path, news), getPath(state, path).length = news.length;
|
|
145
141
|
else walk(target, opts.merge ? mergeObjs(olds, news, opts) : news, opts.depth === true ? Infinity : opts.depth);
|
|
146
142
|
} finally {
|
|
147
143
|
CTX.isCascading = prev;
|
|
@@ -216,11 +212,11 @@ export {
|
|
|
216
212
|
isObj,
|
|
217
213
|
isPOJO,
|
|
218
214
|
canHandle,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
215
|
+
getPath,
|
|
216
|
+
setPath,
|
|
217
|
+
deletePath,
|
|
218
|
+
hasPath,
|
|
219
|
+
parsePathObj,
|
|
224
220
|
parseEvtOpts,
|
|
225
221
|
fanout,
|
|
226
222
|
fanoutOptsArr,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
wpArr
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VIDZLTP2.js";
|
|
4
4
|
import {
|
|
5
5
|
reactive
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-T2CAL5F4.js";
|
|
7
7
|
import {
|
|
8
8
|
createEl,
|
|
9
9
|
formatKeyForDisplay,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
RAW,
|
|
17
17
|
canHandle,
|
|
18
18
|
nuke
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-4PLMBUCP.js";
|
|
20
20
|
|
|
21
21
|
// src/ts/adapters/autotracker.ts
|
|
22
22
|
var Autotracker = class {
|