@vielzeug/stateit 2.0.0 → 3.0.1
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 +60 -290
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -9
- package/dist/stateit.cjs +1 -1
- package/dist/stateit.cjs.map +1 -1
- package/dist/stateit.d.ts +68 -0
- package/dist/stateit.d.ts.map +1 -0
- package/dist/stateit.js +294 -228
- package/dist/stateit.js.map +1 -1
- package/package.json +6 -5
- package/dist/batch.cjs +0 -2
- package/dist/batch.cjs.map +0 -1
- package/dist/batch.d.ts +0 -5
- package/dist/batch.d.ts.map +0 -1
- package/dist/batch.js +0 -28
- package/dist/batch.js.map +0 -1
- package/dist/computed.cjs +0 -2
- package/dist/computed.cjs.map +0 -1
- package/dist/computed.d.ts +0 -58
- package/dist/computed.d.ts.map +0 -1
- package/dist/computed.js +0 -65
- package/dist/computed.js.map +0 -1
- package/dist/effect.cjs +0 -2
- package/dist/effect.cjs.map +0 -1
- package/dist/effect.d.ts +0 -31
- package/dist/effect.d.ts.map +0 -1
- package/dist/effect.js +0 -53
- package/dist/effect.js.map +0 -1
- package/dist/runtime.cjs +0 -2
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.d.ts +0 -40
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -47
- package/dist/runtime.js.map +0 -1
- package/dist/signal.cjs +0 -2
- package/dist/signal.cjs.map +0 -1
- package/dist/signal.d.ts +0 -26
- package/dist/signal.d.ts.map +0 -1
- package/dist/signal.js +0 -40
- package/dist/signal.js.map +0 -1
- package/dist/store.cjs +0 -2
- package/dist/store.cjs.map +0 -1
- package/dist/store.d.ts +0 -32
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js +0 -51
- package/dist/store.js.map +0 -1
- package/dist/types.cjs +0 -2
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.ts +0 -39
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/watch.cjs +0 -2
- package/dist/watch.cjs.map +0 -1
- package/dist/watch.d.ts +0 -36
- package/dist/watch.d.ts.map +0 -1
- package/dist/watch.js +0 -32
- package/dist/watch.js.map +0 -1
package/dist/stateit.js
CHANGED
|
@@ -1,270 +1,336 @@
|
|
|
1
|
-
//#region src/
|
|
2
|
-
var e = Symbol("stateit.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}, a = () => {
|
|
12
|
-
n.depth = 0, t.deps = null, t.effect = null, t.cleanups = null, n.pending.clear();
|
|
13
|
-
}, o = class {
|
|
14
|
-
#e = /* @__PURE__ */ new Set();
|
|
15
|
-
_track() {
|
|
16
|
-
if (t.deps !== null && t.effect !== null) {
|
|
17
|
-
let e = t.effect;
|
|
18
|
-
this.#e.add(e), t.deps.add(() => this.#e.delete(e));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
_notify() {
|
|
22
|
-
if (this.#e.size === 0) return;
|
|
23
|
-
if (n.depth > 0) {
|
|
24
|
-
for (let e of this.#e) n.pending.add(e);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
let e = [];
|
|
28
|
-
for (let t of [...this.#e]) try {
|
|
29
|
-
t();
|
|
30
|
-
} catch (t) {
|
|
31
|
-
e.push(t);
|
|
32
|
-
}
|
|
33
|
-
if (e.length) throw e.length === 1 ? e[0] : AggregateError(e, "[stateit] multiple subscriber errors");
|
|
34
|
-
}
|
|
35
|
-
}, s = (e, n, r, i) => {
|
|
36
|
-
let a = t.effect, o = t.deps, s = t.cleanups;
|
|
37
|
-
t.effect = e, t.deps = n, t.cleanups = r;
|
|
38
|
-
try {
|
|
39
|
-
return i();
|
|
40
|
-
} finally {
|
|
41
|
-
t.effect = a, t.deps = o, t.cleanups = s;
|
|
42
|
-
}
|
|
43
|
-
}, c = () => {
|
|
44
|
-
let e = [...n.pending];
|
|
45
|
-
n.pending.clear();
|
|
46
|
-
let t = [];
|
|
47
|
-
for (let n of e) try {
|
|
48
|
-
n();
|
|
1
|
+
//#region src/stateit.ts
|
|
2
|
+
var e = 100, t = Symbol("stateit.is-signal"), n = Symbol.observable ?? Symbol.for("observable"), r = n, i = (e) => Object.assign(e, {
|
|
3
|
+
dispose: e,
|
|
4
|
+
[Symbol.dispose]: e
|
|
5
|
+
}), a = /* @__PURE__ */ new WeakMap(), o = (e) => e instanceof Error ? e : Error(String(e)), s = (e, t) => {
|
|
6
|
+
if (typeof e != "object" || !e || Array.isArray(e)) throw TypeError(t);
|
|
7
|
+
}, c = (e, t) => {
|
|
8
|
+
let n = [];
|
|
9
|
+
for (let t of e) try {
|
|
10
|
+
t();
|
|
49
11
|
} catch (e) {
|
|
50
|
-
|
|
12
|
+
n.push(e);
|
|
51
13
|
}
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
14
|
+
if (n.length === 1) throw n[0];
|
|
15
|
+
if (n.length > 1) throw AggregateError(n, `[stateit] ${t}`);
|
|
16
|
+
}, l = (e, t, n) => {
|
|
17
|
+
let r = o(e);
|
|
18
|
+
throw t.length === 0 ? r : AggregateError([r, ...t.map(o)], `[stateit] ${n}`, { cause: r });
|
|
19
|
+
}, u = (e) => {
|
|
55
20
|
try {
|
|
56
|
-
|
|
57
|
-
return --n.depth === 0 && c(), t;
|
|
21
|
+
return c(e, "cleanup errors"), [];
|
|
58
22
|
} catch (e) {
|
|
59
|
-
|
|
60
|
-
c();
|
|
61
|
-
} catch {}
|
|
62
|
-
throw e;
|
|
23
|
+
return e instanceof AggregateError ? e.errors : [e];
|
|
63
24
|
}
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
#a = /* @__PURE__ */ new Set();
|
|
72
|
-
#o = () => {
|
|
73
|
-
this.#n || (this.#n = !0, this._notify());
|
|
74
|
-
};
|
|
75
|
-
constructor(e, t) {
|
|
76
|
-
super(), this.#e = e, this.#i = t?.equals ?? Object.is, t?.lazy || this.#s();
|
|
25
|
+
}, d = null, f = null, p = null, m = null, h = (e, t, n, r, i) => {
|
|
26
|
+
let a = d, o = f, s = p, c = m;
|
|
27
|
+
d = e, f = t, p = n, m = r;
|
|
28
|
+
try {
|
|
29
|
+
return i();
|
|
30
|
+
} finally {
|
|
31
|
+
d = a, f = o, p = s, m = c;
|
|
77
32
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
33
|
+
}, g = 0, _ = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ new Set(), y = (e) => {
|
|
34
|
+
let t = new Set(e), n = /* @__PURE__ */ new Map();
|
|
35
|
+
for (let t of e) n.set(t, 0);
|
|
36
|
+
for (let r of e) for (let e of r.computedSubscribers()) t.has(e) && n.set(e, (n.get(e) ?? 0) + 1);
|
|
37
|
+
let r = [];
|
|
38
|
+
for (let t of e) (n.get(t) ?? 0) === 0 && r.push(t);
|
|
39
|
+
let i = [];
|
|
40
|
+
for (; r.length > 0;) {
|
|
41
|
+
let e = r.shift();
|
|
42
|
+
i.push(e);
|
|
43
|
+
for (let i of e.computedSubscribers()) {
|
|
44
|
+
if (!t.has(i)) continue;
|
|
45
|
+
let e = (n.get(i) ?? 0) - 1;
|
|
46
|
+
n.set(i, e), e === 0 && r.push(i);
|
|
47
|
+
}
|
|
83
48
|
}
|
|
84
|
-
|
|
85
|
-
|
|
49
|
+
if (i.length < e.length) for (let t of e) i.includes(t) || i.push(t);
|
|
50
|
+
return i;
|
|
51
|
+
}, b = (e) => {
|
|
52
|
+
let t = [...e.computedSubscribers()], n = /* @__PURE__ */ new Set();
|
|
53
|
+
for (let t of e.subscribers()) _.add(t);
|
|
54
|
+
for (; t.length > 0;) {
|
|
55
|
+
let e = t.pop();
|
|
56
|
+
if (!n.has(e) && (n.add(e), e.markDirty())) {
|
|
57
|
+
v.add(e);
|
|
58
|
+
for (let n of e.computedSubscribers()) t.push(n);
|
|
59
|
+
}
|
|
86
60
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
61
|
+
}, x = () => {
|
|
62
|
+
for (; v.size > 0;) {
|
|
63
|
+
let e = y([...v]);
|
|
64
|
+
v.clear();
|
|
65
|
+
for (let t of e) if (t.hasAnySubscribers() && t.refreshIfDirty()) {
|
|
66
|
+
for (let e of t.subscribers()) _.add(e);
|
|
67
|
+
for (let e of t.computedSubscribers()) e.markDirty() && v.add(e);
|
|
91
68
|
}
|
|
92
|
-
return this.#t;
|
|
93
69
|
}
|
|
94
|
-
|
|
95
|
-
|
|
70
|
+
}, S = () => {
|
|
71
|
+
let t = 0;
|
|
72
|
+
for (; _.size > 0 || v.size > 0;) {
|
|
73
|
+
if (++t > e) throw Error(`[stateit] infinite flush loop (> ${e} iterations)`);
|
|
74
|
+
if (v.size > 0 && x(), _.size === 0) continue;
|
|
75
|
+
let n = [..._];
|
|
76
|
+
_.clear(), c(n, "subscriber errors");
|
|
96
77
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
78
|
+
}, C = (e) => {
|
|
79
|
+
e.hasAnySubscribers() && (b(e), g === 0 && S());
|
|
80
|
+
}, w = class {
|
|
81
|
+
computedSubs_ = /* @__PURE__ */ new Set();
|
|
82
|
+
subscribers_ = /* @__PURE__ */ new Set();
|
|
83
|
+
track() {
|
|
84
|
+
if (p) {
|
|
85
|
+
if (f !== null) {
|
|
86
|
+
let e = f;
|
|
87
|
+
this.computedSubs_.add(e), p.add(() => this.computedSubs_.delete(e));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (d !== null) {
|
|
91
|
+
let e = d;
|
|
92
|
+
this.subscribers_.add(e), p.add(() => this.subscribers_.delete(e));
|
|
93
|
+
}
|
|
102
94
|
}
|
|
103
95
|
}
|
|
104
|
-
|
|
105
|
-
this
|
|
96
|
+
notify() {
|
|
97
|
+
C(this);
|
|
106
98
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
constructor(e, t, n) {
|
|
110
|
-
super(e, n), this.#e = t;
|
|
99
|
+
hasAnySubscribers() {
|
|
100
|
+
return this.computedSubs_.size > 0 || this.subscribers_.size > 0;
|
|
111
101
|
}
|
|
112
|
-
|
|
113
|
-
return
|
|
102
|
+
computedSubscribers() {
|
|
103
|
+
return this.computedSubs_;
|
|
114
104
|
}
|
|
115
|
-
|
|
116
|
-
this
|
|
105
|
+
subscribers() {
|
|
106
|
+
return this.subscribers_;
|
|
117
107
|
}
|
|
118
|
-
|
|
119
|
-
this
|
|
108
|
+
subscribe(e) {
|
|
109
|
+
return this.subscribers_.add(e), i(() => {
|
|
110
|
+
this.subscribers_.delete(e);
|
|
111
|
+
});
|
|
120
112
|
}
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
i.clear();
|
|
126
|
-
}, d = () => {
|
|
127
|
-
o = !1, u();
|
|
128
|
-
let r = [], a, l = !1;
|
|
129
|
-
try {
|
|
130
|
-
s(f, i, r, () => {
|
|
131
|
-
let t = e();
|
|
132
|
-
typeof t == "function" && r.push(t);
|
|
133
|
-
});
|
|
134
|
-
} catch (e) {
|
|
135
|
-
if (t?.onError) l = !0, a = e;
|
|
136
|
-
else throw e;
|
|
137
|
-
}
|
|
138
|
-
return n = r.length > 0 ? () => {
|
|
139
|
-
for (let e of r) e();
|
|
140
|
-
} : void 0, l && (u(), t.onError(a), c = !0), l;
|
|
141
|
-
}, f = () => {
|
|
142
|
-
if (c || a) {
|
|
143
|
-
a && (o = !0);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
a = !0;
|
|
147
|
-
try {
|
|
148
|
-
let e = 0;
|
|
149
|
-
do {
|
|
150
|
-
if (++e > l) throw Error(`[stateit] effect: possible infinite reactive loop (> ${l} iterations)`);
|
|
151
|
-
if (d()) break;
|
|
152
|
-
} while (o);
|
|
153
|
-
} finally {
|
|
154
|
-
a = !1;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
f();
|
|
158
|
-
let p = () => {
|
|
159
|
-
c || (c = !0, u());
|
|
160
|
-
};
|
|
161
|
-
return Object.assign(p, {
|
|
162
|
-
dispose: p,
|
|
163
|
-
[Symbol.dispose]: p
|
|
164
|
-
});
|
|
165
|
-
}, v = (e) => s(null, null, null, e), y = (e) => {
|
|
166
|
-
t.cleanups?.push(e);
|
|
167
|
-
}, b = class extends o {
|
|
168
|
-
[u] = !0;
|
|
169
|
-
#e;
|
|
170
|
-
#t;
|
|
113
|
+
}, T = class extends w {
|
|
114
|
+
value_;
|
|
115
|
+
equals_;
|
|
116
|
+
[t] = !0;
|
|
171
117
|
constructor(e, t) {
|
|
172
|
-
super(), this
|
|
118
|
+
super(), this.value_ = e, this.equals_ = t ?? Object.is;
|
|
173
119
|
}
|
|
174
120
|
get value() {
|
|
175
|
-
return this.
|
|
121
|
+
return this.track(), this.value_;
|
|
176
122
|
}
|
|
177
|
-
|
|
178
|
-
|
|
123
|
+
peek() {
|
|
124
|
+
return this.value_;
|
|
179
125
|
}
|
|
126
|
+
subscribe = (e) => super.subscribe(e);
|
|
180
127
|
update(e) {
|
|
181
|
-
this.value = e(this
|
|
128
|
+
this.value = e(this.value_);
|
|
182
129
|
}
|
|
183
|
-
|
|
184
|
-
|
|
130
|
+
set value(e) {
|
|
131
|
+
this.equals_(this.value_, e) || (this.value_ = e, this.notify());
|
|
185
132
|
}
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
return S.set(e, n), n;
|
|
199
|
-
}, w = (e) => typeof e == "object" && !!e && u in e, T = (e) => w(e) ? e.value : e, E = (e) => w(e) ? e.peek() : e, D = (e, t) => {
|
|
200
|
-
if (e === t) return !0;
|
|
201
|
-
if (e == null || t == null) return e === t;
|
|
202
|
-
if (typeof e != "object" || typeof t != "object") return !1;
|
|
203
|
-
let n = Object.keys(e), r = Object.keys(t);
|
|
204
|
-
if (n.length !== r.length) return !1;
|
|
205
|
-
for (let r of n) if (!Object.is(e[r], t[r])) return !1;
|
|
206
|
-
return !0;
|
|
207
|
-
}, O = class extends b {
|
|
208
|
-
[d] = !0;
|
|
209
|
-
#e;
|
|
210
|
-
#t = !1;
|
|
133
|
+
}, E = class extends w {
|
|
134
|
+
hasValue_ = !1;
|
|
135
|
+
value_;
|
|
136
|
+
dirty_ = !0;
|
|
137
|
+
computing_ = !1;
|
|
138
|
+
disposed_ = !1;
|
|
139
|
+
deps_ = /* @__PURE__ */ new Set();
|
|
140
|
+
compute_;
|
|
141
|
+
equals_;
|
|
142
|
+
[t] = !0;
|
|
211
143
|
constructor(e, t) {
|
|
212
|
-
super(
|
|
213
|
-
}
|
|
214
|
-
get frozen() {
|
|
215
|
-
return this.#t;
|
|
144
|
+
super(), this.compute_ = e, this.equals_ = t ?? Object.is;
|
|
216
145
|
}
|
|
217
|
-
|
|
218
|
-
return
|
|
146
|
+
markDirty() {
|
|
147
|
+
return this.disposed_ || this.dirty_ ? !1 : (this.dirty_ = !0, !0);
|
|
219
148
|
}
|
|
220
|
-
|
|
221
|
-
this
|
|
149
|
+
refreshIfDirty() {
|
|
150
|
+
return this.dirty_ ? this.recompute() : !1;
|
|
222
151
|
}
|
|
223
|
-
|
|
224
|
-
this.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
152
|
+
recompute() {
|
|
153
|
+
if (this.computing_) throw Error("[stateit] computed cycle detected");
|
|
154
|
+
for (let e of this.deps_) e();
|
|
155
|
+
this.deps_.clear(), this.computing_ = !0;
|
|
156
|
+
try {
|
|
157
|
+
let e = h(null, this, this.deps_, null, this.compute_);
|
|
158
|
+
return this.dirty_ = !1, !this.hasValue_ || !this.equals_(this.value_, e) ? (this.hasValue_ = !0, this.value_ = e, !0) : !1;
|
|
159
|
+
} catch (e) {
|
|
160
|
+
let t = u(this.deps_);
|
|
161
|
+
return this.deps_.clear(), l(e, t, "computed failed dependency cleanup errors");
|
|
162
|
+
} finally {
|
|
163
|
+
this.computing_ = !1;
|
|
164
|
+
}
|
|
228
165
|
}
|
|
229
|
-
|
|
230
|
-
this.
|
|
166
|
+
get value() {
|
|
167
|
+
if (this.disposed_) throw Error("[stateit] Cannot read disposed computed signal");
|
|
168
|
+
return this.refreshIfDirty(), this.track(), this.value_;
|
|
231
169
|
}
|
|
232
|
-
|
|
233
|
-
this.
|
|
170
|
+
peek() {
|
|
171
|
+
if (this.disposed_) throw Error("[stateit] Cannot read disposed computed signal");
|
|
172
|
+
return this.refreshIfDirty(), this.value_;
|
|
234
173
|
}
|
|
235
|
-
|
|
236
|
-
|
|
174
|
+
subscribe = (e) => {
|
|
175
|
+
if (this.disposed_) throw Error("[stateit] Cannot subscribe to a disposed computed signal");
|
|
176
|
+
return this.refreshIfDirty(), super.subscribe(e);
|
|
177
|
+
};
|
|
178
|
+
dispose() {
|
|
179
|
+
if (!this.disposed_) {
|
|
180
|
+
this.disposed_ = !0;
|
|
181
|
+
for (let e of this.deps_) e();
|
|
182
|
+
this.deps_.clear();
|
|
183
|
+
}
|
|
237
184
|
}
|
|
238
|
-
|
|
239
|
-
this
|
|
185
|
+
[Symbol.dispose]() {
|
|
186
|
+
this.dispose();
|
|
240
187
|
}
|
|
241
|
-
},
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (!r(i, o)) {
|
|
248
|
-
let e = i;
|
|
249
|
-
i = o, t(o, e), n?.once && a();
|
|
250
|
-
}
|
|
251
|
-
}), a;
|
|
252
|
-
}, M = (e, t, n) => new Promise((r, i) => {
|
|
253
|
-
let a = n?.signal;
|
|
188
|
+
}, D = (e, t) => new T(e, t?.equals), O = (e, t) => {
|
|
189
|
+
let n = new E(e, t?.equals);
|
|
190
|
+
return m !== null && F(() => n.dispose()), n;
|
|
191
|
+
}, k = (e) => {
|
|
192
|
+
g++;
|
|
193
|
+
let t, n;
|
|
254
194
|
try {
|
|
255
|
-
|
|
195
|
+
t = e();
|
|
196
|
+
} catch (e) {
|
|
197
|
+
n = e;
|
|
198
|
+
}
|
|
199
|
+
if (g--, g === 0) try {
|
|
200
|
+
S();
|
|
256
201
|
} catch (e) {
|
|
257
|
-
|
|
258
|
-
return;
|
|
202
|
+
throw n === void 0 ? o(e) : AggregateError([n, e], "[stateit] batch error with flush errors", { cause: e });
|
|
259
203
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
204
|
+
if (n !== void 0) throw o(n);
|
|
205
|
+
return t;
|
|
206
|
+
}, A = (t) => {
|
|
207
|
+
let n, r = /* @__PURE__ */ new Set(), a = !1, o = !1, s = !1, d = () => {
|
|
208
|
+
if (!n && r.size === 0) return;
|
|
209
|
+
let e = n ? [n, ...r] : [...r];
|
|
210
|
+
n = void 0, r.clear(), c(e, "effect teardown errors");
|
|
211
|
+
}, f = () => {
|
|
212
|
+
if (!s) {
|
|
213
|
+
if (a) {
|
|
214
|
+
o = !0;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
a = !0;
|
|
218
|
+
try {
|
|
219
|
+
let i = 0;
|
|
220
|
+
do {
|
|
221
|
+
if (++i > e) throw Error(`[stateit] infinite effect loop (> ${e} iterations)`);
|
|
222
|
+
o = !1, d();
|
|
223
|
+
let a = [], s;
|
|
224
|
+
try {
|
|
225
|
+
s = h(f, null, r, a, t);
|
|
226
|
+
} catch (e) {
|
|
227
|
+
let t = [...u(r), ...u(a)];
|
|
228
|
+
r.clear(), l(e, t, "effect failure with cleanup errors");
|
|
229
|
+
}
|
|
230
|
+
typeof s == "function" && a.push(s), n = a.length > 0 ? () => {
|
|
231
|
+
c(a, "effect cleanup errors");
|
|
232
|
+
} : void 0;
|
|
233
|
+
} while (o && !s);
|
|
234
|
+
} finally {
|
|
235
|
+
a = !1;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return f(), i(() => {
|
|
240
|
+
s || (s = !0, d());
|
|
241
|
+
});
|
|
242
|
+
}, j = (e) => h(null, null, null, null, e), M = (e) => {
|
|
243
|
+
let t = e, n = a.get(t);
|
|
244
|
+
if (n) return n;
|
|
245
|
+
let r = {
|
|
246
|
+
peek() {
|
|
247
|
+
return e.peek();
|
|
248
|
+
},
|
|
249
|
+
subscribe(t) {
|
|
250
|
+
return e.subscribe(t);
|
|
251
|
+
},
|
|
252
|
+
get value() {
|
|
253
|
+
return e.value;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
return a.set(t, r), r;
|
|
257
|
+
}, N = (e) => ({ subscribe(t) {
|
|
258
|
+
return t(e.value), e.subscribe(() => t(e.value));
|
|
259
|
+
} }), P = (e) => {
|
|
260
|
+
let t = (t) => {
|
|
261
|
+
let n = typeof t == "function" ? { next: t } : t;
|
|
262
|
+
n.next?.(e.value);
|
|
263
|
+
let r = e.subscribe(() => n.next?.(e.value));
|
|
264
|
+
return { unsubscribe() {
|
|
265
|
+
r();
|
|
266
|
+
} };
|
|
267
|
+
}, r = {
|
|
268
|
+
[n]() {
|
|
269
|
+
return r;
|
|
270
|
+
},
|
|
271
|
+
subscribe: t
|
|
272
|
+
};
|
|
273
|
+
return r;
|
|
274
|
+
}, F = (e) => {
|
|
275
|
+
if (m === null) throw Error("[stateit] onCleanup() must be called from within an active effect or scope.");
|
|
276
|
+
m.push(e);
|
|
277
|
+
}, I = (e) => {
|
|
278
|
+
let t = [], n = !1, r = (e) => {
|
|
279
|
+
if (n) throw Error("[stateit] Cannot run inside a disposed scope.");
|
|
280
|
+
return h(null, null, null, t, e);
|
|
281
|
+
}, i = () => {
|
|
282
|
+
n || (n = !0, c([...t].reverse(), "scope cleanup errors"), t.length = 0);
|
|
283
|
+
}, a = {
|
|
284
|
+
dispose: i,
|
|
285
|
+
run: r,
|
|
286
|
+
[Symbol.dispose]: i
|
|
287
|
+
};
|
|
288
|
+
return e && r(e), a;
|
|
289
|
+
};
|
|
290
|
+
function L(e, t, n) {
|
|
291
|
+
let r = typeof e == "function" ? e : () => e.value, i = n?.equals ?? Object.is, a = !1, o;
|
|
292
|
+
return n?.immediate && (o = j(r), a = !0, t(o, o)), A(() => {
|
|
293
|
+
let e = r();
|
|
294
|
+
if (!a) {
|
|
295
|
+
a = !0, o = e;
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (i(o, e)) return;
|
|
299
|
+
let n = o;
|
|
300
|
+
o = e, t(e, n);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
var R = (e) => {
|
|
304
|
+
s(e, "[stateit] store() requires a plain object initial state.");
|
|
305
|
+
let n = structuredClone(e), r = D(structuredClone(e));
|
|
306
|
+
return {
|
|
307
|
+
[t]: !0,
|
|
308
|
+
patch(e) {
|
|
309
|
+
s(e, "[stateit] store.patch() requires a plain object partial.");
|
|
310
|
+
let t = j(() => r.value);
|
|
311
|
+
Object.keys(e).some((n) => !Object.is(t[n], e[n])) && (r.value = {
|
|
312
|
+
...t,
|
|
313
|
+
...e
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
peek() {
|
|
317
|
+
return r.peek();
|
|
318
|
+
},
|
|
319
|
+
reset() {
|
|
320
|
+
r.value = structuredClone(n);
|
|
321
|
+
},
|
|
322
|
+
subscribe(e) {
|
|
323
|
+
return r.subscribe(e);
|
|
324
|
+
},
|
|
325
|
+
update(e) {
|
|
326
|
+
r.update(e);
|
|
327
|
+
},
|
|
328
|
+
get value() {
|
|
329
|
+
return r.value;
|
|
330
|
+
}
|
|
264
331
|
};
|
|
265
|
-
|
|
266
|
-
});
|
|
332
|
+
}, z = (e) => typeof e == "object" && !!e && !!e[t];
|
|
267
333
|
//#endregion
|
|
268
|
-
export {
|
|
334
|
+
export { k as batch, O as computed, A as effect, z as isSignal, r as observableSymbol, F as onCleanup, M as readonly, I as scope, D as signal, R as store, P as toObservable, N as toStore, i as toSubscription, j as untrack, L as watch };
|
|
269
335
|
|
|
270
336
|
//# sourceMappingURL=stateit.js.map
|