@expressive/mvc 0.52.2-alpha.74 → 0.53.2
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.mjs
CHANGED
|
@@ -1,56 +1,76 @@
|
|
|
1
1
|
// src/control.ts
|
|
2
|
-
var
|
|
3
|
-
var OBSERVER = /* @__PURE__ */ new WeakMap();
|
|
2
|
+
var onReady = () => null;
|
|
4
3
|
var LISTENERS = /* @__PURE__ */ new WeakMap();
|
|
5
4
|
var PENDING = /* @__PURE__ */ new WeakMap();
|
|
6
|
-
var
|
|
5
|
+
var PENDING_KEYS = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
var DISPATCH = /* @__PURE__ */ new Set();
|
|
7
|
+
var OBSERVER = /* @__PURE__ */ new WeakMap();
|
|
7
8
|
function addListener(subject, callback, select) {
|
|
8
|
-
let
|
|
9
|
-
if (!
|
|
10
|
-
LISTENERS.set(subject,
|
|
9
|
+
let listeners = LISTENERS.get(subject);
|
|
10
|
+
if (!listeners)
|
|
11
|
+
LISTENERS.set(subject, listeners = /* @__PURE__ */ new Map([[onReady, void 0]]));
|
|
11
12
|
const filter = select === void 0 ? void 0 : /* @__PURE__ */ new Set([select]);
|
|
12
|
-
if (!
|
|
13
|
-
callback(true, subject);
|
|
14
|
-
|
|
15
|
-
return () =>
|
|
13
|
+
if (!listeners.has(onReady) && !filter)
|
|
14
|
+
callback.call(subject, true, subject);
|
|
15
|
+
listeners.set(callback, filter);
|
|
16
|
+
return () => listeners.delete(callback);
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
function watch(from, key2, value) {
|
|
23
|
-
const access = OBSERVER.get(from);
|
|
24
|
-
return access ? access(from, key2, value) : value;
|
|
25
|
-
}
|
|
26
|
-
function emit(source, key2) {
|
|
27
|
-
const subs = LISTENERS.get(source);
|
|
28
|
-
const ready = !subs.has(onReady);
|
|
29
|
-
if (key2 === true && ready)
|
|
18
|
+
function emit(model, key2) {
|
|
19
|
+
const listeners = LISTENERS.get(model);
|
|
20
|
+
const notReady = listeners.has(onReady);
|
|
21
|
+
if (key2 === true && !notReady)
|
|
30
22
|
return;
|
|
31
|
-
let
|
|
32
|
-
if (
|
|
33
|
-
|
|
23
|
+
let pending2 = PENDING.get(model);
|
|
24
|
+
if (pending2) {
|
|
25
|
+
pending2.add(key2);
|
|
34
26
|
return;
|
|
35
27
|
}
|
|
36
|
-
PENDING.set(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
queue(after);
|
|
28
|
+
PENDING.set(model, pending2 = new Set(notReady ? [true, key2] : [key2]));
|
|
29
|
+
for (const key3 of pending2)
|
|
30
|
+
for (const [callback, filter] of listeners)
|
|
31
|
+
if (!filter || filter.has(key3)) {
|
|
32
|
+
const after = callback.call(model, key3, model);
|
|
33
|
+
if (after)
|
|
34
|
+
enqueue(after);
|
|
35
|
+
else if (after === null)
|
|
36
|
+
listeners.delete(callback);
|
|
46
37
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
if (key2 === null)
|
|
39
|
+
listeners.clear();
|
|
40
|
+
PENDING.delete(model);
|
|
41
|
+
}
|
|
42
|
+
function event(subject, key2, silent) {
|
|
43
|
+
if (key2 === null)
|
|
44
|
+
return emit(subject, key2);
|
|
45
|
+
if (!key2)
|
|
46
|
+
return emit(subject, true);
|
|
47
|
+
let pending2 = PENDING_KEYS.get(subject);
|
|
48
|
+
if (!pending2) {
|
|
49
|
+
PENDING_KEYS.set(subject, pending2 = /* @__PURE__ */ new Set());
|
|
50
|
+
if (!silent)
|
|
51
|
+
enqueue(() => {
|
|
52
|
+
emit(subject, false);
|
|
53
|
+
PENDING_KEYS.delete(subject);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
pending2.add(key2);
|
|
57
|
+
if (!silent)
|
|
58
|
+
emit(subject, key2);
|
|
52
59
|
}
|
|
53
|
-
function
|
|
60
|
+
function pending(subject) {
|
|
61
|
+
if (PENDING_KEYS.has(subject))
|
|
62
|
+
return {
|
|
63
|
+
then: (res) => new Promise((res2) => {
|
|
64
|
+
const remove = addListener(subject, (key2) => {
|
|
65
|
+
if (key2 !== true) {
|
|
66
|
+
remove();
|
|
67
|
+
return res2.bind(null, Array.from(PENDING_KEYS.get(subject)));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}).then(res)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function enqueue(eventHandler) {
|
|
54
74
|
if (!DISPATCH.size)
|
|
55
75
|
setTimeout(() => {
|
|
56
76
|
DISPATCH.forEach((event2) => {
|
|
@@ -64,6 +84,15 @@ function queue(eventHandler) {
|
|
|
64
84
|
}, 0);
|
|
65
85
|
DISPATCH.add(eventHandler);
|
|
66
86
|
}
|
|
87
|
+
function createProxy(from, observer) {
|
|
88
|
+
const proxy = Object.create(from);
|
|
89
|
+
OBSERVER.set(proxy, observer);
|
|
90
|
+
return proxy;
|
|
91
|
+
}
|
|
92
|
+
function watch(from, key2, value) {
|
|
93
|
+
const access = OBSERVER.get(from);
|
|
94
|
+
return access ? access(from, key2, value) : value;
|
|
95
|
+
}
|
|
67
96
|
function createEffect(target, callback, requireValues) {
|
|
68
97
|
const listeners = LISTENERS.get(target);
|
|
69
98
|
let unset;
|
|
@@ -130,7 +159,6 @@ var define = Object.defineProperty;
|
|
|
130
159
|
var ID = /* @__PURE__ */ new WeakMap();
|
|
131
160
|
var STATE = /* @__PURE__ */ new WeakMap();
|
|
132
161
|
var NOTIFY = /* @__PURE__ */ new WeakMap();
|
|
133
|
-
var PENDING2 = /* @__PURE__ */ new WeakMap();
|
|
134
162
|
var PARENT = /* @__PURE__ */ new WeakMap();
|
|
135
163
|
var METHODS = /* @__PURE__ */ new WeakMap();
|
|
136
164
|
var METHOD = /* @__PURE__ */ new WeakMap();
|
|
@@ -142,65 +170,44 @@ var Model = class {
|
|
|
142
170
|
}
|
|
143
171
|
get(arg1, arg2) {
|
|
144
172
|
const self = this.is;
|
|
145
|
-
if (arg1 === void 0)
|
|
146
|
-
return snapshot(self);
|
|
147
173
|
if (typeof arg1 == "function") {
|
|
148
|
-
let
|
|
149
|
-
return createEffect(self, (
|
|
150
|
-
const cb = arg1.call(
|
|
174
|
+
let pending2 = /* @__PURE__ */ new Set();
|
|
175
|
+
return createEffect(self, (proxy) => {
|
|
176
|
+
const cb = arg1.call(proxy, proxy, pending2);
|
|
151
177
|
return cb === null ? cb : (update2) => {
|
|
152
|
-
|
|
178
|
+
pending2 = PENDING_KEYS.get(self);
|
|
153
179
|
if (typeof cb == "function")
|
|
154
180
|
cb(update2);
|
|
155
181
|
};
|
|
156
182
|
});
|
|
157
183
|
}
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (arg1 in state)
|
|
163
|
-
arg2.call(this, state[arg1], arg1, this);
|
|
164
|
-
return addListener(self, () => {
|
|
165
|
-
arg2.call(this, arg1 in state ? state[arg1] : arg1, arg1, this);
|
|
166
|
-
}, arg1);
|
|
167
|
-
}
|
|
184
|
+
if (arg1 === void 0)
|
|
185
|
+
return snapshot(self);
|
|
186
|
+
if (typeof arg2 == "function")
|
|
187
|
+
return addListener(self, arg2, arg1);
|
|
168
188
|
return arg1 === null ? Object.isFrozen(STATE.get(self)) : fetch(self, arg1, arg2);
|
|
169
189
|
}
|
|
170
|
-
set(arg1, arg2
|
|
190
|
+
set(arg1, arg2) {
|
|
171
191
|
const self = this.is;
|
|
172
192
|
if (typeof arg1 == "function")
|
|
173
193
|
return addListener(self, (key2) => {
|
|
174
194
|
if (typeof key2 == "string")
|
|
175
195
|
return arg1.call(self, key2, self);
|
|
176
196
|
});
|
|
177
|
-
if (arg1
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
else if (1 in arguments)
|
|
186
|
-
update(self, arg1, arg2, arg3);
|
|
187
|
-
else
|
|
197
|
+
if (arg1 && typeof arg1 == "object") {
|
|
198
|
+
const methods = METHODS.get(self.constructor);
|
|
199
|
+
for (const key2 in arg1)
|
|
200
|
+
if (methods.has(key2))
|
|
201
|
+
self[key2] = arg1[key2];
|
|
202
|
+
else if (key2 in self)
|
|
203
|
+
update(self, key2, arg1[key2], arg2 === true);
|
|
204
|
+
} else
|
|
188
205
|
event(self, arg1);
|
|
189
|
-
|
|
190
|
-
return {
|
|
191
|
-
then: (res) => new Promise((res2) => {
|
|
192
|
-
const remove = addListener(self, (key2) => {
|
|
193
|
-
if (key2 !== true) {
|
|
194
|
-
remove();
|
|
195
|
-
return res2.bind(null, Array.from(PENDING2.get(self)));
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}).then(res)
|
|
199
|
-
};
|
|
206
|
+
return pending(self);
|
|
200
207
|
}
|
|
201
208
|
/**
|
|
202
209
|
* Iterate over managed properties in this instance of Model.
|
|
203
|
-
* Yeilds the key and
|
|
210
|
+
* Yeilds the key and current value for each property.
|
|
204
211
|
*/
|
|
205
212
|
[Symbol.iterator]() {
|
|
206
213
|
return Object.entries(STATE.get(this.is))[Symbol.iterator]();
|
|
@@ -214,7 +221,7 @@ var Model = class {
|
|
|
214
221
|
*/
|
|
215
222
|
static new(...args) {
|
|
216
223
|
const instance = new this(...args);
|
|
217
|
-
|
|
224
|
+
event(instance);
|
|
218
225
|
return instance;
|
|
219
226
|
}
|
|
220
227
|
/**
|
|
@@ -272,25 +279,23 @@ function prepare(model) {
|
|
|
272
279
|
for (const [key2, { value }] of Object.entries(
|
|
273
280
|
Object.getOwnPropertyDescriptors(type.prototype)
|
|
274
281
|
)) {
|
|
275
|
-
let
|
|
276
|
-
|
|
277
|
-
}, set3 = function(method) {
|
|
278
|
-
const value2 = method.bind(this.is);
|
|
282
|
+
let bind2 = function(method = value) {
|
|
283
|
+
const value2 = method.bind(model);
|
|
279
284
|
METHOD.set(value2, method);
|
|
280
|
-
define(
|
|
285
|
+
define(model, key2, { value: value2, writable: true });
|
|
281
286
|
return value2;
|
|
282
287
|
};
|
|
283
|
-
var
|
|
288
|
+
var bind = bind2;
|
|
284
289
|
if (!value || key2 == "constructor")
|
|
285
290
|
continue;
|
|
286
291
|
keys2.add(key2);
|
|
287
|
-
define(type.prototype, key2, { get:
|
|
292
|
+
define(type.prototype, key2, { get: bind2, set: bind2 });
|
|
288
293
|
}
|
|
289
294
|
}
|
|
290
295
|
}
|
|
291
296
|
function init(model, args) {
|
|
297
|
+
const methods = METHODS.get(model.constructor);
|
|
292
298
|
const state = {};
|
|
293
|
-
const clean = /* @__PURE__ */ new Set();
|
|
294
299
|
STATE.set(model, state);
|
|
295
300
|
args = args.flat().filter((arg) => {
|
|
296
301
|
if (typeof arg != "string")
|
|
@@ -307,10 +312,13 @@ function init(model, args) {
|
|
|
307
312
|
console.error(`Async error in constructor for ${model}:`);
|
|
308
313
|
console.error(err);
|
|
309
314
|
});
|
|
310
|
-
else if (typeof use2 == "object")
|
|
311
|
-
assign(model, use2);
|
|
312
315
|
else if (typeof use2 == "function")
|
|
313
|
-
|
|
316
|
+
addListener(model, use2, null);
|
|
317
|
+
else if (typeof use2 == "object") {
|
|
318
|
+
for (const key2 in use2)
|
|
319
|
+
if (key2 in model || methods.has(key2))
|
|
320
|
+
model[key2] = use2[key2];
|
|
321
|
+
}
|
|
314
322
|
});
|
|
315
323
|
for (const key2 in model) {
|
|
316
324
|
const desc = Object.getOwnPropertyDescriptor(model, key2);
|
|
@@ -318,22 +326,30 @@ function init(model, args) {
|
|
|
318
326
|
update(model, key2, desc.value, true);
|
|
319
327
|
define(model, key2, {
|
|
320
328
|
configurable: false,
|
|
321
|
-
set: (x) => update(model, key2, x),
|
|
322
329
|
get() {
|
|
323
330
|
return watch(this, key2, state[key2]);
|
|
331
|
+
},
|
|
332
|
+
set(value) {
|
|
333
|
+
update(model, key2, value);
|
|
334
|
+
mayAdopt(model, value);
|
|
324
335
|
}
|
|
325
336
|
});
|
|
326
337
|
}
|
|
327
338
|
}
|
|
339
|
+
addListener(model, () => {
|
|
340
|
+
for (const [_, value] of model)
|
|
341
|
+
if (value instanceof Model && PARENT.get(value) === model)
|
|
342
|
+
value.set(null);
|
|
343
|
+
Object.freeze(state);
|
|
344
|
+
}, null);
|
|
328
345
|
return null;
|
|
329
346
|
});
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}, null);
|
|
347
|
+
}
|
|
348
|
+
function mayAdopt(parent, child) {
|
|
349
|
+
if (child instanceof Model && !PARENT.has(child)) {
|
|
350
|
+
PARENT.set(child, parent);
|
|
351
|
+
event(child);
|
|
352
|
+
}
|
|
337
353
|
}
|
|
338
354
|
function fetch(subject, property, required) {
|
|
339
355
|
const state = STATE.get(subject);
|
|
@@ -392,37 +408,14 @@ function update(subject, key2, value, arg) {
|
|
|
392
408
|
value = out();
|
|
393
409
|
}
|
|
394
410
|
if (value === previous)
|
|
395
|
-
return
|
|
396
|
-
if (value instanceof Model && !PARENT.has(value)) {
|
|
397
|
-
PARENT.set(value, subject);
|
|
398
|
-
emit(value, true);
|
|
399
|
-
}
|
|
411
|
+
return;
|
|
400
412
|
state[key2] = value;
|
|
401
413
|
if (arg !== true)
|
|
402
414
|
event(subject, key2);
|
|
403
|
-
|
|
404
|
-
function event(subject, key2, silent) {
|
|
405
|
-
let pending = PENDING2.get(subject);
|
|
406
|
-
if (!pending) {
|
|
407
|
-
PENDING2.set(subject, pending = /* @__PURE__ */ new Set());
|
|
408
|
-
if (!silent)
|
|
409
|
-
queue(() => {
|
|
410
|
-
emit(subject, false);
|
|
411
|
-
PENDING2.delete(subject);
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
pending.add(key2);
|
|
415
|
-
if (!silent)
|
|
416
|
-
emit(subject, key2);
|
|
417
|
-
}
|
|
418
|
-
function assign(to, values) {
|
|
419
|
-
const methods = METHODS.get(to.constructor);
|
|
420
|
-
for (const key2 in values)
|
|
421
|
-
if (key2 in to || methods.has(key2))
|
|
422
|
-
to[key2] = values[key2];
|
|
415
|
+
return true;
|
|
423
416
|
}
|
|
424
417
|
function uid() {
|
|
425
|
-
return (Math.random() * 0.722
|
|
418
|
+
return (0.278 + Math.random() * 0.722).toString(36).substring(2, 8).toUpperCase();
|
|
426
419
|
}
|
|
427
420
|
|
|
428
421
|
// src/context.ts
|
|
@@ -515,11 +508,11 @@ var Context = class _Context {
|
|
|
515
508
|
}
|
|
516
509
|
}
|
|
517
510
|
for (const [model, explicit] of init2) {
|
|
518
|
-
|
|
511
|
+
model.set();
|
|
519
512
|
if (typeof forEach == "function")
|
|
520
513
|
forEach(model, explicit);
|
|
521
514
|
else if (forEach && explicit)
|
|
522
|
-
|
|
515
|
+
model.set(forEach);
|
|
523
516
|
for (const [_key, value] of model)
|
|
524
517
|
if (PARENT.get(value) === model) {
|
|
525
518
|
this.add(value, true);
|
|
@@ -536,8 +529,8 @@ var Context = class _Context {
|
|
|
536
529
|
I = new input();
|
|
537
530
|
this.cleanup.add(() => I.set(null));
|
|
538
531
|
} else {
|
|
532
|
+
T = input.constructor;
|
|
539
533
|
I = input;
|
|
540
|
-
T = I.constructor;
|
|
541
534
|
}
|
|
542
535
|
keys(T, true).forEach((K) => {
|
|
543
536
|
const result = this[K];
|
|
@@ -594,8 +587,7 @@ Model.on((_, model) => {
|
|
|
594
587
|
const { value } = Object.getOwnPropertyDescriptor(model, key2);
|
|
595
588
|
const instruction = INSTRUCT.get(value);
|
|
596
589
|
if (!instruction) {
|
|
597
|
-
|
|
598
|
-
update(model, key2, value);
|
|
590
|
+
mayAdopt(model, value);
|
|
599
591
|
continue;
|
|
600
592
|
}
|
|
601
593
|
INSTRUCT.delete(value);
|
|
@@ -629,76 +621,80 @@ Model.on((_, model) => {
|
|
|
629
621
|
var STALE = /* @__PURE__ */ new WeakSet();
|
|
630
622
|
function get(arg0, arg1) {
|
|
631
623
|
return use((key2, subject, state) => {
|
|
632
|
-
let from = subject;
|
|
633
624
|
if (typeof arg0 == "symbol")
|
|
634
|
-
throw new Error(`Attempted to use an instruction result (probably use or get) as computed source for ${
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
625
|
+
throw new Error(`Attempted to use an instruction result (probably use or get) as computed source for ${subject}.${key2}. This is not allowed.`);
|
|
626
|
+
if (Model.is(arg0)) {
|
|
627
|
+
let assign2 = function(value) {
|
|
628
|
+
if (typeof arg1 == "function")
|
|
629
|
+
value.get((x) => arg1(x, key2));
|
|
630
|
+
update(subject, key2, value);
|
|
631
|
+
};
|
|
632
|
+
var assign = assign2;
|
|
633
|
+
const hasParent = PARENT.get(subject);
|
|
640
634
|
if (!hasParent) {
|
|
641
635
|
if (arg1 === true)
|
|
642
|
-
throw new Error(`${
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
});
|
|
651
|
-
};
|
|
636
|
+
throw new Error(`${subject} may only exist as a child of type ${arg0}.`);
|
|
637
|
+
Context.get(subject, (context) => {
|
|
638
|
+
const model = context.get(arg0);
|
|
639
|
+
if (model)
|
|
640
|
+
assign2(model);
|
|
641
|
+
else if (arg1 !== false)
|
|
642
|
+
throw new Error(`Required ${arg0} not found in context for ${subject}.`);
|
|
643
|
+
});
|
|
652
644
|
} else if (!arg0 || hasParent instanceof arg0)
|
|
653
|
-
|
|
645
|
+
assign2(hasParent);
|
|
654
646
|
else
|
|
655
|
-
throw new Error(`New ${
|
|
647
|
+
throw new Error(`New ${subject} created as child of ${hasParent}, but must be instanceof ${arg0}.`);
|
|
648
|
+
return {
|
|
649
|
+
get: arg1 !== false
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
let from = subject;
|
|
653
|
+
if (arg0 instanceof Model) {
|
|
654
|
+
from = arg0;
|
|
656
655
|
} else {
|
|
657
656
|
const fn = METHOD.get(arg0) || arg0;
|
|
658
657
|
arg1 = (p, k) => fn.call(p, k, p);
|
|
659
658
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
} else
|
|
700
|
-
source((got) => subject.set(key2, got));
|
|
701
|
-
return { get: arg1 };
|
|
659
|
+
const source = (resolve) => resolve(from);
|
|
660
|
+
const getter = arg1;
|
|
661
|
+
let reset;
|
|
662
|
+
let isAsync;
|
|
663
|
+
let proxy;
|
|
664
|
+
function connect(model) {
|
|
665
|
+
reset = createEffect(model, (current) => {
|
|
666
|
+
proxy = current;
|
|
667
|
+
if (!(key2 in state) || STALE.delete(compute))
|
|
668
|
+
compute(!reset);
|
|
669
|
+
return (didUpdate) => {
|
|
670
|
+
if (didUpdate) {
|
|
671
|
+
STALE.add(compute);
|
|
672
|
+
event(subject, key2, true);
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
function compute(initial) {
|
|
678
|
+
let next;
|
|
679
|
+
try {
|
|
680
|
+
next = getter.call(proxy, proxy, key2);
|
|
681
|
+
} catch (err) {
|
|
682
|
+
console.warn(`An exception was thrown while ${initial ? "initializing" : "refreshing"} ${subject}.${key2}.`);
|
|
683
|
+
if (initial)
|
|
684
|
+
throw err;
|
|
685
|
+
console.error(err);
|
|
686
|
+
}
|
|
687
|
+
update(subject, key2, next, !isAsync);
|
|
688
|
+
}
|
|
689
|
+
return () => {
|
|
690
|
+
if (!proxy) {
|
|
691
|
+
source(connect);
|
|
692
|
+
isAsync = true;
|
|
693
|
+
}
|
|
694
|
+
if (STALE.delete(compute))
|
|
695
|
+
compute();
|
|
696
|
+
return fetch(subject, key2, !proxy);
|
|
697
|
+
};
|
|
702
698
|
});
|
|
703
699
|
}
|
|
704
700
|
|
|
@@ -720,7 +716,9 @@ function ref(arg, arg2) {
|
|
|
720
716
|
});
|
|
721
717
|
else {
|
|
722
718
|
const get2 = () => state[key3];
|
|
723
|
-
const set2 = (value2) =>
|
|
719
|
+
const set2 = (value2) => {
|
|
720
|
+
update(subject, key3, value2);
|
|
721
|
+
};
|
|
724
722
|
define(set2, "current", { get: get2, set: set2 });
|
|
725
723
|
define(set2, "get", { value: get2 });
|
|
726
724
|
define(value, key3, { value: set2 });
|
|
@@ -732,7 +730,7 @@ function ref(arg, arg2) {
|
|
|
732
730
|
let unSet;
|
|
733
731
|
const get2 = () => state[key2];
|
|
734
732
|
const set2 = (value2) => {
|
|
735
|
-
if (!subject
|
|
733
|
+
if (!update(subject, key2, value2) || !arg)
|
|
736
734
|
return;
|
|
737
735
|
if (unSet)
|
|
738
736
|
unSet = void unSet(value2);
|
|
@@ -768,16 +766,16 @@ function set(value, argument) {
|
|
|
768
766
|
output.get = argument === true;
|
|
769
767
|
if (value instanceof Promise) {
|
|
770
768
|
value.then((value2) => {
|
|
771
|
-
subject
|
|
769
|
+
update(subject, key2, value2);
|
|
772
770
|
return value2;
|
|
773
771
|
}).catch((err) => {
|
|
774
|
-
subject
|
|
772
|
+
event(subject, key2);
|
|
775
773
|
output.get = () => {
|
|
776
774
|
throw err;
|
|
777
775
|
};
|
|
778
776
|
});
|
|
779
777
|
} else
|
|
780
|
-
subject
|
|
778
|
+
update(subject, key2, value);
|
|
781
779
|
if (0 in arguments)
|
|
782
780
|
return subject[key2];
|
|
783
781
|
};
|
|
@@ -802,7 +800,7 @@ function set(value, argument) {
|
|
|
802
800
|
} else
|
|
803
801
|
output.set = (value2) => {
|
|
804
802
|
output.get = void 0;
|
|
805
|
-
subject
|
|
803
|
+
update(subject, key2, value2);
|
|
806
804
|
};
|
|
807
805
|
return output;
|
|
808
806
|
});
|
|
@@ -830,17 +828,17 @@ var APPLY = /* @__PURE__ */ new WeakMap();
|
|
|
830
828
|
function has(arg1, arg2) {
|
|
831
829
|
return use((key2, subject) => {
|
|
832
830
|
const applied = /* @__PURE__ */ new Set();
|
|
833
|
-
const
|
|
834
|
-
subject
|
|
831
|
+
const apply = () => {
|
|
832
|
+
update(subject, key2, Object.freeze(Array.from(applied)));
|
|
835
833
|
};
|
|
836
834
|
if (Model.is(arg1))
|
|
837
835
|
Context.get(subject, (context) => {
|
|
838
|
-
context.has(arg1, (
|
|
836
|
+
context.has(arg1, (model) => {
|
|
839
837
|
let remove;
|
|
840
838
|
let disconnect;
|
|
841
|
-
if (applied.has(
|
|
839
|
+
if (applied.has(model))
|
|
842
840
|
return;
|
|
843
|
-
const callback = APPLY.get(
|
|
841
|
+
const callback = APPLY.get(model);
|
|
844
842
|
if (callback) {
|
|
845
843
|
const after = callback(subject);
|
|
846
844
|
if (after === false)
|
|
@@ -849,7 +847,7 @@ function has(arg1, arg2) {
|
|
|
849
847
|
disconnect = after;
|
|
850
848
|
}
|
|
851
849
|
if (typeof arg2 == "function") {
|
|
852
|
-
const done2 = arg2(
|
|
850
|
+
const done2 = arg2(model, subject);
|
|
853
851
|
if (done2 === false)
|
|
854
852
|
return false;
|
|
855
853
|
remove = () => {
|
|
@@ -857,18 +855,18 @@ function has(arg1, arg2) {
|
|
|
857
855
|
done2();
|
|
858
856
|
};
|
|
859
857
|
}
|
|
860
|
-
applied.add(
|
|
861
|
-
|
|
858
|
+
applied.add(model);
|
|
859
|
+
apply();
|
|
862
860
|
const done = () => {
|
|
863
|
-
|
|
864
|
-
applied.delete(
|
|
865
|
-
|
|
861
|
+
ignore();
|
|
862
|
+
applied.delete(model);
|
|
863
|
+
apply();
|
|
866
864
|
if (disconnect)
|
|
867
865
|
disconnect();
|
|
868
866
|
if (typeof remove == "function")
|
|
869
867
|
remove();
|
|
870
868
|
};
|
|
871
|
-
const
|
|
869
|
+
const ignore = model.get(null, done);
|
|
872
870
|
return done;
|
|
873
871
|
});
|
|
874
872
|
});
|
|
@@ -883,10 +881,10 @@ function has(arg1, arg2) {
|
|
|
883
881
|
return false;
|
|
884
882
|
}
|
|
885
883
|
applied.add(recipient);
|
|
886
|
-
|
|
884
|
+
apply();
|
|
887
885
|
return () => {
|
|
888
886
|
applied.delete(recipient);
|
|
889
|
-
|
|
887
|
+
apply();
|
|
890
888
|
if (typeof remove == "function")
|
|
891
889
|
remove();
|
|
892
890
|
};
|
package/package.json
CHANGED