opshot 0.5.2 → 0.6.0
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 +83 -24
- package/dist/chunk-4JZIOHSP.js +768 -0
- package/dist/createMutableState-DJ9dmpR-.d.ts +36 -0
- package/dist/index.d.ts +52 -76
- package/dist/index.js +7 -1254
- package/dist/react.d.ts +23 -0
- package/dist/react.js +517 -0
- package/package.json +10 -1
package/dist/index.js
CHANGED
|
@@ -1,694 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// src/utils/constructorName.ts
|
|
5
|
-
var constructorName = (candidate) => typeof candidate === "function" && candidate.name !== "" ? candidate.name : "Object";
|
|
6
|
-
|
|
7
|
-
// src/boundaryErrors.ts
|
|
8
|
-
var ignoreOption = "ignore(value) to store it by reference, untracked";
|
|
9
|
-
var unsafeTrackDataOption = "unsafeTrack(value) to track its data anyway";
|
|
10
|
-
var unsafeTrackPrivateOption = "unsafeTrack(value) tracks public fields while private methods stay untracked";
|
|
11
|
-
var unsafeTrackSlotOption = "unsafeTrack(value) tracks public fields while slot methods stay untracked";
|
|
12
|
-
var unsafeTrackLossyOption = "unsafeTrack(value) to track it lossily";
|
|
13
|
-
var locationClause = (path) => path === void 0 || path.length === 0 ? "" : ` at /${path.join("/")}`;
|
|
14
|
-
var boundaryError = (className, reason, options, path) => new Error(
|
|
15
|
-
`opshot: ${className}${locationClause(path)} cannot be tracked (${reason}). Options:
|
|
16
|
-
${options.map((option) => `- ${option}`).join("\n")}`
|
|
17
|
-
);
|
|
18
|
-
var slotContainerError = (className, trackedName, path) => boundaryError(
|
|
19
|
-
className,
|
|
20
|
-
"its state lives in internal slots",
|
|
21
|
-
[`use ${trackedName} for a tracked equivalent`, unsafeTrackLossyOption, ignoreOption],
|
|
22
|
-
path
|
|
23
|
-
);
|
|
24
|
-
var arraySubclassError = (className, path) => boundaryError(className, "array subclasses are not plain arrays", [unsafeTrackDataOption, ignoreOption], path);
|
|
25
|
-
var cleanClassError = (className, path) => boundaryError(className, "arrow-method writes won't be tracked", [unsafeTrackDataOption, ignoreOption], path);
|
|
26
|
-
var privateClassError = (className, path) => boundaryError(className, "its state is hidden in private fields", [unsafeTrackPrivateOption, ignoreOption], path);
|
|
27
|
-
var nativeClassError = (className, path) => boundaryError(className, "its state is hidden in internal slots", [unsafeTrackSlotOption, ignoreOption], path);
|
|
28
|
-
var nonWritablePropertyError = (value, path) => boundaryError(
|
|
29
|
-
constructorName(value.constructor),
|
|
30
|
-
"a non-writable property's interior is silently mutable and untracked",
|
|
31
|
-
["make the property writable", "ignore(value) to declare the escape"],
|
|
32
|
-
path
|
|
33
|
-
);
|
|
34
|
-
var inheritsFromPrototype = (value, prototype) => {
|
|
35
|
-
for (let current = Reflect.getPrototypeOf(value); current !== null; current = Reflect.getPrototypeOf(current))
|
|
36
|
-
if (current === prototype) return true;
|
|
37
|
-
return false;
|
|
38
|
-
};
|
|
39
|
-
var rejectionError = (value, kind, path) => {
|
|
40
|
-
const className = constructorName(value.constructor);
|
|
41
|
-
if (inheritsFromPrototype(value, Map.prototype)) return slotContainerError(className, "TrackedMap", path);
|
|
42
|
-
if (inheritsFromPrototype(value, Set.prototype)) return slotContainerError(className, "TrackedSet", path);
|
|
43
|
-
if (inheritsFromPrototype(value, Date.prototype)) return slotContainerError(className, "TrackedDate", path);
|
|
44
|
-
switch (kind) {
|
|
45
|
-
case "arraySubclass":
|
|
46
|
-
return arraySubclassError(className, path);
|
|
47
|
-
case "cleanClass":
|
|
48
|
-
return cleanClassError(className, path);
|
|
49
|
-
case "privateClass":
|
|
50
|
-
return privateClassError(className, path);
|
|
51
|
-
case "nativeClass":
|
|
52
|
-
return nativeClassError(className, path);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// src/classify.ts
|
|
57
|
-
var isDangerousKind = (kind) => kind !== "plain" && kind !== "plainArray" && kind !== "cleanClass";
|
|
58
|
-
var sourceCache = /* @__PURE__ */ new WeakMap();
|
|
59
|
-
var kindCache = /* @__PURE__ */ new WeakMap();
|
|
60
|
-
var readSource = (constructor) => {
|
|
61
|
-
const cached = sourceCache.get(constructor);
|
|
62
|
-
if (cached !== void 0) return cached;
|
|
63
|
-
const source = Function.prototype.toString.call(constructor);
|
|
64
|
-
sourceCache.set(constructor, source);
|
|
65
|
-
return source;
|
|
66
|
-
};
|
|
67
|
-
var privateNameAccess = /\.\s*#[A-Za-z_$]/;
|
|
68
|
-
var privateNameDeclaration = new RegExp(
|
|
69
|
-
String.raw`[{;}](?:\s|\/\*[\s\S]*?\*\/|\/\/[^\n]*\n|static\b|async\b|get\b|set\b|\*)*` + String.raw`#[A-Za-z_$][\w$]*` + String.raw`(?:[ \t]*(?:\/\*[\s\S]*?\*\/[ \t]*)*[(=;}]|[ \t]*(?:\/\/[^\n]*|\/\*[\s\S]*?\*\/[ \t]*)?(?:\r?\n|$))`,
|
|
70
|
-
"m"
|
|
71
|
-
);
|
|
72
|
-
var hasPrivateName = (source) => privateNameAccess.test(source) || privateNameDeclaration.test(source);
|
|
73
|
-
var classifyChain = (initialConstructor) => {
|
|
74
|
-
if (typeof initialConstructor !== "function") return "cleanClass";
|
|
75
|
-
const cached = kindCache.get(initialConstructor);
|
|
76
|
-
if (cached !== void 0) return cached;
|
|
77
|
-
let sawNativeSource = false;
|
|
78
|
-
let current = initialConstructor;
|
|
79
|
-
let kind = "cleanClass";
|
|
80
|
-
while (typeof current === "function" && current !== Object && current !== Array && current !== Function.prototype) {
|
|
81
|
-
const source = readSource(current);
|
|
82
|
-
if (hasPrivateName(source)) {
|
|
83
|
-
kind = "privateClass";
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
if (source.includes("[native code]")) sawNativeSource = true;
|
|
87
|
-
current = Reflect.getPrototypeOf(current);
|
|
88
|
-
}
|
|
89
|
-
if (kind !== "privateClass") kind = sawNativeSource ? "nativeClass" : "cleanClass";
|
|
90
|
-
kindCache.set(initialConstructor, kind);
|
|
91
|
-
return kind;
|
|
92
|
-
};
|
|
93
|
-
function classifyValue(value) {
|
|
94
|
-
const prototype = Object.getPrototypeOf(value);
|
|
95
|
-
if (Array.isArray(value))
|
|
96
|
-
return prototype === Array.prototype || prototype === null ? "plainArray" : "arraySubclass";
|
|
97
|
-
if (prototype === Object.prototype || prototype === null) return "plain";
|
|
98
|
-
return classifyChain(value.constructor);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// src/node.ts
|
|
102
|
-
var byRaw = /* @__PURE__ */ new WeakMap();
|
|
103
|
-
var byProxy = /* @__PURE__ */ new WeakMap();
|
|
104
|
-
var proxyHandler;
|
|
105
|
-
function installProxyHandler(handler2) {
|
|
106
|
-
proxyHandler = handler2;
|
|
107
|
-
}
|
|
108
|
-
function recordOf(value) {
|
|
109
|
-
return byRaw.get(value) ?? byProxy.get(value);
|
|
110
|
-
}
|
|
111
|
-
function rawOf(value) {
|
|
112
|
-
return recordOf(value)?.raw ?? value;
|
|
113
|
-
}
|
|
114
|
-
function proxyOf(raw) {
|
|
115
|
-
const existing = recordOf(raw);
|
|
116
|
-
if (existing !== void 0) return existing.proxy;
|
|
117
|
-
if (proxyHandler === void 0) throw new Error("opshot: proxy handler is not installed");
|
|
118
|
-
const proxy = new Proxy(raw, proxyHandler);
|
|
119
|
-
const record = { raw, proxy, memberships: /* @__PURE__ */ new Map() };
|
|
120
|
-
byRaw.set(raw, record);
|
|
121
|
-
byProxy.set(proxy, record);
|
|
122
|
-
return proxy;
|
|
123
|
-
}
|
|
124
|
-
function handlesOf(node) {
|
|
125
|
-
return membershipsOf(node).map(([handle]) => handle);
|
|
126
|
-
}
|
|
127
|
-
function membershipsOf(node) {
|
|
128
|
-
const record = recordOf(rawOf(node));
|
|
129
|
-
if (record === void 0) return [];
|
|
130
|
-
const memberships = new Array();
|
|
131
|
-
for (const [handle, membership] of record.memberships) {
|
|
132
|
-
if (membership.edges > 0) memberships.push([handle, membership]);
|
|
133
|
-
}
|
|
134
|
-
return memberships;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/ignore.ts
|
|
138
|
-
var ignored = /* @__PURE__ */ new WeakSet();
|
|
139
|
-
function ignore(value, on = true) {
|
|
140
|
-
if (value === null || typeof value !== "object" && typeof value !== "function") return value;
|
|
141
|
-
if (on) ignored.add(rawOf(value));
|
|
142
|
-
else ignored.delete(rawOf(value));
|
|
143
|
-
return value;
|
|
144
|
-
}
|
|
145
|
-
var isIgnored = (value) => ignored.has(rawOf(value));
|
|
146
|
-
|
|
147
|
-
// src/unsafeTrack.ts
|
|
148
|
-
var unsafeMarked = /* @__PURE__ */ new WeakSet();
|
|
149
|
-
function unsafeTrack(value, on = true) {
|
|
150
|
-
if (value === null || typeof value !== "object" && typeof value !== "function") return value;
|
|
151
|
-
if (on) unsafeMarked.add(rawOf(value));
|
|
152
|
-
else unsafeMarked.delete(rawOf(value));
|
|
153
|
-
return value;
|
|
154
|
-
}
|
|
155
|
-
var isUnsafeMarked = (value) => unsafeMarked.has(rawOf(value));
|
|
156
|
-
|
|
157
|
-
// src/utils/dataEntries.ts
|
|
158
|
-
var walkDataEntries = (value) => {
|
|
159
|
-
const entries = new Array();
|
|
160
|
-
for (const key of Reflect.ownKeys(value)) {
|
|
161
|
-
if (typeof key !== "string" || key === "__proto__") continue;
|
|
162
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(value, key);
|
|
163
|
-
if (descriptor === void 0 || !descriptor.enumerable || !("value" in descriptor)) continue;
|
|
164
|
-
entries.push({ key, value: descriptor.value, writable: descriptor.writable === true });
|
|
165
|
-
}
|
|
166
|
-
return entries;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
// src/edges.ts
|
|
170
|
-
var isTrackedEntry = (value, writable) => writable && typeof value === "object" && value !== null && !isIgnored(value) && !Object.isFrozen(value);
|
|
171
|
-
var checkNode = (node, entries, route) => {
|
|
172
|
-
const kind = classifyValue(node);
|
|
173
|
-
if (isDangerousKind(kind)) throw rejectionError(node, kind, route);
|
|
174
|
-
for (const entry of entries) {
|
|
175
|
-
if (typeof entry.value === "function") {
|
|
176
|
-
if (kind === "cleanClass") throw rejectionError(node, "cleanClass", [...route, entry.key]);
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
if (typeof entry.value !== "object" || entry.value === null) continue;
|
|
180
|
-
if (isIgnored(entry.value) || Object.isFrozen(entry.value)) continue;
|
|
181
|
-
if (!entry.writable) throw nonWritablePropertyError(node, [...route, entry.key]);
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var descend = (handle, node, route, checked) => {
|
|
185
|
-
const entries = walkDataEntries(node);
|
|
186
|
-
if (checked) checkNode(node, entries, route);
|
|
187
|
-
for (const entry of entries) {
|
|
188
|
-
if (isTrackedEntry(entry.value, entry.writable))
|
|
189
|
-
attach(handle, node, entry.key, entry.value, [...route, entry.key]);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
var flip = (handle, node, route) => {
|
|
193
|
-
const membership = recordOf(node)?.memberships.get(handle);
|
|
194
|
-
if (!membership?.exempt) return;
|
|
195
|
-
membership.exempt = false;
|
|
196
|
-
const entries = walkDataEntries(node);
|
|
197
|
-
checkNode(node, entries, route);
|
|
198
|
-
for (const entry of entries) {
|
|
199
|
-
if (!isTrackedEntry(entry.value, entry.writable)) continue;
|
|
200
|
-
const child = rawOf(entry.value);
|
|
201
|
-
if (recordOf(child)?.memberships.has(handle) === true) flip(handle, child, [...route, entry.key]);
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
var cascade = (handle, node, keys) => {
|
|
205
|
-
for (const key of keys) {
|
|
206
|
-
const value = Reflect.get(node, key);
|
|
207
|
-
if (typeof value !== "object" || value === null) continue;
|
|
208
|
-
const child = rawOf(value);
|
|
209
|
-
if (recordOf(child)?.memberships.has(handle) === true) detach(handle, child);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
function attach(handle, parent, key, child, route) {
|
|
213
|
-
const parentMembership = recordOf(parent)?.memberships.get(handle);
|
|
214
|
-
if (parentMembership === void 0) return;
|
|
215
|
-
parentMembership.keys.add(key);
|
|
216
|
-
const rawChild = rawOf(child);
|
|
217
|
-
proxyOf(rawChild);
|
|
218
|
-
const record = recordOf(rawChild);
|
|
219
|
-
if (record === void 0) return;
|
|
220
|
-
const edgeExempt = parentMembership.exempt || isUnsafeMarked(rawChild);
|
|
221
|
-
const membership = record.memberships.get(handle);
|
|
222
|
-
if (membership === void 0) {
|
|
223
|
-
record.memberships.set(handle, { edges: 1, exempt: edgeExempt, keys: /* @__PURE__ */ new Set() });
|
|
224
|
-
descend(handle, rawChild, route, !edgeExempt);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
membership.edges += 1;
|
|
228
|
-
if (membership.exempt && !edgeExempt) flip(handle, rawChild, route);
|
|
229
|
-
}
|
|
230
|
-
function attachRoot(handle, root, exempt) {
|
|
231
|
-
const record = recordOf(root);
|
|
232
|
-
if (record === void 0) return;
|
|
233
|
-
record.memberships.set(handle, { edges: 1, exempt, keys: /* @__PURE__ */ new Set() });
|
|
234
|
-
try {
|
|
235
|
-
descend(handle, root, [], !exempt);
|
|
236
|
-
} catch (error) {
|
|
237
|
-
evict(handle, root);
|
|
238
|
-
throw error;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
function detach(handle, child) {
|
|
242
|
-
const rawChild = rawOf(child);
|
|
243
|
-
const record = recordOf(rawChild);
|
|
244
|
-
const membership = record?.memberships.get(handle);
|
|
245
|
-
if (record === void 0 || membership === void 0) return;
|
|
246
|
-
membership.edges -= 1;
|
|
247
|
-
if (membership.edges > 0) return;
|
|
248
|
-
record.memberships.delete(handle);
|
|
249
|
-
cascade(handle, rawChild, membership.keys);
|
|
250
|
-
}
|
|
251
|
-
function evict(handle, node) {
|
|
252
|
-
const rawNode = rawOf(node);
|
|
253
|
-
const record = recordOf(rawNode);
|
|
254
|
-
const membership = record?.memberships.get(handle);
|
|
255
|
-
if (record === void 0 || membership === void 0) return;
|
|
256
|
-
record.memberships.delete(handle);
|
|
257
|
-
cascade(handle, rawNode, membership.keys);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// src/utils/predicates.ts
|
|
261
|
-
var isObjectLike = (value) => value !== null && (typeof value === "object" || typeof value === "function");
|
|
262
|
-
|
|
263
|
-
// src/identity.ts
|
|
264
|
-
var readProxyTargets = /* @__PURE__ */ new WeakMap();
|
|
265
|
-
var identityRecords = /* @__PURE__ */ new WeakMap();
|
|
266
|
-
var nextInternId = 0;
|
|
267
|
-
var registerReadProxyTarget = (readProxy, target) => {
|
|
268
|
-
readProxyTargets.set(readProxy, target);
|
|
269
|
-
};
|
|
270
|
-
var getRegisteredReadProxyTarget = (readProxy) => readProxyTargets.get(readProxy);
|
|
271
|
-
function resolveIdentity(value) {
|
|
272
|
-
let current = value;
|
|
273
|
-
while (isObjectLike(current)) {
|
|
274
|
-
const readTarget = getRegisteredReadProxyTarget(current);
|
|
275
|
-
if (readTarget !== void 0 && readTarget !== current) {
|
|
276
|
-
current = readTarget;
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
const raw = rawOf(current);
|
|
280
|
-
if (raw !== current) {
|
|
281
|
-
current = raw;
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
break;
|
|
285
|
-
}
|
|
286
|
-
return current;
|
|
287
|
-
}
|
|
288
|
-
var recordFor = (key) => {
|
|
289
|
-
let record = identityRecords.get(key);
|
|
290
|
-
if (record === void 0) {
|
|
291
|
-
record = {};
|
|
292
|
-
identityRecords.set(key, record);
|
|
293
|
-
}
|
|
294
|
-
return record;
|
|
295
|
-
};
|
|
296
|
-
function identify(value) {
|
|
297
|
-
const target = resolveIdentity(value);
|
|
298
|
-
if (!isObjectLike(target)) return value;
|
|
299
|
-
const record = recordFor(target);
|
|
300
|
-
if (record.token !== void 0) return record.token;
|
|
301
|
-
const token = Object.freeze({});
|
|
302
|
-
record.token = token;
|
|
303
|
-
return token;
|
|
304
|
-
}
|
|
305
|
-
var internIdentity = (key) => {
|
|
306
|
-
const resolved = resolveIdentity(key);
|
|
307
|
-
const record = recordFor(resolved);
|
|
308
|
-
if (record.id !== void 0) return record.id;
|
|
309
|
-
const id = nextInternId;
|
|
310
|
-
nextInternId += 1;
|
|
311
|
-
record.id = id;
|
|
312
|
-
return id;
|
|
313
|
-
};
|
|
314
|
-
function isSameIdentity(first, second) {
|
|
315
|
-
const resolvedFirst = resolveIdentity(first);
|
|
316
|
-
const resolvedSecond = resolveIdentity(second);
|
|
317
|
-
return resolvedFirst === resolvedSecond;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// src/peelReadProxy.ts
|
|
321
|
-
function peelReadProxy(value) {
|
|
322
|
-
if (!isObjectLike(value)) return value;
|
|
323
|
-
let current = value;
|
|
324
|
-
while (isObjectLike(current)) {
|
|
325
|
-
const registeredTarget = getRegisteredReadProxyTarget(current);
|
|
326
|
-
if (registeredTarget === void 0) break;
|
|
327
|
-
current = registeredTarget;
|
|
328
|
-
}
|
|
329
|
-
return current;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// src/handle.ts
|
|
333
|
-
function handleOf(state) {
|
|
334
|
-
const peeled = peelReadProxy(state);
|
|
335
|
-
if (!isObjectLike(peeled)) return void 0;
|
|
336
|
-
const raw = rawOf(peeled);
|
|
337
|
-
const record = recordOf(raw);
|
|
338
|
-
if (record === void 0) return void 0;
|
|
339
|
-
for (const handle of record.memberships.keys()) {
|
|
340
|
-
if (handle.root === raw) return handle;
|
|
341
|
-
}
|
|
342
|
-
return void 0;
|
|
343
|
-
}
|
|
344
|
-
function requireHandle(state, message) {
|
|
345
|
-
const handle = handleOf(state);
|
|
346
|
-
if (handle === void 0) throw new Error(message);
|
|
347
|
-
return handle;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// src/batch.ts
|
|
351
|
-
var metaStack = [];
|
|
352
|
-
function currentMeta() {
|
|
353
|
-
return metaStack.length === 0 ? void 0 : metaStack[metaStack.length - 1];
|
|
354
|
-
}
|
|
355
|
-
function batch(callback, meta) {
|
|
356
|
-
metaStack.push(meta);
|
|
357
|
-
try {
|
|
358
|
-
callback();
|
|
359
|
-
} finally {
|
|
360
|
-
metaStack.pop();
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// src/emit/emitterDeliver.ts
|
|
365
|
-
var runDelivery = (pending, failures) => {
|
|
366
|
-
pending.handle.lastDirty = pending.dirty;
|
|
367
|
-
for (const deliver of pending.deliveries) {
|
|
368
|
-
try {
|
|
369
|
-
deliver(pending.operations);
|
|
370
|
-
} catch (error) {
|
|
371
|
-
failures.push(error);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
var raiseFailures = (failures) => {
|
|
376
|
-
if (failures.length === 0) return;
|
|
377
|
-
if (failures.length > 1) throw new AggregateError(failures, "opshot: listeners failed during delivery");
|
|
378
|
-
throw failures[0];
|
|
379
|
-
};
|
|
380
|
-
var queuedDeliveries = [];
|
|
381
|
-
var deliveryFailures = [];
|
|
382
|
-
var isDraining = false;
|
|
383
|
-
var prepareDelivery = (handle, operations, dirty) => ({
|
|
384
|
-
deliveries: [...handle.subscribers.values()],
|
|
385
|
-
operations,
|
|
386
|
-
handle,
|
|
387
|
-
dirty
|
|
388
|
-
});
|
|
389
|
-
var enqueueDelivery = (pending) => {
|
|
390
|
-
queuedDeliveries.push(pending);
|
|
391
|
-
};
|
|
392
|
-
var drainDeliveries = () => {
|
|
393
|
-
if (isDraining) return;
|
|
394
|
-
isDraining = true;
|
|
395
|
-
let failures = [];
|
|
396
|
-
try {
|
|
397
|
-
while (queuedDeliveries.length > 0) {
|
|
398
|
-
for (const queued of queuedDeliveries.splice(0, queuedDeliveries.length)) {
|
|
399
|
-
runDelivery(queued, deliveryFailures);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
} finally {
|
|
403
|
-
isDraining = false;
|
|
404
|
-
failures = deliveryFailures.splice(0, deliveryFailures.length);
|
|
405
|
-
}
|
|
406
|
-
raiseFailures(failures);
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// src/emit/window.ts
|
|
410
|
-
function recordOperation(handle, raw, pending) {
|
|
411
|
-
let byKey = handle.pendingIndex.get(raw);
|
|
412
|
-
if (byKey === void 0) {
|
|
413
|
-
byKey = /* @__PURE__ */ new Map();
|
|
414
|
-
handle.pendingIndex.set(raw, byKey);
|
|
415
|
-
}
|
|
416
|
-
const index = byKey.get(pending.key);
|
|
417
|
-
const existing = index === void 0 ? void 0 : handle.pending[index];
|
|
418
|
-
if (existing !== void 0 && Object.is(existing.meta, pending.meta)) {
|
|
419
|
-
existing.after = pending.after;
|
|
420
|
-
existing.hasAfter = pending.hasAfter;
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
handle.pending.push(pending);
|
|
424
|
-
byKey.set(pending.key, handle.pending.length - 1);
|
|
425
|
-
if (handle.scheduledFlush !== void 0) return;
|
|
426
|
-
const run = () => {
|
|
427
|
-
if (handle.scheduledFlush !== run) return;
|
|
428
|
-
flushWindow(handle);
|
|
429
|
-
};
|
|
430
|
-
handle.scheduledFlush = run;
|
|
431
|
-
void Promise.resolve().then(() => {
|
|
432
|
-
if (handle.scheduledFlush !== run) return;
|
|
433
|
-
const emitOn = handle.emitOn;
|
|
434
|
-
if (emitOn === void 0) run();
|
|
435
|
-
else emitOn(run);
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
function flushWindow(handle) {
|
|
439
|
-
handle.scheduledFlush = void 0;
|
|
440
|
-
const pending = handle.pending.splice(0);
|
|
441
|
-
handle.pendingIndex.clear();
|
|
442
|
-
const operations = new Array();
|
|
443
|
-
for (const item of pending) {
|
|
444
|
-
if (item.hasBefore === item.hasAfter && (!item.hasBefore || Object.is(item.before, item.after))) continue;
|
|
445
|
-
const operation = {
|
|
446
|
-
node: item.node,
|
|
447
|
-
key: item.key,
|
|
448
|
-
meta: item.meta,
|
|
449
|
-
...item.hasBefore ? { before: item.before } : {},
|
|
450
|
-
...item.hasAfter ? { after: item.after } : {}
|
|
451
|
-
};
|
|
452
|
-
operations.push(Object.freeze(operation));
|
|
453
|
-
}
|
|
454
|
-
if (operations.length === 0) return;
|
|
455
|
-
const edges = /* @__PURE__ */ new Map();
|
|
456
|
-
const nodes = /* @__PURE__ */ new Set();
|
|
457
|
-
for (const operation of operations) {
|
|
458
|
-
const raw = rawOf(operation.node);
|
|
459
|
-
let keys = edges.get(raw);
|
|
460
|
-
if (keys === void 0) {
|
|
461
|
-
keys = /* @__PURE__ */ new Set();
|
|
462
|
-
edges.set(raw, keys);
|
|
463
|
-
}
|
|
464
|
-
keys.add(operation.key);
|
|
465
|
-
nodes.add(raw);
|
|
466
|
-
}
|
|
467
|
-
const dirty = { edges, nodes };
|
|
468
|
-
enqueueDelivery(prepareDelivery(handle, operations, dirty));
|
|
469
|
-
drainDeliveries();
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// src/proxy.ts
|
|
473
|
-
var prototypeFunctionOf = (target, key) => {
|
|
474
|
-
for (let holder = Reflect.getPrototypeOf(target); holder !== null; holder = Reflect.getPrototypeOf(holder)) {
|
|
475
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(holder, key);
|
|
476
|
-
if (descriptor === void 0) continue;
|
|
477
|
-
const method = "value" in descriptor ? descriptor.value : void 0;
|
|
478
|
-
return typeof method === "function" ? method : void 0;
|
|
479
|
-
}
|
|
480
|
-
return void 0;
|
|
481
|
-
};
|
|
482
|
-
var isRideAlongKey = (target, key) => {
|
|
483
|
-
if (key === "__proto__") return true;
|
|
484
|
-
if (key === "length") return false;
|
|
485
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
|
|
486
|
-
return descriptor?.enumerable === false;
|
|
487
|
-
};
|
|
488
|
-
var writesThroughAccessor = (target, property) => {
|
|
489
|
-
let holder = target;
|
|
490
|
-
while (holder !== null) {
|
|
491
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(holder, property);
|
|
492
|
-
if (descriptor !== void 0) return !("value" in descriptor);
|
|
493
|
-
holder = Reflect.getPrototypeOf(holder);
|
|
494
|
-
}
|
|
495
|
-
return false;
|
|
496
|
-
};
|
|
497
|
-
var proxied = (value) => isObjectLike(value) ? recordOf(value)?.proxy ?? value : value;
|
|
498
|
-
var truncatedOwnEntriesOf = (target, next) => {
|
|
499
|
-
if (!Array.isArray(target)) return [];
|
|
500
|
-
const coercible = next === null || typeof next !== "object" && typeof next !== "function";
|
|
501
|
-
const newLength = coercible ? Number(next) : Number.NaN;
|
|
502
|
-
if (!Number.isInteger(newLength) || newLength < 0 || newLength >= target.length) return [];
|
|
503
|
-
const truncated = new Array();
|
|
504
|
-
for (let index = newLength; index < target.length; index += 1) {
|
|
505
|
-
const key = String(index);
|
|
506
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
|
|
507
|
-
if (descriptor === void 0 || !("value" in descriptor)) continue;
|
|
508
|
-
truncated.push({
|
|
509
|
-
key,
|
|
510
|
-
value: descriptor.value,
|
|
511
|
-
writable: descriptor.writable === true
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
return truncated;
|
|
515
|
-
};
|
|
516
|
-
var ownDataDescriptor = (target, key) => {
|
|
517
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
|
|
518
|
-
if (descriptor === void 0 || !("value" in descriptor)) return { hadPrevious: false, previous: void 0 };
|
|
519
|
-
return { hadPrevious: true, previous: descriptor.value };
|
|
520
|
-
};
|
|
521
|
-
var handler = {
|
|
522
|
-
get(target, key, receiver) {
|
|
523
|
-
const value = Reflect.get(target, key, receiver);
|
|
524
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
|
|
525
|
-
const locked = descriptor?.writable === false && descriptor.configurable === false;
|
|
526
|
-
if (locked || !isObjectLike(value)) return value;
|
|
527
|
-
if (typeof value === "function") {
|
|
528
|
-
const method = prototypeFunctionOf(target, key);
|
|
529
|
-
const kind = classifyValue(target);
|
|
530
|
-
if (method !== void 0 && value === method && (kind === "nativeClass" || kind === "privateClass")) {
|
|
531
|
-
const bound = Function.prototype.bind.call(method, target);
|
|
532
|
-
return typeof bound === "function" ? bound : value;
|
|
533
|
-
}
|
|
534
|
-
return value;
|
|
535
|
-
}
|
|
536
|
-
return recordOf(value)?.proxy ?? value;
|
|
537
|
-
},
|
|
538
|
-
set(target, key, value, receiver) {
|
|
539
|
-
if (typeof key !== "string" || writesThroughAccessor(target, key) || isRideAlongKey(target, key)) {
|
|
540
|
-
return Reflect.set(target, key, value, receiver);
|
|
541
|
-
}
|
|
542
|
-
const { hadPrevious, previous } = ownDataDescriptor(target, key);
|
|
543
|
-
const resolved = isObjectLike(value) ? rawOf(value) : value;
|
|
544
|
-
const memberships = membershipsOf(target).map(([handle, membership]) => ({
|
|
545
|
-
handle,
|
|
546
|
-
membership,
|
|
547
|
-
hadKey: membership.keys.has(key)
|
|
548
|
-
}));
|
|
549
|
-
const truncated = key === "length" ? truncatedOwnEntriesOf(target, resolved) : [];
|
|
550
|
-
const previousLength = Array.isArray(target) ? target.length : void 0;
|
|
551
|
-
if (typeof resolved === "function" && memberships.some(({ membership }) => !membership.exempt)) {
|
|
552
|
-
const kind = classifyValue(target);
|
|
553
|
-
if (kind !== "plain" && kind !== "plainArray") throw rejectionError(target, kind, [key]);
|
|
554
|
-
}
|
|
555
|
-
const incoming = resolved !== previous && isTrackedEntry(resolved, true) ? resolved : void 0;
|
|
556
|
-
let rollBack;
|
|
557
|
-
if (incoming !== void 0) {
|
|
558
|
-
const started = new Array();
|
|
559
|
-
rollBack = () => {
|
|
560
|
-
for (const { handle, membership, hadKey } of started) {
|
|
561
|
-
detach(handle, incoming);
|
|
562
|
-
if (!hadKey) membership.keys.delete(key);
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
try {
|
|
566
|
-
for (const write of memberships) {
|
|
567
|
-
started.push(write);
|
|
568
|
-
attach(write.handle, target, key, incoming, [key]);
|
|
569
|
-
}
|
|
570
|
-
} catch (error) {
|
|
571
|
-
rollBack();
|
|
572
|
-
throw error;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
const result = Reflect.set(target, key, resolved, receiver);
|
|
576
|
-
if (!result) {
|
|
577
|
-
rollBack?.();
|
|
578
|
-
return result;
|
|
579
|
-
}
|
|
580
|
-
const meta = currentMeta();
|
|
581
|
-
const node = proxyOf(target);
|
|
582
|
-
for (const { handle, membership, hadKey } of memberships) {
|
|
583
|
-
for (const entry of truncated) {
|
|
584
|
-
if (membership.keys.delete(entry.key) && isObjectLike(entry.value)) detach(handle, entry.value);
|
|
585
|
-
recordOperation(handle, target, {
|
|
586
|
-
node,
|
|
587
|
-
key: entry.key,
|
|
588
|
-
meta,
|
|
589
|
-
before: proxied(entry.value),
|
|
590
|
-
hasBefore: true,
|
|
591
|
-
hasAfter: false
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
if (hadKey && previous !== resolved) {
|
|
595
|
-
if (isObjectLike(previous)) detach(handle, previous);
|
|
596
|
-
if (incoming === void 0) membership.keys.delete(key);
|
|
597
|
-
}
|
|
598
|
-
recordOperation(handle, target, {
|
|
599
|
-
node,
|
|
600
|
-
key,
|
|
601
|
-
meta,
|
|
602
|
-
before: proxied(previous),
|
|
603
|
-
after: proxied(resolved),
|
|
604
|
-
hasBefore: hadPrevious,
|
|
605
|
-
hasAfter: true
|
|
606
|
-
});
|
|
607
|
-
if (key !== "length" && Array.isArray(target) && previousLength !== target.length) {
|
|
608
|
-
recordOperation(handle, target, {
|
|
609
|
-
node,
|
|
610
|
-
key: "length",
|
|
611
|
-
meta,
|
|
612
|
-
before: previousLength,
|
|
613
|
-
after: target.length,
|
|
614
|
-
hasBefore: true,
|
|
615
|
-
hasAfter: true
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
return result;
|
|
620
|
-
},
|
|
621
|
-
deleteProperty(target, key) {
|
|
622
|
-
if (typeof key !== "string" || isRideAlongKey(target, key)) return Reflect.deleteProperty(target, key);
|
|
623
|
-
const { hadPrevious, previous } = ownDataDescriptor(target, key);
|
|
624
|
-
const result = Reflect.deleteProperty(target, key);
|
|
625
|
-
if (!result || !hadPrevious) return result;
|
|
626
|
-
const meta = currentMeta();
|
|
627
|
-
const node = proxyOf(target);
|
|
628
|
-
for (const [handle, membership] of membershipsOf(target)) {
|
|
629
|
-
if (membership.keys.delete(key) && isObjectLike(previous)) detach(handle, previous);
|
|
630
|
-
recordOperation(handle, target, {
|
|
631
|
-
node,
|
|
632
|
-
key,
|
|
633
|
-
meta,
|
|
634
|
-
before: proxied(previous),
|
|
635
|
-
hasBefore: true,
|
|
636
|
-
hasAfter: false
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
return result;
|
|
640
|
-
},
|
|
641
|
-
preventExtensions(target) {
|
|
642
|
-
for (const [handle] of membershipsOf(target)) evict(handle, target);
|
|
643
|
-
return Reflect.preventExtensions(target);
|
|
644
|
-
},
|
|
645
|
-
defineProperty(target, key, descriptor) {
|
|
646
|
-
return Reflect.defineProperty(target, key, descriptor);
|
|
647
|
-
},
|
|
648
|
-
setPrototypeOf(target, prototype) {
|
|
649
|
-
return Reflect.setPrototypeOf(target, prototype);
|
|
650
|
-
},
|
|
651
|
-
has(target, key) {
|
|
652
|
-
return Reflect.has(target, key);
|
|
653
|
-
},
|
|
654
|
-
ownKeys(target) {
|
|
655
|
-
return Reflect.ownKeys(target);
|
|
656
|
-
},
|
|
657
|
-
getOwnPropertyDescriptor(target, key) {
|
|
658
|
-
return Reflect.getOwnPropertyDescriptor(target, key);
|
|
659
|
-
}
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
// src/createMutableState.ts
|
|
663
|
-
installProxyHandler(handler);
|
|
664
|
-
function createMutableState(properties, options) {
|
|
665
|
-
const incoming = peelReadProxy(properties);
|
|
666
|
-
if (typeof incoming !== "object" || incoming === null) return properties;
|
|
667
|
-
if (isIgnored(incoming)) return properties;
|
|
668
|
-
if (Object.isFrozen(incoming)) return properties;
|
|
669
|
-
const root = rawOf(incoming);
|
|
670
|
-
if (handleOf(incoming) !== void 0) return proxyOf(incoming);
|
|
671
|
-
const strict = options?.strict !== false;
|
|
672
|
-
const exempt = !strict || isUnsafeMarked(root);
|
|
673
|
-
const handle = {
|
|
674
|
-
root,
|
|
675
|
-
strict,
|
|
676
|
-
emitOn: options?.emitOn,
|
|
677
|
-
subscribers: /* @__PURE__ */ new Map(),
|
|
678
|
-
pending: [],
|
|
679
|
-
pendingIndex: /* @__PURE__ */ new Map()
|
|
680
|
-
};
|
|
681
|
-
const proxy = proxyOf(root);
|
|
682
|
-
attachRoot(handle, root, exempt);
|
|
683
|
-
return proxy;
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// src/isState.ts
|
|
687
|
-
function isState(value) {
|
|
688
|
-
const resolved = peelReadProxy(value);
|
|
689
|
-
if (typeof resolved !== "object" || resolved === null) return false;
|
|
690
|
-
return recordOf(resolved)?.proxy === resolved;
|
|
691
|
-
}
|
|
1
|
+
import { addressOf, flushWindow, requireHandle, isSameIdentity } from './chunk-4JZIOHSP.js';
|
|
2
|
+
export { batch, createMutableState, identify, ignore, isSameIdentity, isState, subscribe, unsafeTrack } from './chunk-4JZIOHSP.js';
|
|
692
3
|
|
|
693
4
|
// src/tracked/facadeGuard.ts
|
|
694
5
|
var assertMutableFacade = (facade, mutationKey) => {
|
|
@@ -900,38 +211,6 @@ Object.defineProperty(TrackedDate.prototype, Symbol.toStringTag, {
|
|
|
900
211
|
writable: false
|
|
901
212
|
});
|
|
902
213
|
|
|
903
|
-
// src/tracked/address.ts
|
|
904
|
-
var UnsupportedKeyTypeError = class extends Error {
|
|
905
|
-
constructor(key) {
|
|
906
|
-
super(`opshot: addressOf received unsupported key type ${typeof key}`);
|
|
907
|
-
this.name = "UnsupportedKeyTypeError";
|
|
908
|
-
}
|
|
909
|
-
};
|
|
910
|
-
var addressOf = (key) => {
|
|
911
|
-
if (key === null) return "z";
|
|
912
|
-
if (key === void 0) return "u";
|
|
913
|
-
switch (typeof key) {
|
|
914
|
-
case "string":
|
|
915
|
-
return `s${key}`;
|
|
916
|
-
case "number":
|
|
917
|
-
return `n${String(key)}`;
|
|
918
|
-
case "bigint":
|
|
919
|
-
return `i${String(key)}`;
|
|
920
|
-
case "boolean":
|
|
921
|
-
return key ? "b1" : "b0";
|
|
922
|
-
case "symbol": {
|
|
923
|
-
const registered = Symbol.keyFor(key);
|
|
924
|
-
if (registered !== void 0) return `r${registered}`;
|
|
925
|
-
return `o${internIdentity(key)}`;
|
|
926
|
-
}
|
|
927
|
-
case "object":
|
|
928
|
-
case "function":
|
|
929
|
-
return `o${internIdentity(key)}`;
|
|
930
|
-
default:
|
|
931
|
-
throw new UnsupportedKeyTypeError(key);
|
|
932
|
-
}
|
|
933
|
-
};
|
|
934
|
-
|
|
935
214
|
// src/tracked/slotStore.ts
|
|
936
215
|
var swapChain = /* @__PURE__ */ new WeakMap();
|
|
937
216
|
var compactStore = (store, addressOfEntry) => {
|
|
@@ -1005,10 +284,10 @@ var EmptyMapSlotError = class extends Error {
|
|
|
1005
284
|
this.name = "EmptyMapSlotError";
|
|
1006
285
|
}
|
|
1007
286
|
};
|
|
1008
|
-
var
|
|
287
|
+
var isObjectLike = (value) => value !== null && (typeof value === "object" || typeof value === "function");
|
|
1009
288
|
var isStoredValue = (stored, incoming) => {
|
|
1010
289
|
if (Object.is(stored, incoming)) return true;
|
|
1011
|
-
return
|
|
290
|
+
return isObjectLike(stored) && isObjectLike(incoming) && isSameIdentity(stored, incoming);
|
|
1012
291
|
};
|
|
1013
292
|
var TrackedMap = class {
|
|
1014
293
|
constructor(entries) {
|
|
@@ -1157,535 +436,9 @@ Object.defineProperty(TrackedSet.prototype, Symbol.toStringTag, {
|
|
|
1157
436
|
writable: false
|
|
1158
437
|
});
|
|
1159
438
|
|
|
1160
|
-
// src/emit/emitterListeners.ts
|
|
1161
|
-
var bindings = /* @__PURE__ */ new WeakMap();
|
|
1162
|
-
function addStateListener(state, listener, deliver) {
|
|
1163
|
-
const handle = requireHandle(state, "opshot: subscribe requires a state");
|
|
1164
|
-
handle.subscribers.set(listener, deliver);
|
|
1165
|
-
const unsubscribe = () => {
|
|
1166
|
-
const held = bindings.get(unsubscribe);
|
|
1167
|
-
if (held === void 0) return;
|
|
1168
|
-
held.handle.subscribers.delete(held.listener);
|
|
1169
|
-
bindings.delete(unsubscribe);
|
|
1170
|
-
};
|
|
1171
|
-
bindings.set(unsubscribe, { handle, listener });
|
|
1172
|
-
return unsubscribe;
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
// src/subscribe.ts
|
|
1176
|
-
function subscribe(state, listener) {
|
|
1177
|
-
return addStateListener(state, listener, listener);
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
439
|
// src/flush.ts
|
|
1181
|
-
function flush(state) {
|
|
1182
|
-
flushWindow(requireHandle(
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
// src/react/propWalk.ts
|
|
1186
|
-
var stateKeysByContainer = /* @__PURE__ */ new WeakMap();
|
|
1187
|
-
var noStateKeys = /* @__PURE__ */ new Set();
|
|
1188
|
-
var isReactOwnNode = (value) => "$$typeof" in value || typeof Node !== "undefined" && value instanceof Node;
|
|
1189
|
-
var canRebuild = (container) => !isDangerousKind(classifyValue(container));
|
|
1190
|
-
var childRole = (value, writable, mode) => {
|
|
1191
|
-
if (typeof value !== "object" || value === null) return "skip";
|
|
1192
|
-
if (isReactOwnNode(value)) return "skip";
|
|
1193
|
-
if (!isTrackedEntry(value, mode === "entry" || writable)) return "skip";
|
|
1194
|
-
if (isState(value)) return "state";
|
|
1195
|
-
if (canRebuild(value)) return "descend";
|
|
1196
|
-
return "skip";
|
|
1197
|
-
};
|
|
1198
|
-
var readVerdict = (container, pass) => pass.verdicts.get(container) ?? stateKeysByContainer.get(container) ?? noStateKeys;
|
|
1199
|
-
var createDiscoveryPass = () => ({
|
|
1200
|
-
entriesByContainer: /* @__PURE__ */ new Map(),
|
|
1201
|
-
verdicts: /* @__PURE__ */ new Map(),
|
|
1202
|
-
inProgress: /* @__PURE__ */ new Set(),
|
|
1203
|
-
relaxable: /* @__PURE__ */ new Set()
|
|
1204
|
-
});
|
|
1205
|
-
function visitContainer(container, pass, mode) {
|
|
1206
|
-
if (mode === "nested" && stateKeysByContainer.has(container)) return false;
|
|
1207
|
-
if (pass.inProgress.has(container)) return true;
|
|
1208
|
-
if (pass.verdicts.has(container)) return pass.relaxable.has(container);
|
|
1209
|
-
pass.inProgress.add(container);
|
|
1210
|
-
const entries = walkDataEntries(container);
|
|
1211
|
-
const keys = /* @__PURE__ */ new Set();
|
|
1212
|
-
let dependedOnBackEdge = false;
|
|
1213
|
-
pass.entriesByContainer.set(container, entries);
|
|
1214
|
-
for (const entry of entries) {
|
|
1215
|
-
const role = childRole(entry.value, entry.writable, mode);
|
|
1216
|
-
if (role === "state") {
|
|
1217
|
-
keys.add(entry.key);
|
|
1218
|
-
continue;
|
|
1219
|
-
}
|
|
1220
|
-
if (role !== "descend") continue;
|
|
1221
|
-
const child = entry.value;
|
|
1222
|
-
if (typeof child !== "object" || child === null) continue;
|
|
1223
|
-
if (visitContainer(child, pass, "nested")) dependedOnBackEdge = true;
|
|
1224
|
-
if (readVerdict(child, pass).size > 0) keys.add(entry.key);
|
|
1225
|
-
}
|
|
1226
|
-
pass.inProgress.delete(container);
|
|
1227
|
-
pass.verdicts.set(container, keys);
|
|
1228
|
-
if (dependedOnBackEdge) pass.relaxable.add(container);
|
|
1229
|
-
return dependedOnBackEdge;
|
|
1230
|
-
}
|
|
1231
|
-
function relaxVerdicts(pass, entryContainer) {
|
|
1232
|
-
let gained = true;
|
|
1233
|
-
while (gained) {
|
|
1234
|
-
gained = false;
|
|
1235
|
-
for (const container of pass.relaxable) {
|
|
1236
|
-
const keys = pass.verdicts.get(container);
|
|
1237
|
-
const entries = pass.entriesByContainer.get(container);
|
|
1238
|
-
if (keys === void 0 || entries === void 0) continue;
|
|
1239
|
-
for (const entry of entries) {
|
|
1240
|
-
if (keys.has(entry.key)) continue;
|
|
1241
|
-
if (childRole(entry.value, entry.writable, container === entryContainer ? "entry" : "nested") !== "descend")
|
|
1242
|
-
continue;
|
|
1243
|
-
const child = entry.value;
|
|
1244
|
-
if (typeof child !== "object" || child === null) continue;
|
|
1245
|
-
if (readVerdict(child, pass).size === 0) continue;
|
|
1246
|
-
keys.add(entry.key);
|
|
1247
|
-
gained = true;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
var cacheNestedVerdicts = (pass, skip) => {
|
|
1253
|
-
for (const [visited, keys] of pass.verdicts) {
|
|
1254
|
-
if (visited === skip) continue;
|
|
1255
|
-
stateKeysByContainer.set(visited, keys);
|
|
1256
|
-
}
|
|
1257
|
-
};
|
|
1258
|
-
function discoverStateKeys(container) {
|
|
1259
|
-
const cached = stateKeysByContainer.get(container);
|
|
1260
|
-
if (cached !== void 0) return cached;
|
|
1261
|
-
if (isReactOwnNode(container)) return noStateKeys;
|
|
1262
|
-
if (Object.isFrozen(container) || !canRebuild(container)) return noStateKeys;
|
|
1263
|
-
const pass = createDiscoveryPass();
|
|
1264
|
-
visitContainer(container, pass, "nested");
|
|
1265
|
-
relaxVerdicts(pass);
|
|
1266
|
-
cacheNestedVerdicts(pass);
|
|
1267
|
-
return pass.verdicts.get(container) ?? noStateKeys;
|
|
1268
|
-
}
|
|
1269
|
-
function substituteContainer(container, substitution, wrap, mode) {
|
|
1270
|
-
const rebuilt = substitution.rebuiltByContainer.get(container);
|
|
1271
|
-
if (rebuilt !== void 0) return rebuilt;
|
|
1272
|
-
let stateKeys;
|
|
1273
|
-
if (mode === "nested") {
|
|
1274
|
-
stateKeys = discoverStateKeys(container);
|
|
1275
|
-
} else {
|
|
1276
|
-
const pass = createDiscoveryPass();
|
|
1277
|
-
visitContainer(container, pass, "entry");
|
|
1278
|
-
relaxVerdicts(pass, container);
|
|
1279
|
-
cacheNestedVerdicts(pass, container);
|
|
1280
|
-
stateKeys = pass.verdicts.get(container) ?? noStateKeys;
|
|
1281
|
-
}
|
|
1282
|
-
if (stateKeys.size === 0) {
|
|
1283
|
-
substitution.rebuiltByContainer.set(container, container);
|
|
1284
|
-
return container;
|
|
1285
|
-
}
|
|
1286
|
-
const clone = Array.isArray(container) ? [] : {};
|
|
1287
|
-
Reflect.setPrototypeOf(clone, Reflect.getPrototypeOf(container));
|
|
1288
|
-
substitution.rebuiltByContainer.set(container, clone);
|
|
1289
|
-
const descriptors = Object.getOwnPropertyDescriptors(container);
|
|
1290
|
-
for (const key of stateKeys) {
|
|
1291
|
-
const descriptor = descriptors[key];
|
|
1292
|
-
if (descriptor === void 0 || !("value" in descriptor)) continue;
|
|
1293
|
-
const value = descriptor.value;
|
|
1294
|
-
const role = childRole(value, descriptor.writable === true, mode);
|
|
1295
|
-
if (role === "state") {
|
|
1296
|
-
const source = peelReadProxy(value);
|
|
1297
|
-
if (typeof source !== "object" || source === null) continue;
|
|
1298
|
-
if (!substitution.visitedSources.has(source)) {
|
|
1299
|
-
substitution.visitedSources.add(source);
|
|
1300
|
-
substitution.sources.push(source);
|
|
1301
|
-
}
|
|
1302
|
-
descriptors[key] = { ...descriptor, value: wrap(source) };
|
|
1303
|
-
continue;
|
|
1304
|
-
}
|
|
1305
|
-
if (role !== "descend") continue;
|
|
1306
|
-
if (typeof value !== "object" || value === null) continue;
|
|
1307
|
-
descriptors[key] = { ...descriptor, value: substituteContainer(value, substitution, wrap, "nested") };
|
|
1308
|
-
}
|
|
1309
|
-
Object.defineProperties(clone, descriptors);
|
|
1310
|
-
return clone;
|
|
1311
|
-
}
|
|
1312
|
-
function substituteStates(root, wrap) {
|
|
1313
|
-
const substitution = {
|
|
1314
|
-
rebuiltByContainer: /* @__PURE__ */ new Map(),
|
|
1315
|
-
sources: [],
|
|
1316
|
-
visitedSources: /* @__PURE__ */ new Set()
|
|
1317
|
-
};
|
|
1318
|
-
if (isReactOwnNode(root) || !canRebuild(root)) {
|
|
1319
|
-
return { props: root, sources: substitution.sources };
|
|
1320
|
-
}
|
|
1321
|
-
return { props: substituteContainer(root, substitution, wrap, "entry"), sources: substitution.sources };
|
|
1322
|
-
}
|
|
1323
|
-
var NO_SLOT = /* @__PURE__ */ Symbol("opshot.noDispatcherSlot");
|
|
1324
|
-
var readDispatcher = () => {
|
|
1325
|
-
const internals = React;
|
|
1326
|
-
const modern = internals.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
|
1327
|
-
if (modern !== void 0) return modern.H;
|
|
1328
|
-
const legacy = internals.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?.ReactCurrentDispatcher;
|
|
1329
|
-
if (legacy !== void 0) return legacy.current;
|
|
1330
|
-
return NO_SLOT;
|
|
1331
|
-
};
|
|
1332
|
-
var nonRenderDispatcher;
|
|
1333
|
-
var learnNonRenderDispatcher = () => {
|
|
1334
|
-
const current = readDispatcher();
|
|
1335
|
-
if (current === NO_SLOT || current === null || current === void 0) return;
|
|
1336
|
-
nonRenderDispatcher = current;
|
|
1337
|
-
};
|
|
1338
|
-
var isRendering = () => {
|
|
1339
|
-
if (nonRenderDispatcher === void 0) return false;
|
|
1340
|
-
const current = readDispatcher();
|
|
1341
|
-
if (current === NO_SLOT || current === null || current === void 0) return false;
|
|
1342
|
-
return current !== nonRenderDispatcher;
|
|
1343
|
-
};
|
|
1344
|
-
|
|
1345
|
-
// src/react/readTracker.ts
|
|
1346
|
-
var KEYS_PROPERTY = "k";
|
|
1347
|
-
var HAS_KEY_PROPERTY = "h";
|
|
1348
|
-
var HAS_OWN_KEY_PROPERTY = "o";
|
|
1349
|
-
var ALL_OWN_KEYS_PROPERTY = "w";
|
|
1350
|
-
var isWriteProxy = (value) => recordOf(value)?.proxy === value;
|
|
1351
|
-
var getUsage = (affected, target) => {
|
|
1352
|
-
let used = affected.get(target);
|
|
1353
|
-
if (used === void 0) {
|
|
1354
|
-
used = {};
|
|
1355
|
-
affected.set(target, used);
|
|
1356
|
-
}
|
|
1357
|
-
return used;
|
|
1358
|
-
};
|
|
1359
|
-
var recordIn = (slot, key, value) => {
|
|
1360
|
-
const map = slot ?? /* @__PURE__ */ new Map();
|
|
1361
|
-
if (!map.has(key)) map.set(key, value);
|
|
1362
|
-
return map;
|
|
1363
|
-
};
|
|
1364
|
-
var recordGet = (used, key, value) => {
|
|
1365
|
-
used[KEYS_PROPERTY] = recordIn(used[KEYS_PROPERTY], key, value);
|
|
1366
|
-
};
|
|
1367
|
-
var recordHas = (used, key, value) => {
|
|
1368
|
-
used[HAS_KEY_PROPERTY] = recordIn(used[HAS_KEY_PROPERTY], key, value);
|
|
1369
|
-
};
|
|
1370
|
-
var recordOwn = (used, key, value) => {
|
|
1371
|
-
used[HAS_OWN_KEY_PROPERTY] = recordIn(used[HAS_OWN_KEY_PROPERTY], key, value);
|
|
1372
|
-
};
|
|
1373
|
-
var getPrototypeMethod = (target, prop) => {
|
|
1374
|
-
let prototype = Reflect.getPrototypeOf(target);
|
|
1375
|
-
while (prototype !== null) {
|
|
1376
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(prototype, prop);
|
|
1377
|
-
if (descriptor !== void 0) {
|
|
1378
|
-
const descriptorValue = "value" in descriptor ? descriptor.value : void 0;
|
|
1379
|
-
return typeof descriptorValue === "function" ? descriptorValue : void 0;
|
|
1380
|
-
}
|
|
1381
|
-
prototype = Reflect.getPrototypeOf(prototype);
|
|
1382
|
-
}
|
|
1383
|
-
return void 0;
|
|
1384
|
-
};
|
|
1385
|
-
var UnregisteredReadTrackerError = class extends Error {
|
|
1386
|
-
constructor() {
|
|
1387
|
-
super("opshot: readsIntersectDirty received an unregistered tracker");
|
|
1388
|
-
this.name = "UnregisteredReadTrackerError";
|
|
1389
|
-
}
|
|
1390
|
-
};
|
|
1391
|
-
var trackerPartitions = /* @__PURE__ */ new WeakMap();
|
|
1392
|
-
var partitionsOf = (tracker) => {
|
|
1393
|
-
const partitions = trackerPartitions.get(tracker);
|
|
1394
|
-
if (partitions === void 0) throw new UnregisteredReadTrackerError();
|
|
1395
|
-
return partitions;
|
|
1396
|
-
};
|
|
1397
|
-
var recordedKeysOf = (used) => {
|
|
1398
|
-
const keyMaps = new Array();
|
|
1399
|
-
if (used[KEYS_PROPERTY] !== void 0) keyMaps.push(used[KEYS_PROPERTY]);
|
|
1400
|
-
if (used[HAS_KEY_PROPERTY] !== void 0) keyMaps.push(used[HAS_KEY_PROPERTY]);
|
|
1401
|
-
if (used[HAS_OWN_KEY_PROPERTY] !== void 0) keyMaps.push(used[HAS_OWN_KEY_PROPERTY]);
|
|
1402
|
-
return keyMaps;
|
|
1403
|
-
};
|
|
1404
|
-
function readsIntersectDirty(tracker, dirty) {
|
|
1405
|
-
for (const partition of partitionsOf(tracker).values()) {
|
|
1406
|
-
for (const [writeProxy, used] of partition.affected) {
|
|
1407
|
-
const raw = rawOf(writeProxy);
|
|
1408
|
-
const edges = dirty.edges.get(raw);
|
|
1409
|
-
for (const keys of recordedKeysOf(used)) {
|
|
1410
|
-
for (const key of keys.keys()) {
|
|
1411
|
-
if (typeof key === "symbol") continue;
|
|
1412
|
-
if (edges?.has(key) === true) return true;
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
if (used[ALL_OWN_KEYS_PROPERTY] !== void 0 && dirty.nodes.has(raw)) return true;
|
|
1416
|
-
}
|
|
1417
|
-
for (const writeProxy of partition.identityReads) {
|
|
1418
|
-
if (partition.affected.has(writeProxy)) continue;
|
|
1419
|
-
if (dirty.nodes.has(rawOf(writeProxy))) return true;
|
|
1420
|
-
}
|
|
1421
|
-
}
|
|
1422
|
-
return false;
|
|
1423
|
-
}
|
|
1424
|
-
function readsChanged(tracker) {
|
|
1425
|
-
for (const partition of partitionsOf(tracker).values()) {
|
|
1426
|
-
for (const [writeProxy, used] of partition.affected) {
|
|
1427
|
-
const gets = used[KEYS_PROPERTY];
|
|
1428
|
-
if (gets !== void 0) {
|
|
1429
|
-
for (const [key, stored] of gets) {
|
|
1430
|
-
if (!Object.is(Reflect.get(writeProxy, key, writeProxy), stored)) return true;
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
const hasKeys = used[HAS_KEY_PROPERTY];
|
|
1434
|
-
if (hasKeys !== void 0) {
|
|
1435
|
-
for (const [key, stored] of hasKeys) {
|
|
1436
|
-
if (!Object.is(Reflect.has(writeProxy, key), stored)) return true;
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
const ownKeys = used[HAS_OWN_KEY_PROPERTY];
|
|
1440
|
-
if (ownKeys !== void 0) {
|
|
1441
|
-
for (const [key, stored] of ownKeys) {
|
|
1442
|
-
const present = Reflect.getOwnPropertyDescriptor(writeProxy, key) !== void 0;
|
|
1443
|
-
if (!Object.is(present, stored)) return true;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
const listed = used[ALL_OWN_KEYS_PROPERTY];
|
|
1447
|
-
if (listed !== void 0) {
|
|
1448
|
-
const current = Reflect.ownKeys(writeProxy);
|
|
1449
|
-
if (current.length !== listed.length) return true;
|
|
1450
|
-
for (let index = 0; index < listed.length; index += 1) {
|
|
1451
|
-
if (!Object.is(current[index], listed[index])) return true;
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
return false;
|
|
1457
|
-
}
|
|
1458
|
-
function createReadTracker() {
|
|
1459
|
-
const partitions = /* @__PURE__ */ new Map();
|
|
1460
|
-
let afterRender = false;
|
|
1461
|
-
let releasing = false;
|
|
1462
|
-
const getPartition = (writeProxy) => {
|
|
1463
|
-
let partition = partitions.get(writeProxy);
|
|
1464
|
-
if (partition === void 0) {
|
|
1465
|
-
partition = {
|
|
1466
|
-
affected: /* @__PURE__ */ new Map(),
|
|
1467
|
-
identityReads: /* @__PURE__ */ new Set(),
|
|
1468
|
-
proxyCache: /* @__PURE__ */ new WeakMap()
|
|
1469
|
-
};
|
|
1470
|
-
partitions.set(writeProxy, partition);
|
|
1471
|
-
}
|
|
1472
|
-
return partition;
|
|
1473
|
-
};
|
|
1474
|
-
const shouldRecord = () => !afterRender || isRendering();
|
|
1475
|
-
const trackUsage = (partition, writeProxy) => shouldRecord() ? getUsage(partition.affected, writeProxy) : {};
|
|
1476
|
-
const recordIdentity = (partition, value) => {
|
|
1477
|
-
if (!shouldRecord()) return;
|
|
1478
|
-
if (isObjectLike(value) && isWriteProxy(value)) partition.identityReads.add(value);
|
|
1479
|
-
};
|
|
1480
|
-
const toReadProxy = (writeProxy, partition) => {
|
|
1481
|
-
const raw = rawOf(writeProxy);
|
|
1482
|
-
const cached = partition.proxyCache.get(raw);
|
|
1483
|
-
if (cached !== void 0) return cached;
|
|
1484
|
-
const target = raw;
|
|
1485
|
-
const readProxyBox = {};
|
|
1486
|
-
const boundMethods = /* @__PURE__ */ new WeakMap();
|
|
1487
|
-
const bindMethodToReadProxy = (readProxy2, method) => {
|
|
1488
|
-
const existing = boundMethods.get(method);
|
|
1489
|
-
if (existing !== void 0) return existing;
|
|
1490
|
-
const bound = Function.prototype.bind.call(method, readProxy2);
|
|
1491
|
-
boundMethods.set(method, bound);
|
|
1492
|
-
return bound;
|
|
1493
|
-
};
|
|
1494
|
-
const handler2 = {
|
|
1495
|
-
get(_target, prop) {
|
|
1496
|
-
const readProxy2 = readProxyBox.current;
|
|
1497
|
-
const value = Reflect.get(writeProxy, prop, readProxy2 ?? writeProxy);
|
|
1498
|
-
const used = trackUsage(partition, writeProxy);
|
|
1499
|
-
recordGet(used, prop, value);
|
|
1500
|
-
recordIdentity(partition, value);
|
|
1501
|
-
if (typeof value === "function") {
|
|
1502
|
-
const method = getPrototypeMethod(target, prop);
|
|
1503
|
-
if (method !== void 0 && value === method && readProxy2 !== void 0) {
|
|
1504
|
-
return bindMethodToReadProxy(readProxy2, method);
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
if (!isObjectLike(value)) return value;
|
|
1508
|
-
if (typeof value === "function") return value;
|
|
1509
|
-
if (!isWriteProxy(value)) return value;
|
|
1510
|
-
return toReadProxy(value, partition);
|
|
1511
|
-
},
|
|
1512
|
-
has(_target, prop) {
|
|
1513
|
-
const used = trackUsage(partition, writeProxy);
|
|
1514
|
-
const result = Reflect.has(writeProxy, prop);
|
|
1515
|
-
recordHas(used, prop, result);
|
|
1516
|
-
return result;
|
|
1517
|
-
},
|
|
1518
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
1519
|
-
const used = trackUsage(partition, writeProxy);
|
|
1520
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(writeProxy, prop);
|
|
1521
|
-
recordOwn(used, prop, descriptor !== void 0);
|
|
1522
|
-
return descriptor;
|
|
1523
|
-
},
|
|
1524
|
-
ownKeys() {
|
|
1525
|
-
const used = trackUsage(partition, writeProxy);
|
|
1526
|
-
const keys = Reflect.ownKeys(writeProxy);
|
|
1527
|
-
used[ALL_OWN_KEYS_PROPERTY] ??= keys;
|
|
1528
|
-
return keys;
|
|
1529
|
-
},
|
|
1530
|
-
set(_target, prop, value) {
|
|
1531
|
-
return Reflect.set(writeProxy, prop, value, writeProxy);
|
|
1532
|
-
},
|
|
1533
|
-
deleteProperty(_target, prop) {
|
|
1534
|
-
return Reflect.deleteProperty(writeProxy, prop);
|
|
1535
|
-
}
|
|
1536
|
-
};
|
|
1537
|
-
const readProxy = new Proxy(writeProxy, handler2);
|
|
1538
|
-
readProxyBox.current = readProxy;
|
|
1539
|
-
registerReadProxyTarget(readProxy, writeProxy);
|
|
1540
|
-
partition.proxyCache.set(raw, readProxy);
|
|
1541
|
-
return readProxy;
|
|
1542
|
-
};
|
|
1543
|
-
const tracker = {
|
|
1544
|
-
wrap(writeProxy) {
|
|
1545
|
-
if (!isWriteProxy(writeProxy)) {
|
|
1546
|
-
throw new Error("opshot: ReadTracker.wrap requires a write proxy");
|
|
1547
|
-
}
|
|
1548
|
-
const partition = getPartition(writeProxy);
|
|
1549
|
-
return toReadProxy(writeProxy, partition);
|
|
1550
|
-
},
|
|
1551
|
-
captureReads() {
|
|
1552
|
-
learnNonRenderDispatcher();
|
|
1553
|
-
afterRender = true;
|
|
1554
|
-
},
|
|
1555
|
-
resetReads() {
|
|
1556
|
-
afterRender = false;
|
|
1557
|
-
for (const partition of partitions.values()) {
|
|
1558
|
-
partition.affected.clear();
|
|
1559
|
-
partition.identityReads.clear();
|
|
1560
|
-
partition.proxyCache = /* @__PURE__ */ new WeakMap();
|
|
1561
|
-
}
|
|
1562
|
-
},
|
|
1563
|
-
retain() {
|
|
1564
|
-
releasing = false;
|
|
1565
|
-
},
|
|
1566
|
-
dispose() {
|
|
1567
|
-
releasing = true;
|
|
1568
|
-
void Promise.resolve().then(() => {
|
|
1569
|
-
if (!releasing) return;
|
|
1570
|
-
releasing = false;
|
|
1571
|
-
partitions.clear();
|
|
1572
|
-
});
|
|
1573
|
-
}
|
|
1574
|
-
};
|
|
1575
|
-
trackerPartitions.set(tracker, partitions);
|
|
1576
|
-
return tracker;
|
|
1577
|
-
}
|
|
1578
|
-
var useCommitEffect = typeof document === "undefined" ? useEffect : useLayoutEffect;
|
|
1579
|
-
|
|
1580
|
-
// src/react/scope.tsx
|
|
1581
|
-
var sourcesKey = (sources) => `${sources.length}:${sources.map((source) => addressOf(source)).join(",")}`;
|
|
1582
|
-
var uniqueHandlesOf = (nodes) => {
|
|
1583
|
-
const unique = new Array();
|
|
1584
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1585
|
-
for (const node of nodes) {
|
|
1586
|
-
for (const handle of handlesOf(node)) {
|
|
1587
|
-
if (seen.has(handle)) continue;
|
|
1588
|
-
seen.add(handle);
|
|
1589
|
-
unique.push(handle);
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
return unique;
|
|
1593
|
-
};
|
|
1594
|
-
var arePropsEqual = (previous, next) => {
|
|
1595
|
-
const previousRecord = previous;
|
|
1596
|
-
const nextRecord = next;
|
|
1597
|
-
const keys = Object.keys(previousRecord);
|
|
1598
|
-
if (keys.length !== Object.keys(nextRecord).length) return false;
|
|
1599
|
-
for (const key of keys) {
|
|
1600
|
-
const before = previousRecord[key];
|
|
1601
|
-
const after = nextRecord[key];
|
|
1602
|
-
if (Object.is(before, after)) continue;
|
|
1603
|
-
if (typeof before === "object" && before !== null && typeof after === "object" && after !== null && isState(before) && isState(after) && isSameIdentity(before, after)) {
|
|
1604
|
-
continue;
|
|
1605
|
-
}
|
|
1606
|
-
return false;
|
|
1607
|
-
}
|
|
1608
|
-
return true;
|
|
1609
|
-
};
|
|
1610
|
-
function scope(Component) {
|
|
1611
|
-
const Scoped = (props) => {
|
|
1612
|
-
const readTrackerRef = useRef(void 0);
|
|
1613
|
-
const currentHandlesRef = useRef([]);
|
|
1614
|
-
readTrackerRef.current ??= createReadTracker();
|
|
1615
|
-
const readTracker = readTrackerRef.current;
|
|
1616
|
-
const [, bump] = useReducer((value) => value + 1, 0);
|
|
1617
|
-
readTracker.resetReads();
|
|
1618
|
-
const { props: renderedProps, sources } = substituteStates(props, (source) => readTracker.wrap(source));
|
|
1619
|
-
const uniqueHandles = uniqueHandlesOf(sources);
|
|
1620
|
-
useCommitEffect(() => {
|
|
1621
|
-
currentHandlesRef.current = uniqueHandles;
|
|
1622
|
-
readTracker.captureReads();
|
|
1623
|
-
});
|
|
1624
|
-
useEffect(() => {
|
|
1625
|
-
readTracker.retain();
|
|
1626
|
-
return () => readTracker.dispose();
|
|
1627
|
-
}, [readTracker]);
|
|
1628
|
-
useEffect(() => {
|
|
1629
|
-
let cancelled = false;
|
|
1630
|
-
const subscribedHandles = uniqueHandlesOf(sources);
|
|
1631
|
-
const unsubscribes = subscribedHandles.map(
|
|
1632
|
-
(handle) => subscribe(proxyOf(handle.root), () => {
|
|
1633
|
-
if (cancelled) return;
|
|
1634
|
-
const dirty = handle.lastDirty;
|
|
1635
|
-
if (dirty !== void 0 && readsIntersectDirty(readTracker, dirty)) bump();
|
|
1636
|
-
})
|
|
1637
|
-
);
|
|
1638
|
-
if (readsChanged(readTracker)) bump();
|
|
1639
|
-
return () => {
|
|
1640
|
-
cancelled = true;
|
|
1641
|
-
for (const unsubscribe of unsubscribes) unsubscribe();
|
|
1642
|
-
};
|
|
1643
|
-
}, [sourcesKey(sources), readTracker]);
|
|
1644
|
-
return createElement(Component, renderedProps);
|
|
1645
|
-
};
|
|
1646
|
-
const baseName = Component.displayName ?? Component.name;
|
|
1647
|
-
Scoped.displayName = `scope(${typeof baseName === "string" && baseName !== "" ? baseName : "Component"})`;
|
|
1648
|
-
return memo(Scoped, arePropsEqual);
|
|
1649
|
-
}
|
|
1650
|
-
var isObjectLike3 = (value) => value !== null && (typeof value === "object" || typeof value === "function");
|
|
1651
|
-
function useMutableState(properties, options) {
|
|
1652
|
-
const [{ writeProxy, readTracker }] = useState(() => {
|
|
1653
|
-
const initial = typeof properties === "function" ? properties() : properties;
|
|
1654
|
-
return {
|
|
1655
|
-
writeProxy: createMutableState(initial, options),
|
|
1656
|
-
readTracker: createReadTracker()
|
|
1657
|
-
};
|
|
1658
|
-
});
|
|
1659
|
-
const [, bump] = useReducer((value) => value + 1, 0);
|
|
1660
|
-
const currentHandlesRef = useRef([]);
|
|
1661
|
-
const uniqueHandles = isObjectLike3(writeProxy) ? handlesOf(writeProxy) : [];
|
|
1662
|
-
readTracker.resetReads();
|
|
1663
|
-
const readProxy = isObjectLike3(writeProxy) ? readTracker.wrap(writeProxy) : writeProxy;
|
|
1664
|
-
useCommitEffect(() => {
|
|
1665
|
-
currentHandlesRef.current = uniqueHandles;
|
|
1666
|
-
readTracker.captureReads();
|
|
1667
|
-
});
|
|
1668
|
-
useEffect(() => {
|
|
1669
|
-
readTracker.retain();
|
|
1670
|
-
return () => readTracker.dispose();
|
|
1671
|
-
}, [readTracker]);
|
|
1672
|
-
useEffect(() => {
|
|
1673
|
-
let cancelled = false;
|
|
1674
|
-
const subscribedHandles = isObjectLike3(writeProxy) ? handlesOf(writeProxy) : [];
|
|
1675
|
-
const unsubscribes = subscribedHandles.map(
|
|
1676
|
-
(handle) => subscribe(proxyOf(handle.root), () => {
|
|
1677
|
-
if (cancelled) return;
|
|
1678
|
-
const dirty = handle.lastDirty;
|
|
1679
|
-
if (dirty !== void 0 && readsIntersectDirty(readTracker, dirty)) bump();
|
|
1680
|
-
})
|
|
1681
|
-
);
|
|
1682
|
-
if (readsChanged(readTracker)) bump();
|
|
1683
|
-
return () => {
|
|
1684
|
-
cancelled = true;
|
|
1685
|
-
for (const unsubscribe of unsubscribes) unsubscribe();
|
|
1686
|
-
};
|
|
1687
|
-
}, [writeProxy, readTracker]);
|
|
1688
|
-
return readProxy;
|
|
440
|
+
function flush(state, ...states) {
|
|
441
|
+
for (const target of [state, ...states]) flushWindow(requireHandle(target, "opshot: flush requires a state"));
|
|
1689
442
|
}
|
|
1690
443
|
|
|
1691
|
-
export { TrackedDate, TrackedMap, TrackedSet,
|
|
444
|
+
export { TrackedDate, TrackedMap, TrackedSet, flush };
|