@expressive/mvc 0.52.2-alpha.74 → 0.53.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/dist/index.d.ts +35 -42
- package/dist/index.js +213 -215
- package/dist/index.mjs +213 -215
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -35,58 +35,78 @@ __export(src_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
37
|
// src/control.ts
|
|
38
|
-
var
|
|
39
|
-
var OBSERVER = /* @__PURE__ */ new WeakMap();
|
|
38
|
+
var onReady = () => null;
|
|
40
39
|
var LISTENERS = /* @__PURE__ */ new WeakMap();
|
|
41
40
|
var PENDING = /* @__PURE__ */ new WeakMap();
|
|
42
|
-
var
|
|
41
|
+
var PENDING_KEYS = /* @__PURE__ */ new WeakMap();
|
|
42
|
+
var DISPATCH = /* @__PURE__ */ new Set();
|
|
43
|
+
var OBSERVER = /* @__PURE__ */ new WeakMap();
|
|
43
44
|
function addListener(subject, callback, select) {
|
|
44
|
-
let
|
|
45
|
-
if (!
|
|
46
|
-
LISTENERS.set(subject,
|
|
45
|
+
let listeners = LISTENERS.get(subject);
|
|
46
|
+
if (!listeners)
|
|
47
|
+
LISTENERS.set(subject, listeners = /* @__PURE__ */ new Map([[onReady, void 0]]));
|
|
47
48
|
const filter = select === void 0 ? void 0 : /* @__PURE__ */ new Set([select]);
|
|
48
|
-
if (!
|
|
49
|
-
callback(true, subject);
|
|
50
|
-
|
|
51
|
-
return () =>
|
|
49
|
+
if (!listeners.has(onReady) && !filter)
|
|
50
|
+
callback.call(subject, true, subject);
|
|
51
|
+
listeners.set(callback, filter);
|
|
52
|
+
return () => listeners.delete(callback);
|
|
52
53
|
}
|
|
53
|
-
function
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
function watch(from, key2, value) {
|
|
59
|
-
const access = OBSERVER.get(from);
|
|
60
|
-
return access ? access(from, key2, value) : value;
|
|
61
|
-
}
|
|
62
|
-
function emit(source, key2) {
|
|
63
|
-
const subs = LISTENERS.get(source);
|
|
64
|
-
const ready = !subs.has(onReady);
|
|
65
|
-
if (key2 === true && ready)
|
|
54
|
+
function emit(model, key2) {
|
|
55
|
+
const listeners = LISTENERS.get(model);
|
|
56
|
+
const notReady = listeners.has(onReady);
|
|
57
|
+
if (key2 === true && !notReady)
|
|
66
58
|
return;
|
|
67
|
-
let
|
|
68
|
-
if (
|
|
69
|
-
|
|
59
|
+
let pending2 = PENDING.get(model);
|
|
60
|
+
if (pending2) {
|
|
61
|
+
pending2.add(key2);
|
|
70
62
|
return;
|
|
71
63
|
}
|
|
72
|
-
PENDING.set(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
queue(after);
|
|
64
|
+
PENDING.set(model, pending2 = new Set(notReady ? [true, key2] : [key2]));
|
|
65
|
+
for (const key3 of pending2)
|
|
66
|
+
for (const [callback, filter] of listeners)
|
|
67
|
+
if (!filter || filter.has(key3)) {
|
|
68
|
+
const after = callback.call(model, key3, model);
|
|
69
|
+
if (after)
|
|
70
|
+
enqueue(after);
|
|
71
|
+
else if (after === null)
|
|
72
|
+
listeners.delete(callback);
|
|
82
73
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
74
|
+
if (key2 === null)
|
|
75
|
+
listeners.clear();
|
|
76
|
+
PENDING.delete(model);
|
|
77
|
+
}
|
|
78
|
+
function event(subject, key2, silent) {
|
|
79
|
+
if (key2 === null)
|
|
80
|
+
return emit(subject, key2);
|
|
81
|
+
if (!key2)
|
|
82
|
+
return emit(subject, true);
|
|
83
|
+
let pending2 = PENDING_KEYS.get(subject);
|
|
84
|
+
if (!pending2) {
|
|
85
|
+
PENDING_KEYS.set(subject, pending2 = /* @__PURE__ */ new Set());
|
|
86
|
+
if (!silent)
|
|
87
|
+
enqueue(() => {
|
|
88
|
+
emit(subject, false);
|
|
89
|
+
PENDING_KEYS.delete(subject);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
pending2.add(key2);
|
|
93
|
+
if (!silent)
|
|
94
|
+
emit(subject, key2);
|
|
88
95
|
}
|
|
89
|
-
function
|
|
96
|
+
function pending(subject) {
|
|
97
|
+
if (PENDING_KEYS.has(subject))
|
|
98
|
+
return {
|
|
99
|
+
then: (res) => new Promise((res2) => {
|
|
100
|
+
const remove = addListener(subject, (key2) => {
|
|
101
|
+
if (key2 !== true) {
|
|
102
|
+
remove();
|
|
103
|
+
return res2.bind(null, Array.from(PENDING_KEYS.get(subject)));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}).then(res)
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function enqueue(eventHandler) {
|
|
90
110
|
if (!DISPATCH.size)
|
|
91
111
|
setTimeout(() => {
|
|
92
112
|
DISPATCH.forEach((event2) => {
|
|
@@ -100,6 +120,15 @@ function queue(eventHandler) {
|
|
|
100
120
|
}, 0);
|
|
101
121
|
DISPATCH.add(eventHandler);
|
|
102
122
|
}
|
|
123
|
+
function createProxy(from, observer) {
|
|
124
|
+
const proxy = Object.create(from);
|
|
125
|
+
OBSERVER.set(proxy, observer);
|
|
126
|
+
return proxy;
|
|
127
|
+
}
|
|
128
|
+
function watch(from, key2, value) {
|
|
129
|
+
const access = OBSERVER.get(from);
|
|
130
|
+
return access ? access(from, key2, value) : value;
|
|
131
|
+
}
|
|
103
132
|
function createEffect(target, callback, requireValues) {
|
|
104
133
|
const listeners = LISTENERS.get(target);
|
|
105
134
|
let unset;
|
|
@@ -166,7 +195,6 @@ var define = Object.defineProperty;
|
|
|
166
195
|
var ID = /* @__PURE__ */ new WeakMap();
|
|
167
196
|
var STATE = /* @__PURE__ */ new WeakMap();
|
|
168
197
|
var NOTIFY = /* @__PURE__ */ new WeakMap();
|
|
169
|
-
var PENDING2 = /* @__PURE__ */ new WeakMap();
|
|
170
198
|
var PARENT = /* @__PURE__ */ new WeakMap();
|
|
171
199
|
var METHODS = /* @__PURE__ */ new WeakMap();
|
|
172
200
|
var METHOD = /* @__PURE__ */ new WeakMap();
|
|
@@ -178,65 +206,44 @@ var Model = class {
|
|
|
178
206
|
}
|
|
179
207
|
get(arg1, arg2) {
|
|
180
208
|
const self = this.is;
|
|
181
|
-
if (arg1 === void 0)
|
|
182
|
-
return snapshot(self);
|
|
183
209
|
if (typeof arg1 == "function") {
|
|
184
|
-
let
|
|
185
|
-
return createEffect(self, (
|
|
186
|
-
const cb = arg1.call(
|
|
210
|
+
let pending2 = /* @__PURE__ */ new Set();
|
|
211
|
+
return createEffect(self, (proxy) => {
|
|
212
|
+
const cb = arg1.call(proxy, proxy, pending2);
|
|
187
213
|
return cb === null ? cb : (update2) => {
|
|
188
|
-
|
|
214
|
+
pending2 = PENDING_KEYS.get(self);
|
|
189
215
|
if (typeof cb == "function")
|
|
190
216
|
cb(update2);
|
|
191
217
|
};
|
|
192
218
|
});
|
|
193
219
|
}
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (arg1 in state)
|
|
199
|
-
arg2.call(this, state[arg1], arg1, this);
|
|
200
|
-
return addListener(self, () => {
|
|
201
|
-
arg2.call(this, arg1 in state ? state[arg1] : arg1, arg1, this);
|
|
202
|
-
}, arg1);
|
|
203
|
-
}
|
|
220
|
+
if (arg1 === void 0)
|
|
221
|
+
return snapshot(self);
|
|
222
|
+
if (typeof arg2 == "function")
|
|
223
|
+
return addListener(self, arg2, arg1);
|
|
204
224
|
return arg1 === null ? Object.isFrozen(STATE.get(self)) : fetch(self, arg1, arg2);
|
|
205
225
|
}
|
|
206
|
-
set(arg1, arg2
|
|
226
|
+
set(arg1, arg2) {
|
|
207
227
|
const self = this.is;
|
|
208
228
|
if (typeof arg1 == "function")
|
|
209
229
|
return addListener(self, (key2) => {
|
|
210
230
|
if (typeof key2 == "string")
|
|
211
231
|
return arg1.call(self, key2, self);
|
|
212
232
|
});
|
|
213
|
-
if (arg1
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
else if (1 in arguments)
|
|
222
|
-
update(self, arg1, arg2, arg3);
|
|
223
|
-
else
|
|
233
|
+
if (arg1 && typeof arg1 == "object") {
|
|
234
|
+
const methods = METHODS.get(self.constructor);
|
|
235
|
+
for (const key2 in arg1)
|
|
236
|
+
if (methods.has(key2))
|
|
237
|
+
self[key2] = arg1[key2];
|
|
238
|
+
else if (key2 in self)
|
|
239
|
+
update(self, key2, arg1[key2], arg2 === true);
|
|
240
|
+
} else
|
|
224
241
|
event(self, arg1);
|
|
225
|
-
|
|
226
|
-
return {
|
|
227
|
-
then: (res) => new Promise((res2) => {
|
|
228
|
-
const remove = addListener(self, (key2) => {
|
|
229
|
-
if (key2 !== true) {
|
|
230
|
-
remove();
|
|
231
|
-
return res2.bind(null, Array.from(PENDING2.get(self)));
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
}).then(res)
|
|
235
|
-
};
|
|
242
|
+
return pending(self);
|
|
236
243
|
}
|
|
237
244
|
/**
|
|
238
245
|
* Iterate over managed properties in this instance of Model.
|
|
239
|
-
* Yeilds the key and
|
|
246
|
+
* Yeilds the key and current value for each property.
|
|
240
247
|
*/
|
|
241
248
|
[Symbol.iterator]() {
|
|
242
249
|
return Object.entries(STATE.get(this.is))[Symbol.iterator]();
|
|
@@ -250,7 +257,7 @@ var Model = class {
|
|
|
250
257
|
*/
|
|
251
258
|
static new(...args) {
|
|
252
259
|
const instance = new this(...args);
|
|
253
|
-
|
|
260
|
+
event(instance);
|
|
254
261
|
return instance;
|
|
255
262
|
}
|
|
256
263
|
/**
|
|
@@ -308,25 +315,23 @@ function prepare(model) {
|
|
|
308
315
|
for (const [key2, { value }] of Object.entries(
|
|
309
316
|
Object.getOwnPropertyDescriptors(type.prototype)
|
|
310
317
|
)) {
|
|
311
|
-
let
|
|
312
|
-
|
|
313
|
-
}, set3 = function(method) {
|
|
314
|
-
const value2 = method.bind(this.is);
|
|
318
|
+
let bind2 = function(method = value) {
|
|
319
|
+
const value2 = method.bind(model);
|
|
315
320
|
METHOD.set(value2, method);
|
|
316
|
-
define(
|
|
321
|
+
define(model, key2, { value: value2, writable: true });
|
|
317
322
|
return value2;
|
|
318
323
|
};
|
|
319
|
-
var
|
|
324
|
+
var bind = bind2;
|
|
320
325
|
if (!value || key2 == "constructor")
|
|
321
326
|
continue;
|
|
322
327
|
keys2.add(key2);
|
|
323
|
-
define(type.prototype, key2, { get:
|
|
328
|
+
define(type.prototype, key2, { get: bind2, set: bind2 });
|
|
324
329
|
}
|
|
325
330
|
}
|
|
326
331
|
}
|
|
327
332
|
function init(model, args) {
|
|
333
|
+
const methods = METHODS.get(model.constructor);
|
|
328
334
|
const state = {};
|
|
329
|
-
const clean = /* @__PURE__ */ new Set();
|
|
330
335
|
STATE.set(model, state);
|
|
331
336
|
args = args.flat().filter((arg) => {
|
|
332
337
|
if (typeof arg != "string")
|
|
@@ -343,10 +348,13 @@ function init(model, args) {
|
|
|
343
348
|
console.error(`Async error in constructor for ${model}:`);
|
|
344
349
|
console.error(err);
|
|
345
350
|
});
|
|
346
|
-
else if (typeof use2 == "object")
|
|
347
|
-
assign(model, use2);
|
|
348
351
|
else if (typeof use2 == "function")
|
|
349
|
-
|
|
352
|
+
addListener(model, use2, null);
|
|
353
|
+
else if (typeof use2 == "object") {
|
|
354
|
+
for (const key2 in use2)
|
|
355
|
+
if (key2 in model || methods.has(key2))
|
|
356
|
+
model[key2] = use2[key2];
|
|
357
|
+
}
|
|
350
358
|
});
|
|
351
359
|
for (const key2 in model) {
|
|
352
360
|
const desc = Object.getOwnPropertyDescriptor(model, key2);
|
|
@@ -354,22 +362,30 @@ function init(model, args) {
|
|
|
354
362
|
update(model, key2, desc.value, true);
|
|
355
363
|
define(model, key2, {
|
|
356
364
|
configurable: false,
|
|
357
|
-
set: (x) => update(model, key2, x),
|
|
358
365
|
get() {
|
|
359
366
|
return watch(this, key2, state[key2]);
|
|
367
|
+
},
|
|
368
|
+
set(value) {
|
|
369
|
+
update(model, key2, value);
|
|
370
|
+
mayAdopt(model, value);
|
|
360
371
|
}
|
|
361
372
|
});
|
|
362
373
|
}
|
|
363
374
|
}
|
|
375
|
+
addListener(model, () => {
|
|
376
|
+
for (const [_, value] of model)
|
|
377
|
+
if (value instanceof Model && PARENT.get(value) === model)
|
|
378
|
+
value.set(null);
|
|
379
|
+
Object.freeze(state);
|
|
380
|
+
}, null);
|
|
364
381
|
return null;
|
|
365
382
|
});
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}, null);
|
|
383
|
+
}
|
|
384
|
+
function mayAdopt(parent, child) {
|
|
385
|
+
if (child instanceof Model && !PARENT.has(child)) {
|
|
386
|
+
PARENT.set(child, parent);
|
|
387
|
+
event(child);
|
|
388
|
+
}
|
|
373
389
|
}
|
|
374
390
|
function fetch(subject, property, required) {
|
|
375
391
|
const state = STATE.get(subject);
|
|
@@ -428,37 +444,14 @@ function update(subject, key2, value, arg) {
|
|
|
428
444
|
value = out();
|
|
429
445
|
}
|
|
430
446
|
if (value === previous)
|
|
431
|
-
return
|
|
432
|
-
if (value instanceof Model && !PARENT.has(value)) {
|
|
433
|
-
PARENT.set(value, subject);
|
|
434
|
-
emit(value, true);
|
|
435
|
-
}
|
|
447
|
+
return;
|
|
436
448
|
state[key2] = value;
|
|
437
449
|
if (arg !== true)
|
|
438
450
|
event(subject, key2);
|
|
439
|
-
|
|
440
|
-
function event(subject, key2, silent) {
|
|
441
|
-
let pending = PENDING2.get(subject);
|
|
442
|
-
if (!pending) {
|
|
443
|
-
PENDING2.set(subject, pending = /* @__PURE__ */ new Set());
|
|
444
|
-
if (!silent)
|
|
445
|
-
queue(() => {
|
|
446
|
-
emit(subject, false);
|
|
447
|
-
PENDING2.delete(subject);
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
pending.add(key2);
|
|
451
|
-
if (!silent)
|
|
452
|
-
emit(subject, key2);
|
|
453
|
-
}
|
|
454
|
-
function assign(to, values) {
|
|
455
|
-
const methods = METHODS.get(to.constructor);
|
|
456
|
-
for (const key2 in values)
|
|
457
|
-
if (key2 in to || methods.has(key2))
|
|
458
|
-
to[key2] = values[key2];
|
|
451
|
+
return true;
|
|
459
452
|
}
|
|
460
453
|
function uid() {
|
|
461
|
-
return (Math.random() * 0.722
|
|
454
|
+
return (0.278 + Math.random() * 0.722).toString(36).substring(2, 8).toUpperCase();
|
|
462
455
|
}
|
|
463
456
|
|
|
464
457
|
// src/context.ts
|
|
@@ -551,11 +544,11 @@ var Context = class _Context {
|
|
|
551
544
|
}
|
|
552
545
|
}
|
|
553
546
|
for (const [model, explicit] of init2) {
|
|
554
|
-
|
|
547
|
+
model.set();
|
|
555
548
|
if (typeof forEach == "function")
|
|
556
549
|
forEach(model, explicit);
|
|
557
550
|
else if (forEach && explicit)
|
|
558
|
-
|
|
551
|
+
model.set(forEach);
|
|
559
552
|
for (const [_key, value] of model)
|
|
560
553
|
if (PARENT.get(value) === model) {
|
|
561
554
|
this.add(value, true);
|
|
@@ -572,8 +565,8 @@ var Context = class _Context {
|
|
|
572
565
|
I = new input();
|
|
573
566
|
this.cleanup.add(() => I.set(null));
|
|
574
567
|
} else {
|
|
568
|
+
T = input.constructor;
|
|
575
569
|
I = input;
|
|
576
|
-
T = I.constructor;
|
|
577
570
|
}
|
|
578
571
|
keys(T, true).forEach((K) => {
|
|
579
572
|
const result = this[K];
|
|
@@ -630,8 +623,7 @@ Model.on((_, model) => {
|
|
|
630
623
|
const { value } = Object.getOwnPropertyDescriptor(model, key2);
|
|
631
624
|
const instruction = INSTRUCT.get(value);
|
|
632
625
|
if (!instruction) {
|
|
633
|
-
|
|
634
|
-
update(model, key2, value);
|
|
626
|
+
mayAdopt(model, value);
|
|
635
627
|
continue;
|
|
636
628
|
}
|
|
637
629
|
INSTRUCT.delete(value);
|
|
@@ -665,76 +657,80 @@ Model.on((_, model) => {
|
|
|
665
657
|
var STALE = /* @__PURE__ */ new WeakSet();
|
|
666
658
|
function get(arg0, arg1) {
|
|
667
659
|
return use((key2, subject, state) => {
|
|
668
|
-
let from = subject;
|
|
669
660
|
if (typeof arg0 == "symbol")
|
|
670
|
-
throw new Error(`Attempted to use an instruction result (probably use or get) as computed source for ${
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
661
|
+
throw new Error(`Attempted to use an instruction result (probably use or get) as computed source for ${subject}.${key2}. This is not allowed.`);
|
|
662
|
+
if (Model.is(arg0)) {
|
|
663
|
+
let assign2 = function(value) {
|
|
664
|
+
if (typeof arg1 == "function")
|
|
665
|
+
value.get((x) => arg1(x, key2));
|
|
666
|
+
update(subject, key2, value);
|
|
667
|
+
};
|
|
668
|
+
var assign = assign2;
|
|
669
|
+
const hasParent = PARENT.get(subject);
|
|
676
670
|
if (!hasParent) {
|
|
677
671
|
if (arg1 === true)
|
|
678
|
-
throw new Error(`${
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
});
|
|
687
|
-
};
|
|
672
|
+
throw new Error(`${subject} may only exist as a child of type ${arg0}.`);
|
|
673
|
+
Context.get(subject, (context) => {
|
|
674
|
+
const model = context.get(arg0);
|
|
675
|
+
if (model)
|
|
676
|
+
assign2(model);
|
|
677
|
+
else if (arg1 !== false)
|
|
678
|
+
throw new Error(`Required ${arg0} not found in context for ${subject}.`);
|
|
679
|
+
});
|
|
688
680
|
} else if (!arg0 || hasParent instanceof arg0)
|
|
689
|
-
|
|
681
|
+
assign2(hasParent);
|
|
690
682
|
else
|
|
691
|
-
throw new Error(`New ${
|
|
683
|
+
throw new Error(`New ${subject} created as child of ${hasParent}, but must be instanceof ${arg0}.`);
|
|
684
|
+
return {
|
|
685
|
+
get: arg1 !== false
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
let from = subject;
|
|
689
|
+
if (arg0 instanceof Model) {
|
|
690
|
+
from = arg0;
|
|
692
691
|
} else {
|
|
693
692
|
const fn = METHOD.get(arg0) || arg0;
|
|
694
693
|
arg1 = (p, k) => fn.call(p, k, p);
|
|
695
694
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
} else
|
|
736
|
-
source((got) => subject.set(key2, got));
|
|
737
|
-
return { get: arg1 };
|
|
695
|
+
const source = (resolve) => resolve(from);
|
|
696
|
+
const getter = arg1;
|
|
697
|
+
let reset;
|
|
698
|
+
let isAsync;
|
|
699
|
+
let proxy;
|
|
700
|
+
function connect(model) {
|
|
701
|
+
reset = createEffect(model, (current) => {
|
|
702
|
+
proxy = current;
|
|
703
|
+
if (!(key2 in state) || STALE.delete(compute))
|
|
704
|
+
compute(!reset);
|
|
705
|
+
return (didUpdate) => {
|
|
706
|
+
if (didUpdate) {
|
|
707
|
+
STALE.add(compute);
|
|
708
|
+
event(subject, key2, true);
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
function compute(initial) {
|
|
714
|
+
let next;
|
|
715
|
+
try {
|
|
716
|
+
next = getter.call(proxy, proxy, key2);
|
|
717
|
+
} catch (err) {
|
|
718
|
+
console.warn(`An exception was thrown while ${initial ? "initializing" : "refreshing"} ${subject}.${key2}.`);
|
|
719
|
+
if (initial)
|
|
720
|
+
throw err;
|
|
721
|
+
console.error(err);
|
|
722
|
+
}
|
|
723
|
+
update(subject, key2, next, !isAsync);
|
|
724
|
+
}
|
|
725
|
+
return () => {
|
|
726
|
+
if (!proxy) {
|
|
727
|
+
source(connect);
|
|
728
|
+
isAsync = true;
|
|
729
|
+
}
|
|
730
|
+
if (STALE.delete(compute))
|
|
731
|
+
compute();
|
|
732
|
+
return fetch(subject, key2, !proxy);
|
|
733
|
+
};
|
|
738
734
|
});
|
|
739
735
|
}
|
|
740
736
|
|
|
@@ -756,7 +752,9 @@ function ref(arg, arg2) {
|
|
|
756
752
|
});
|
|
757
753
|
else {
|
|
758
754
|
const get2 = () => state[key3];
|
|
759
|
-
const set2 = (value2) =>
|
|
755
|
+
const set2 = (value2) => {
|
|
756
|
+
update(subject, key3, value2);
|
|
757
|
+
};
|
|
760
758
|
define(set2, "current", { get: get2, set: set2 });
|
|
761
759
|
define(set2, "get", { value: get2 });
|
|
762
760
|
define(value, key3, { value: set2 });
|
|
@@ -768,7 +766,7 @@ function ref(arg, arg2) {
|
|
|
768
766
|
let unSet;
|
|
769
767
|
const get2 = () => state[key2];
|
|
770
768
|
const set2 = (value2) => {
|
|
771
|
-
if (!subject
|
|
769
|
+
if (!update(subject, key2, value2) || !arg)
|
|
772
770
|
return;
|
|
773
771
|
if (unSet)
|
|
774
772
|
unSet = void unSet(value2);
|
|
@@ -804,16 +802,16 @@ function set(value, argument) {
|
|
|
804
802
|
output.get = argument === true;
|
|
805
803
|
if (value instanceof Promise) {
|
|
806
804
|
value.then((value2) => {
|
|
807
|
-
subject
|
|
805
|
+
update(subject, key2, value2);
|
|
808
806
|
return value2;
|
|
809
807
|
}).catch((err) => {
|
|
810
|
-
subject
|
|
808
|
+
event(subject, key2);
|
|
811
809
|
output.get = () => {
|
|
812
810
|
throw err;
|
|
813
811
|
};
|
|
814
812
|
});
|
|
815
813
|
} else
|
|
816
|
-
subject
|
|
814
|
+
update(subject, key2, value);
|
|
817
815
|
if (0 in arguments)
|
|
818
816
|
return subject[key2];
|
|
819
817
|
};
|
|
@@ -838,7 +836,7 @@ function set(value, argument) {
|
|
|
838
836
|
} else
|
|
839
837
|
output.set = (value2) => {
|
|
840
838
|
output.get = void 0;
|
|
841
|
-
subject
|
|
839
|
+
update(subject, key2, value2);
|
|
842
840
|
};
|
|
843
841
|
return output;
|
|
844
842
|
});
|
|
@@ -866,17 +864,17 @@ var APPLY = /* @__PURE__ */ new WeakMap();
|
|
|
866
864
|
function has(arg1, arg2) {
|
|
867
865
|
return use((key2, subject) => {
|
|
868
866
|
const applied = /* @__PURE__ */ new Set();
|
|
869
|
-
const
|
|
870
|
-
subject
|
|
867
|
+
const apply = () => {
|
|
868
|
+
update(subject, key2, Object.freeze(Array.from(applied)));
|
|
871
869
|
};
|
|
872
870
|
if (Model.is(arg1))
|
|
873
871
|
Context.get(subject, (context) => {
|
|
874
|
-
context.has(arg1, (
|
|
872
|
+
context.has(arg1, (model) => {
|
|
875
873
|
let remove;
|
|
876
874
|
let disconnect;
|
|
877
|
-
if (applied.has(
|
|
875
|
+
if (applied.has(model))
|
|
878
876
|
return;
|
|
879
|
-
const callback = APPLY.get(
|
|
877
|
+
const callback = APPLY.get(model);
|
|
880
878
|
if (callback) {
|
|
881
879
|
const after = callback(subject);
|
|
882
880
|
if (after === false)
|
|
@@ -885,7 +883,7 @@ function has(arg1, arg2) {
|
|
|
885
883
|
disconnect = after;
|
|
886
884
|
}
|
|
887
885
|
if (typeof arg2 == "function") {
|
|
888
|
-
const done2 = arg2(
|
|
886
|
+
const done2 = arg2(model, subject);
|
|
889
887
|
if (done2 === false)
|
|
890
888
|
return false;
|
|
891
889
|
remove = () => {
|
|
@@ -893,18 +891,18 @@ function has(arg1, arg2) {
|
|
|
893
891
|
done2();
|
|
894
892
|
};
|
|
895
893
|
}
|
|
896
|
-
applied.add(
|
|
897
|
-
|
|
894
|
+
applied.add(model);
|
|
895
|
+
apply();
|
|
898
896
|
const done = () => {
|
|
899
|
-
|
|
900
|
-
applied.delete(
|
|
901
|
-
|
|
897
|
+
ignore();
|
|
898
|
+
applied.delete(model);
|
|
899
|
+
apply();
|
|
902
900
|
if (disconnect)
|
|
903
901
|
disconnect();
|
|
904
902
|
if (typeof remove == "function")
|
|
905
903
|
remove();
|
|
906
904
|
};
|
|
907
|
-
const
|
|
905
|
+
const ignore = model.get(null, done);
|
|
908
906
|
return done;
|
|
909
907
|
});
|
|
910
908
|
});
|
|
@@ -919,10 +917,10 @@ function has(arg1, arg2) {
|
|
|
919
917
|
return false;
|
|
920
918
|
}
|
|
921
919
|
applied.add(recipient);
|
|
922
|
-
|
|
920
|
+
apply();
|
|
923
921
|
return () => {
|
|
924
922
|
applied.delete(recipient);
|
|
925
|
-
|
|
923
|
+
apply();
|
|
926
924
|
if (typeof remove == "function")
|
|
927
925
|
remove();
|
|
928
926
|
};
|