@expressive/mvc 0.4.5 → 0.5.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/lib/index.d.ts +41 -43
- package/lib/index.esm.js +410 -561
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +411 -563
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -8,31 +8,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
|
|
9
9
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
10
|
|
|
11
|
-
/*! *****************************************************************************
|
|
12
|
-
Copyright (c) Microsoft Corporation.
|
|
13
|
-
|
|
14
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
15
|
-
purpose with or without fee is hereby granted.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
18
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
19
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
20
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
21
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
22
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
23
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
24
|
-
***************************************************************************** */
|
|
25
|
-
|
|
26
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
27
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
29
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
30
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
31
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
11
|
class Issue extends Error {
|
|
37
12
|
constructor() {
|
|
38
13
|
super(...arguments);
|
|
@@ -95,78 +70,6 @@ function mayRetry(fn) {
|
|
|
95
70
|
}
|
|
96
71
|
|
|
97
72
|
const Oops$b = issues({
|
|
98
|
-
BadCallback: () => `Callback for effect-callback may only return a function.`
|
|
99
|
-
});
|
|
100
|
-
const { assign, create, defineProperty, entries, getPrototypeOf, getOwnPropertyNames, getOwnPropertyDescriptor, getOwnPropertySymbols, values } = Object;
|
|
101
|
-
function define(target, key, value) {
|
|
102
|
-
defineProperty(target, key, { value });
|
|
103
|
-
}
|
|
104
|
-
function defineLazy(object, property, init) {
|
|
105
|
-
defineProperty(object, property, {
|
|
106
|
-
configurable: true,
|
|
107
|
-
get() {
|
|
108
|
-
const value = init.call(this);
|
|
109
|
-
defineProperty(this, property, { value });
|
|
110
|
-
return value;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
function createEffect(callback) {
|
|
115
|
-
let unSet;
|
|
116
|
-
return function (value) {
|
|
117
|
-
if (typeof unSet == "function")
|
|
118
|
-
unSet();
|
|
119
|
-
unSet = callback.call(this, value);
|
|
120
|
-
if (unSet instanceof Promise)
|
|
121
|
-
unSet = undefined;
|
|
122
|
-
if (unSet && typeof unSet !== "function")
|
|
123
|
-
throw Oops$b.BadCallback();
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function createValueEffect(callback) {
|
|
127
|
-
let unSet;
|
|
128
|
-
return function (value) {
|
|
129
|
-
if (typeof unSet == "function")
|
|
130
|
-
unSet(value);
|
|
131
|
-
const out = callback.call(this, value, this);
|
|
132
|
-
if (typeof out == "boolean")
|
|
133
|
-
return out;
|
|
134
|
-
if (!out || out instanceof Promise)
|
|
135
|
-
return;
|
|
136
|
-
if (typeof out == "function")
|
|
137
|
-
unSet = out;
|
|
138
|
-
else
|
|
139
|
-
throw Oops$b.BadCallback();
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function ensure(subject, cb) {
|
|
144
|
-
let control = subject[CONTROL];
|
|
145
|
-
if (!control) {
|
|
146
|
-
control = new Controller(subject);
|
|
147
|
-
define(subject, CONTROL, control);
|
|
148
|
-
}
|
|
149
|
-
if (!control.state) {
|
|
150
|
-
const { waiting } = control;
|
|
151
|
-
if (cb) {
|
|
152
|
-
let done;
|
|
153
|
-
waiting.add(() => {
|
|
154
|
-
done = cb(control);
|
|
155
|
-
});
|
|
156
|
-
return () => done && done();
|
|
157
|
-
}
|
|
158
|
-
control.state = new Map();
|
|
159
|
-
for (const key in subject)
|
|
160
|
-
control.add(key);
|
|
161
|
-
const callback = Array.from(waiting);
|
|
162
|
-
waiting.clear();
|
|
163
|
-
for (const cb of callback)
|
|
164
|
-
cb();
|
|
165
|
-
}
|
|
166
|
-
return cb ? cb(control) : control;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const Oops$a = issues({
|
|
170
73
|
BadSource: (model, property, got) => `Bad from-instruction provided to ${model}.${property}. Expects an arrow-function or a Model as source. Got ${got}.`,
|
|
171
74
|
PeerNotAllowed: (model, property) => `Attempted to use an instruction result (probably use or tap) as computed source for ${model}.${property}. This is not possible.`,
|
|
172
75
|
Failed: (parent, property, initial) => `An exception was thrown while ${initial ? "initializing" : "refreshing"} [${parent}.${property}].`
|
|
@@ -174,8 +77,8 @@ const Oops$a = issues({
|
|
|
174
77
|
const INFO = new WeakMap();
|
|
175
78
|
const KEYS = new WeakMap();
|
|
176
79
|
const ORDER = new WeakMap();
|
|
177
|
-
function
|
|
178
|
-
return apply(function
|
|
80
|
+
function get(source, arg1, arg2) {
|
|
81
|
+
return apply(function get(key) {
|
|
179
82
|
const { subject, state } = this;
|
|
180
83
|
const required = arg2 === true || arg1 === true;
|
|
181
84
|
let getSource;
|
|
@@ -183,7 +86,7 @@ function from(source, arg1, arg2) {
|
|
|
183
86
|
arg1 = undefined;
|
|
184
87
|
// Easy mistake, using a peer, will always be unresolved.
|
|
185
88
|
if (typeof source == "symbol")
|
|
186
|
-
throw Oops$
|
|
89
|
+
throw Oops$b.PeerNotAllowed(subject, key);
|
|
187
90
|
// replace source controller in-case it is different
|
|
188
91
|
if (typeof source == "object")
|
|
189
92
|
getSource = () => ensure(source);
|
|
@@ -194,24 +97,23 @@ function from(source, arg1, arg2) {
|
|
|
194
97
|
}
|
|
195
98
|
// Regular function is too ambiguous so not allowed.
|
|
196
99
|
else
|
|
197
|
-
throw Oops$
|
|
100
|
+
throw Oops$b.BadSource(subject, key, source);
|
|
198
101
|
const setter = arg1;
|
|
199
102
|
const info = { key, parent: this };
|
|
200
103
|
let sub;
|
|
201
104
|
let order = ORDER.get(this);
|
|
202
105
|
if (!order)
|
|
203
106
|
ORDER.set(this, order = []);
|
|
204
|
-
state.set(key, undefined);
|
|
205
107
|
const compute = (initial) => {
|
|
206
108
|
try {
|
|
207
109
|
return setter.call(sub.proxy, sub.proxy);
|
|
208
110
|
}
|
|
209
111
|
catch (err) {
|
|
210
|
-
Oops$
|
|
112
|
+
Oops$b.Failed(subject, key, initial).warn();
|
|
211
113
|
throw err;
|
|
212
114
|
}
|
|
213
115
|
};
|
|
214
|
-
const
|
|
116
|
+
const refresh = () => {
|
|
215
117
|
let value;
|
|
216
118
|
try {
|
|
217
119
|
value = compute(false);
|
|
@@ -227,19 +129,18 @@ function from(source, arg1, arg2) {
|
|
|
227
129
|
}
|
|
228
130
|
}
|
|
229
131
|
};
|
|
230
|
-
const
|
|
132
|
+
const update = (_key, source) => {
|
|
231
133
|
if (source !== this) {
|
|
232
|
-
|
|
134
|
+
refresh();
|
|
233
135
|
return;
|
|
234
136
|
}
|
|
235
137
|
let pending = KEYS.get(this);
|
|
236
138
|
if (!pending)
|
|
237
139
|
KEYS.set(this, pending = []);
|
|
238
|
-
pending.push(
|
|
140
|
+
pending.push(refresh);
|
|
239
141
|
};
|
|
240
142
|
const create = () => {
|
|
241
|
-
|
|
242
|
-
sub = control.subscribe(dependancyDidUpdate);
|
|
143
|
+
sub = getSource().subscribe(update);
|
|
243
144
|
try {
|
|
244
145
|
const value = compute(true);
|
|
245
146
|
state.set(key, value);
|
|
@@ -250,10 +151,11 @@ function from(source, arg1, arg2) {
|
|
|
250
151
|
}
|
|
251
152
|
finally {
|
|
252
153
|
sub.commit();
|
|
253
|
-
order.push(
|
|
154
|
+
order.push(refresh);
|
|
254
155
|
}
|
|
255
156
|
};
|
|
256
|
-
|
|
157
|
+
state.set(key, undefined);
|
|
158
|
+
INFO.set(refresh, info);
|
|
257
159
|
return () => {
|
|
258
160
|
const value = sub ? state.get(key) : create();
|
|
259
161
|
if (value === undefined && required)
|
|
@@ -278,6 +180,39 @@ function flush(control) {
|
|
|
278
180
|
KEYS.delete(control);
|
|
279
181
|
}
|
|
280
182
|
|
|
183
|
+
const Oops$a = issues({
|
|
184
|
+
BadCallback: () => `Callback for effect-callback may only return a function.`
|
|
185
|
+
});
|
|
186
|
+
const { assign, create, defineProperty, entries, getPrototypeOf, getOwnPropertyNames, getOwnPropertyDescriptor, getOwnPropertySymbols, values } = Object;
|
|
187
|
+
function createEffect(callback) {
|
|
188
|
+
let unSet;
|
|
189
|
+
return function (value) {
|
|
190
|
+
if (typeof unSet == "function")
|
|
191
|
+
unSet();
|
|
192
|
+
unSet = callback.call(this, value);
|
|
193
|
+
if (unSet instanceof Promise)
|
|
194
|
+
unSet = undefined;
|
|
195
|
+
if (unSet && typeof unSet !== "function")
|
|
196
|
+
throw Oops$a.BadCallback();
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function createValueEffect(callback) {
|
|
200
|
+
let unSet;
|
|
201
|
+
return function (value) {
|
|
202
|
+
if (typeof unSet == "function")
|
|
203
|
+
unSet(value);
|
|
204
|
+
const out = callback.call(this, value, this);
|
|
205
|
+
if (typeof out == "boolean")
|
|
206
|
+
return out;
|
|
207
|
+
if (!out || out instanceof Promise)
|
|
208
|
+
return;
|
|
209
|
+
if (typeof out == "function")
|
|
210
|
+
unSet = out;
|
|
211
|
+
else
|
|
212
|
+
throw Oops$a.BadCallback();
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
281
216
|
class Subscriber {
|
|
282
217
|
constructor(parent, onUpdate) {
|
|
283
218
|
this.onUpdate = onUpdate;
|
|
@@ -285,7 +220,7 @@ class Subscriber {
|
|
|
285
220
|
this.dependant = new Set();
|
|
286
221
|
const proxy = create(parent.subject);
|
|
287
222
|
const using = new Map();
|
|
288
|
-
|
|
223
|
+
defineProperty(proxy, LOCAL, { value: this });
|
|
289
224
|
defineProperty(this, "proxy", {
|
|
290
225
|
configurable: true,
|
|
291
226
|
get() {
|
|
@@ -306,15 +241,13 @@ class Subscriber {
|
|
|
306
241
|
}
|
|
307
242
|
else if (handler === true)
|
|
308
243
|
notify = this.onUpdate(key, parent);
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
UPDATE.set(proxy,
|
|
244
|
+
if (!notify)
|
|
245
|
+
return;
|
|
246
|
+
const notate = () => {
|
|
247
|
+
UPDATE.set(proxy, getUpdate(parent.subject).filter(k => using.has(k)));
|
|
313
248
|
};
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
parent.waiting.add(notify);
|
|
317
|
-
}
|
|
249
|
+
parent.waiting.add(notate);
|
|
250
|
+
parent.waiting.add(notify);
|
|
318
251
|
});
|
|
319
252
|
this.commit = () => {
|
|
320
253
|
this.active = true;
|
|
@@ -334,123 +267,37 @@ class Subscriber {
|
|
|
334
267
|
}
|
|
335
268
|
}
|
|
336
269
|
|
|
337
|
-
const UPDATE = new WeakMap();
|
|
338
|
-
function getUpdate(subject) {
|
|
339
|
-
return UPDATE.get(subject);
|
|
340
|
-
}
|
|
341
|
-
class Controller {
|
|
342
|
-
constructor(subject) {
|
|
343
|
-
this.subject = subject;
|
|
344
|
-
this.frame = new Set();
|
|
345
|
-
this.waiting = new Set();
|
|
346
|
-
this.followers = new Set();
|
|
347
|
-
}
|
|
348
|
-
subscribe(callback) {
|
|
349
|
-
return new Subscriber(this, callback);
|
|
350
|
-
}
|
|
351
|
-
add(key) {
|
|
352
|
-
const { subject, state } = this;
|
|
353
|
-
const { value } = getOwnPropertyDescriptor(subject, key);
|
|
354
|
-
if (typeof value == "function")
|
|
355
|
-
return;
|
|
356
|
-
if (typeof value == "symbol") {
|
|
357
|
-
const instruction = PENDING.get(value);
|
|
358
|
-
if (instruction)
|
|
359
|
-
instruction.call(this, key, this);
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
state.set(key, value);
|
|
363
|
-
defineProperty(subject, key, {
|
|
364
|
-
enumerable: false,
|
|
365
|
-
set: this.ref(key),
|
|
366
|
-
get() {
|
|
367
|
-
const local = this[LOCAL];
|
|
368
|
-
if (local)
|
|
369
|
-
local.add(key);
|
|
370
|
-
return state.get(key);
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
addListener(listener) {
|
|
375
|
-
this.followers.add(listener);
|
|
376
|
-
return () => {
|
|
377
|
-
this.followers.delete(listener);
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
ref(key, handler) {
|
|
381
|
-
const { subject, state } = this;
|
|
382
|
-
return (value) => {
|
|
383
|
-
if (state.get(key) == value)
|
|
384
|
-
return;
|
|
385
|
-
if (handler)
|
|
386
|
-
switch (handler.call(subject, value)) {
|
|
387
|
-
case true:
|
|
388
|
-
this.update(key);
|
|
389
|
-
case false:
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
state.set(key, value);
|
|
393
|
-
this.update(key);
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
update(key) {
|
|
397
|
-
const { followers, frame, subject, waiting } = this;
|
|
398
|
-
if (frame.has(key))
|
|
399
|
-
return;
|
|
400
|
-
else if (!frame.size)
|
|
401
|
-
setTimeout(() => {
|
|
402
|
-
flush(this);
|
|
403
|
-
UPDATE.set(subject, Array.from(frame));
|
|
404
|
-
setTimeout(() => {
|
|
405
|
-
UPDATE.delete(subject);
|
|
406
|
-
}, 0);
|
|
407
|
-
frame.clear();
|
|
408
|
-
for (const notify of waiting)
|
|
409
|
-
try {
|
|
410
|
-
waiting.delete(notify);
|
|
411
|
-
notify();
|
|
412
|
-
}
|
|
413
|
-
catch (err) {
|
|
414
|
-
console.error(err);
|
|
415
|
-
}
|
|
416
|
-
}, 0);
|
|
417
|
-
frame.add(key);
|
|
418
|
-
for (const callback of followers) {
|
|
419
|
-
const event = callback(key, this);
|
|
420
|
-
if (typeof event == "function")
|
|
421
|
-
waiting.add(event);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
clear() {
|
|
425
|
-
const listeners = [...this.followers];
|
|
426
|
-
this.followers.clear();
|
|
427
|
-
listeners.forEach(x => x(null, this));
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
270
|
const Oops$9 = issues({
|
|
432
271
|
Timeout: (keys, timeout) => `No update for [${keys}] within ${timeout}.`,
|
|
433
272
|
StrictUpdate: () => `Strict update() did not find pending updates.`,
|
|
434
273
|
NoChaining: () => `Then called with undefined; update promise will never catch nor supports chaining.`
|
|
435
274
|
});
|
|
436
|
-
const CONTROL = Symbol("CONTROL");
|
|
437
275
|
const WHY = Symbol("UPDATE");
|
|
438
276
|
const LOCAL = Symbol("LOCAL");
|
|
439
277
|
const STATE = Symbol("STATE");
|
|
440
278
|
class Model {
|
|
441
279
|
constructor() {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
280
|
+
defineProperty(this, CONTROL, {
|
|
281
|
+
value: new Controller(this)
|
|
282
|
+
});
|
|
283
|
+
defineProperty(this, "is", {
|
|
284
|
+
value: this
|
|
285
|
+
});
|
|
286
|
+
defineProperty(this, "set", {
|
|
287
|
+
configurable: true,
|
|
288
|
+
get: () => {
|
|
289
|
+
const controller = ensure(this);
|
|
290
|
+
const value = (key, value) => {
|
|
291
|
+
controller.state.set(key, value);
|
|
292
|
+
controller.update(key);
|
|
293
|
+
};
|
|
294
|
+
for (const key of controller.state.keys())
|
|
295
|
+
defineProperty(value, key, {
|
|
296
|
+
value: controller.ref(key)
|
|
297
|
+
});
|
|
298
|
+
defineProperty(this, "set", { value });
|
|
299
|
+
return value;
|
|
300
|
+
}
|
|
454
301
|
});
|
|
455
302
|
}
|
|
456
303
|
get [STATE]() {
|
|
@@ -636,6 +483,127 @@ class Model {
|
|
|
636
483
|
}
|
|
637
484
|
}
|
|
638
485
|
|
|
486
|
+
const UPDATE = new WeakMap();
|
|
487
|
+
const CONTROL = Symbol("CONTROL");
|
|
488
|
+
function getUpdate(subject) {
|
|
489
|
+
return UPDATE.get(subject);
|
|
490
|
+
}
|
|
491
|
+
class Controller {
|
|
492
|
+
constructor(subject) {
|
|
493
|
+
this.subject = subject;
|
|
494
|
+
this.frame = new Set();
|
|
495
|
+
this.waiting = new Set();
|
|
496
|
+
this.followers = new Set();
|
|
497
|
+
}
|
|
498
|
+
subscribe(callback) {
|
|
499
|
+
return new Subscriber(this, callback);
|
|
500
|
+
}
|
|
501
|
+
add(key) {
|
|
502
|
+
const { subject, state } = this;
|
|
503
|
+
const { value } = getOwnPropertyDescriptor(subject, key);
|
|
504
|
+
if (typeof value == "function")
|
|
505
|
+
return;
|
|
506
|
+
if (typeof value == "symbol") {
|
|
507
|
+
const instruction = PENDING.get(value);
|
|
508
|
+
if (instruction)
|
|
509
|
+
instruction.call(this, key, this);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
state.set(key, value);
|
|
513
|
+
defineProperty(subject, key, {
|
|
514
|
+
enumerable: false,
|
|
515
|
+
set: this.ref(key),
|
|
516
|
+
get() {
|
|
517
|
+
const local = this[LOCAL];
|
|
518
|
+
if (local)
|
|
519
|
+
local.add(key);
|
|
520
|
+
return state.get(key);
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
addListener(listener) {
|
|
525
|
+
this.followers.add(listener);
|
|
526
|
+
return () => {
|
|
527
|
+
this.followers.delete(listener);
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
ref(key, handler) {
|
|
531
|
+
const { subject, state } = this;
|
|
532
|
+
return (value) => {
|
|
533
|
+
if (state.get(key) == value)
|
|
534
|
+
return;
|
|
535
|
+
if (handler)
|
|
536
|
+
switch (handler.call(subject, value)) {
|
|
537
|
+
case true:
|
|
538
|
+
this.update(key);
|
|
539
|
+
case false:
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
state.set(key, value);
|
|
543
|
+
this.update(key);
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
update(key) {
|
|
547
|
+
const { followers, frame, subject, waiting } = this;
|
|
548
|
+
if (frame.has(key))
|
|
549
|
+
return;
|
|
550
|
+
else if (!frame.size)
|
|
551
|
+
setTimeout(() => {
|
|
552
|
+
flush(this);
|
|
553
|
+
UPDATE.set(subject, Array.from(frame));
|
|
554
|
+
setTimeout(() => {
|
|
555
|
+
UPDATE.delete(subject);
|
|
556
|
+
}, 0);
|
|
557
|
+
frame.clear();
|
|
558
|
+
for (const notify of waiting)
|
|
559
|
+
try {
|
|
560
|
+
waiting.delete(notify);
|
|
561
|
+
notify();
|
|
562
|
+
}
|
|
563
|
+
catch (err) {
|
|
564
|
+
console.error(err);
|
|
565
|
+
}
|
|
566
|
+
}, 0);
|
|
567
|
+
frame.add(key);
|
|
568
|
+
for (const callback of followers) {
|
|
569
|
+
const event = callback(key, this);
|
|
570
|
+
if (typeof event == "function")
|
|
571
|
+
waiting.add(event);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
clear() {
|
|
575
|
+
const listeners = [...this.followers];
|
|
576
|
+
this.followers.clear();
|
|
577
|
+
listeners.forEach(x => x(null, this));
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
function ensure(subject, cb) {
|
|
581
|
+
let control = subject[CONTROL];
|
|
582
|
+
if (!control)
|
|
583
|
+
defineProperty(subject, CONTROL, {
|
|
584
|
+
value: control =
|
|
585
|
+
new Controller(subject)
|
|
586
|
+
});
|
|
587
|
+
if (!control.state) {
|
|
588
|
+
const { waiting } = control;
|
|
589
|
+
if (cb) {
|
|
590
|
+
let done;
|
|
591
|
+
waiting.add(() => {
|
|
592
|
+
done = cb(control);
|
|
593
|
+
});
|
|
594
|
+
return () => done && done();
|
|
595
|
+
}
|
|
596
|
+
control.state = new Map();
|
|
597
|
+
for (const key in subject)
|
|
598
|
+
control.add(key);
|
|
599
|
+
const callback = Array.from(waiting);
|
|
600
|
+
waiting.clear();
|
|
601
|
+
for (const cb of callback)
|
|
602
|
+
cb();
|
|
603
|
+
}
|
|
604
|
+
return cb ? cb(control) : control;
|
|
605
|
+
}
|
|
606
|
+
|
|
639
607
|
const PENDING = new Map();
|
|
640
608
|
function apply(fn, label) {
|
|
641
609
|
const name = label || fn.name || "pending";
|
|
@@ -654,11 +622,11 @@ function apply(fn, label) {
|
|
|
654
622
|
defineProperty(subject, key, output);
|
|
655
623
|
return false;
|
|
656
624
|
}
|
|
625
|
+
let { get: onGet, set: onSet, suspense } = output;
|
|
626
|
+
if ("value" in output)
|
|
627
|
+
state.set(key, output.value);
|
|
657
628
|
if ("recursive" in output && output.recursive)
|
|
658
|
-
|
|
659
|
-
const desc = output;
|
|
660
|
-
if ("value" in desc)
|
|
661
|
-
state.set(key, desc.value);
|
|
629
|
+
onGet = getRecursive(key, this);
|
|
662
630
|
if ("destroy" in output) {
|
|
663
631
|
const { destroy } = output;
|
|
664
632
|
if (destroy)
|
|
@@ -667,57 +635,84 @@ function apply(fn, label) {
|
|
|
667
635
|
destroy();
|
|
668
636
|
});
|
|
669
637
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
local
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
638
|
+
defineProperty(subject, key, {
|
|
639
|
+
enumerable: output.enumerable,
|
|
640
|
+
set: onSet !== false
|
|
641
|
+
? this.ref(key, onSet)
|
|
642
|
+
: undefined,
|
|
643
|
+
get() {
|
|
644
|
+
if (!state.has(key) && suspense)
|
|
645
|
+
throw suspend(control, key);
|
|
646
|
+
const local = this[LOCAL];
|
|
647
|
+
if (local)
|
|
648
|
+
local.add(key);
|
|
649
|
+
return onGet
|
|
650
|
+
? onGet(local)
|
|
651
|
+
: state.get(key);
|
|
652
|
+
}
|
|
653
|
+
});
|
|
685
654
|
}
|
|
686
655
|
PENDING.set(placeholder, setup);
|
|
687
656
|
return placeholder;
|
|
688
657
|
}
|
|
689
658
|
function getRecursive(key, from) {
|
|
690
659
|
const context = new WeakMap();
|
|
691
|
-
const { state } = from;
|
|
692
660
|
return (local) => {
|
|
693
661
|
if (!local)
|
|
694
|
-
return state.get(key);
|
|
662
|
+
return from.state.get(key);
|
|
695
663
|
if (!context.has(local)) {
|
|
696
|
-
let
|
|
664
|
+
let reset;
|
|
697
665
|
const init = () => {
|
|
698
|
-
if (
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
context.set(local, undefined);
|
|
702
|
-
child = undefined;
|
|
703
|
-
}
|
|
704
|
-
const value = state.get(key);
|
|
666
|
+
if (reset)
|
|
667
|
+
reset();
|
|
668
|
+
const value = from.state.get(key);
|
|
705
669
|
if (value && CONTROL in value) {
|
|
706
|
-
child = ensure(value).subscribe(local.onUpdate);
|
|
670
|
+
const child = ensure(value).subscribe(local.onUpdate);
|
|
707
671
|
if (local.active)
|
|
708
672
|
child.commit();
|
|
709
673
|
local.dependant.add(child);
|
|
710
674
|
context.set(local, child.proxy);
|
|
675
|
+
reset = () => {
|
|
676
|
+
child.release();
|
|
677
|
+
local.dependant.delete(child);
|
|
678
|
+
context.set(local, undefined);
|
|
679
|
+
reset = undefined;
|
|
680
|
+
};
|
|
711
681
|
}
|
|
712
682
|
return true;
|
|
713
683
|
};
|
|
714
|
-
init();
|
|
715
684
|
local.add(key, init);
|
|
685
|
+
init();
|
|
716
686
|
}
|
|
717
687
|
return context.get(local);
|
|
718
688
|
};
|
|
719
689
|
}
|
|
720
690
|
|
|
691
|
+
/*! *****************************************************************************
|
|
692
|
+
Copyright (c) Microsoft Corporation.
|
|
693
|
+
|
|
694
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
695
|
+
purpose with or without fee is hereby granted.
|
|
696
|
+
|
|
697
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
698
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
699
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
700
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
701
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
702
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
703
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
704
|
+
***************************************************************************** */
|
|
705
|
+
|
|
706
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
707
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
708
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
709
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
710
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
711
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
712
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
|
|
721
716
|
const Oops$8 = issues({
|
|
722
717
|
DuplicatePending: (key) => `Invoked action ${key} but one is already active.`
|
|
723
718
|
});
|
|
@@ -748,74 +743,6 @@ function act(task) {
|
|
|
748
743
|
});
|
|
749
744
|
}
|
|
750
745
|
|
|
751
|
-
class Managed extends Array {
|
|
752
|
-
constructor(onUpdate) {
|
|
753
|
-
super();
|
|
754
|
-
this.lastUpdate = [0, 0];
|
|
755
|
-
this.update = (from, to) => {
|
|
756
|
-
this.lastUpdate = [from, to];
|
|
757
|
-
onUpdate();
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
push(...items) {
|
|
761
|
-
const { length } = this;
|
|
762
|
-
const end = super.push(...items);
|
|
763
|
-
this.update(length, end);
|
|
764
|
-
return end;
|
|
765
|
-
}
|
|
766
|
-
unshift(...items) {
|
|
767
|
-
const end = super.push(...items);
|
|
768
|
-
this.update(0, end);
|
|
769
|
-
return end;
|
|
770
|
-
}
|
|
771
|
-
splice(start, deleteCount, ...rest) {
|
|
772
|
-
const end = deleteCount !== rest.length ? Infinity : deleteCount;
|
|
773
|
-
this.update(start, end);
|
|
774
|
-
return super.splice(start, deleteCount, ...rest);
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
function array() {
|
|
778
|
-
return apply(function array(key) {
|
|
779
|
-
const context = new WeakMap();
|
|
780
|
-
const array = new Managed(() => this.update(key));
|
|
781
|
-
const getLocal = (context) => {
|
|
782
|
-
const proxy = Object.create(array);
|
|
783
|
-
let rangeA = 0;
|
|
784
|
-
let rangeB = 0;
|
|
785
|
-
const onUpdate = () => {
|
|
786
|
-
const [lastA, lastB] = array.lastUpdate;
|
|
787
|
-
if (rangeA <= lastB && rangeB >= lastA)
|
|
788
|
-
return true;
|
|
789
|
-
};
|
|
790
|
-
const listen = (eventA, eventB) => {
|
|
791
|
-
if (context.active)
|
|
792
|
-
return;
|
|
793
|
-
context.add(key, onUpdate);
|
|
794
|
-
rangeA = Math.min(rangeA, eventA);
|
|
795
|
-
rangeB = Math.max(rangeB, eventB);
|
|
796
|
-
};
|
|
797
|
-
proxy[Symbol.iterator] = () => {
|
|
798
|
-
listen(0, Infinity);
|
|
799
|
-
return array[Symbol.iterator]();
|
|
800
|
-
};
|
|
801
|
-
return proxy;
|
|
802
|
-
};
|
|
803
|
-
return {
|
|
804
|
-
value: array,
|
|
805
|
-
set: false,
|
|
806
|
-
get: (local) => {
|
|
807
|
-
if (!local)
|
|
808
|
-
return this.state.get(key);
|
|
809
|
-
if (context.has(local))
|
|
810
|
-
return context.get(local);
|
|
811
|
-
const output = getLocal(local);
|
|
812
|
-
context.set(local, output);
|
|
813
|
-
return output;
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
|
|
819
746
|
function ref(callback) {
|
|
820
747
|
return apply(function ref(key) {
|
|
821
748
|
const value = this.ref(key, callback && createValueEffect(callback));
|
|
@@ -838,9 +765,8 @@ const Oops$7 = issues({
|
|
|
838
765
|
function put(factory, argument) {
|
|
839
766
|
return apply(function set(key) {
|
|
840
767
|
const { subject, state } = this;
|
|
841
|
-
const required = argument === true ||
|
|
842
|
-
|
|
843
|
-
let get;
|
|
768
|
+
const required = argument === true ||
|
|
769
|
+
argument === undefined;
|
|
844
770
|
let pending;
|
|
845
771
|
let error;
|
|
846
772
|
const init = () => {
|
|
@@ -863,6 +789,14 @@ function put(factory, argument) {
|
|
|
863
789
|
state.set(key, output);
|
|
864
790
|
return output;
|
|
865
791
|
};
|
|
792
|
+
if (required)
|
|
793
|
+
try {
|
|
794
|
+
init();
|
|
795
|
+
}
|
|
796
|
+
catch (err) {
|
|
797
|
+
Oops$7.Failed(subject, key).warn();
|
|
798
|
+
throw err;
|
|
799
|
+
}
|
|
866
800
|
const suspend = () => {
|
|
867
801
|
if (required === false)
|
|
868
802
|
return undefined;
|
|
@@ -873,30 +807,21 @@ function put(factory, argument) {
|
|
|
873
807
|
});
|
|
874
808
|
throw pending;
|
|
875
809
|
};
|
|
876
|
-
|
|
877
|
-
try {
|
|
878
|
-
init();
|
|
879
|
-
}
|
|
880
|
-
catch (err) {
|
|
881
|
-
Oops$7.Failed(subject, key).warn();
|
|
882
|
-
throw err;
|
|
883
|
-
}
|
|
884
|
-
get = () => {
|
|
810
|
+
const get = () => {
|
|
885
811
|
if (pending)
|
|
886
812
|
return suspend();
|
|
887
813
|
if (error)
|
|
888
814
|
throw error;
|
|
889
815
|
if (state.has(key))
|
|
890
816
|
return state.get(key);
|
|
891
|
-
|
|
817
|
+
const output = init();
|
|
892
818
|
return pending
|
|
893
819
|
? suspend()
|
|
894
820
|
: output;
|
|
895
821
|
};
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
set = (value) => {
|
|
822
|
+
const set = typeof argument == "function"
|
|
823
|
+
? createValueEffect(argument)
|
|
824
|
+
: (value) => {
|
|
900
825
|
if (value === undefined && required)
|
|
901
826
|
throw Oops$7.NonOptional(subject, key);
|
|
902
827
|
};
|
|
@@ -924,257 +849,162 @@ function set(value, argument) {
|
|
|
924
849
|
});
|
|
925
850
|
}
|
|
926
851
|
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
Unexpected: (expects, child, got) => `New ${child} created as child of ${got}, but must be instanceof ${expects}.`,
|
|
931
|
-
});
|
|
932
|
-
function parent(Expects, required) {
|
|
933
|
-
return apply(function parent() {
|
|
934
|
-
const child = this.subject;
|
|
935
|
-
const value = Parent.get(child);
|
|
936
|
-
const expected = Expects.name;
|
|
937
|
-
if (!value) {
|
|
938
|
-
if (required !== false)
|
|
939
|
-
throw Oops$6.Required(expected, child);
|
|
940
|
-
}
|
|
941
|
-
else if (!(value instanceof Expects))
|
|
942
|
-
throw Oops$6.Unexpected(expected, child, value);
|
|
943
|
-
return { value };
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
const ANY$1 = Symbol("any");
|
|
948
|
-
function managedMap(control, property, initial) {
|
|
949
|
-
const managed = new ManagedMap(initial, emit);
|
|
950
|
-
const context = new WeakMap();
|
|
951
|
-
const observers = new Set();
|
|
852
|
+
const ANY = Symbol("any");
|
|
853
|
+
function keyed(control, property, initial) {
|
|
854
|
+
const init = createProxy(emit, watch);
|
|
952
855
|
const frozen = new Set();
|
|
953
|
-
|
|
954
|
-
|
|
856
|
+
const context = new Map();
|
|
857
|
+
const users = new Map();
|
|
858
|
+
const watched = new WeakMap();
|
|
859
|
+
const update = new Set();
|
|
860
|
+
let managed = init(initial);
|
|
861
|
+
function watch(on, key) {
|
|
862
|
+
const include = watched.get(on);
|
|
863
|
+
if (include)
|
|
864
|
+
include.add(key);
|
|
955
865
|
}
|
|
956
866
|
function emit(key) {
|
|
957
|
-
observers.forEach(notify => notify(key));
|
|
958
867
|
control.update(property);
|
|
959
|
-
control.waiting.add(
|
|
868
|
+
control.waiting.add(() => frozen.clear());
|
|
869
|
+
update.forEach(notify => notify(key));
|
|
960
870
|
}
|
|
961
|
-
function
|
|
871
|
+
function subscribe(local) {
|
|
962
872
|
const proxy = create(managed);
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
refresh();
|
|
873
|
+
let watch = users.get(local);
|
|
874
|
+
if (!watch) {
|
|
875
|
+
const using = watch = new Set();
|
|
876
|
+
users.set(local, using);
|
|
877
|
+
function onEvent(key) {
|
|
878
|
+
if (frozen.has(local))
|
|
879
|
+
return;
|
|
880
|
+
if (key === ANY || using.has(key) || using.has(ANY)) {
|
|
881
|
+
const refresh = local.onUpdate(property, control);
|
|
882
|
+
if (refresh) {
|
|
883
|
+
frozen.add(local);
|
|
884
|
+
refresh();
|
|
885
|
+
}
|
|
972
886
|
}
|
|
973
887
|
}
|
|
974
|
-
|
|
975
|
-
|
|
888
|
+
local.add(property, false);
|
|
889
|
+
local.dependant.add({
|
|
890
|
+
commit() {
|
|
891
|
+
if (using.size === 0)
|
|
892
|
+
using.add(ANY);
|
|
893
|
+
update.add(onEvent);
|
|
894
|
+
},
|
|
895
|
+
release() {
|
|
896
|
+
update.delete(onEvent);
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
watched.set(proxy, watch);
|
|
976
901
|
context.set(local, proxy);
|
|
977
|
-
proxy.watch = (key) => {
|
|
978
|
-
if (!local.active)
|
|
979
|
-
using.add(key);
|
|
980
|
-
};
|
|
981
902
|
return proxy;
|
|
982
903
|
}
|
|
983
904
|
return {
|
|
984
905
|
value: initial,
|
|
985
906
|
get(local) {
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
return context.get(local);
|
|
990
|
-
return init(local);
|
|
907
|
+
return local ?
|
|
908
|
+
context.get(local) || subscribe(local) :
|
|
909
|
+
managed;
|
|
991
910
|
},
|
|
992
911
|
set(next) {
|
|
993
|
-
managed.source = next;
|
|
994
912
|
control.state.set(property, next);
|
|
995
|
-
|
|
913
|
+
managed = init(next);
|
|
914
|
+
context.clear();
|
|
915
|
+
emit(ANY);
|
|
996
916
|
},
|
|
997
917
|
destroy() {
|
|
998
|
-
|
|
918
|
+
update.clear();
|
|
919
|
+
context.clear();
|
|
999
920
|
}
|
|
1000
921
|
};
|
|
1001
922
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
const frozen = new Set();
|
|
1063
|
-
function reset() {
|
|
1064
|
-
frozen.clear();
|
|
1065
|
-
}
|
|
1066
|
-
function emit(key) {
|
|
1067
|
-
observers.forEach(notify => notify(key));
|
|
1068
|
-
control.update(property);
|
|
1069
|
-
control.waiting.add(reset);
|
|
1070
|
-
}
|
|
1071
|
-
function init(local) {
|
|
1072
|
-
const proxy = create(managed);
|
|
1073
|
-
const using = new Set();
|
|
1074
|
-
observers.add(key => {
|
|
1075
|
-
if (frozen.has(local))
|
|
1076
|
-
return;
|
|
1077
|
-
if (using.has(key) || using.has(ANY) || key === ANY && using.size) {
|
|
1078
|
-
const refresh = local.onUpdate(property, control);
|
|
1079
|
-
if (refresh) {
|
|
1080
|
-
frozen.add(local);
|
|
1081
|
-
refresh();
|
|
923
|
+
function createProxy(emit, watch) {
|
|
924
|
+
return (from) => {
|
|
925
|
+
const proxy = create(from);
|
|
926
|
+
assign(proxy, {
|
|
927
|
+
from,
|
|
928
|
+
delete(key) {
|
|
929
|
+
emit(key);
|
|
930
|
+
return from.delete(key);
|
|
931
|
+
},
|
|
932
|
+
clear() {
|
|
933
|
+
emit(ANY);
|
|
934
|
+
from.clear();
|
|
935
|
+
},
|
|
936
|
+
has(key) {
|
|
937
|
+
watch(this, key);
|
|
938
|
+
return from.has(key);
|
|
939
|
+
},
|
|
940
|
+
keys() {
|
|
941
|
+
watch(this, ANY);
|
|
942
|
+
return from.keys();
|
|
943
|
+
},
|
|
944
|
+
values() {
|
|
945
|
+
watch(this, ANY);
|
|
946
|
+
return from.values();
|
|
947
|
+
},
|
|
948
|
+
entries() {
|
|
949
|
+
watch(this, ANY);
|
|
950
|
+
return from.entries();
|
|
951
|
+
},
|
|
952
|
+
forEach(callbackfn, thisArg) {
|
|
953
|
+
const acc = [];
|
|
954
|
+
from.forEach((a, b, c) => {
|
|
955
|
+
const result = callbackfn.call(thisArg, a, b, c);
|
|
956
|
+
if (result !== undefined)
|
|
957
|
+
acc.push(result);
|
|
958
|
+
});
|
|
959
|
+
watch(this, ANY);
|
|
960
|
+
return acc;
|
|
961
|
+
},
|
|
962
|
+
[Symbol.iterator]() {
|
|
963
|
+
watch(this, ANY);
|
|
964
|
+
return from[Symbol.iterator]();
|
|
965
|
+
},
|
|
966
|
+
}, from instanceof Set
|
|
967
|
+
? {
|
|
968
|
+
add(key) {
|
|
969
|
+
from.add(key);
|
|
970
|
+
emit(key);
|
|
971
|
+
return this;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
: {
|
|
975
|
+
get(key) {
|
|
976
|
+
watch(this, ANY);
|
|
977
|
+
return from.get(key);
|
|
978
|
+
},
|
|
979
|
+
set(key, value) {
|
|
980
|
+
from.set(key, value);
|
|
981
|
+
emit(key);
|
|
982
|
+
return this;
|
|
1082
983
|
}
|
|
984
|
+
});
|
|
985
|
+
defineProperty(proxy, "size", {
|
|
986
|
+
get() {
|
|
987
|
+
watch(this, ANY);
|
|
988
|
+
return from.size;
|
|
1083
989
|
}
|
|
1084
990
|
});
|
|
1085
|
-
local.add(property, false);
|
|
1086
|
-
context.set(local, proxy);
|
|
1087
|
-
proxy.watch = (key) => {
|
|
1088
|
-
if (!local.active)
|
|
1089
|
-
using.add(key);
|
|
1090
|
-
};
|
|
1091
991
|
return proxy;
|
|
1092
|
-
}
|
|
1093
|
-
return {
|
|
1094
|
-
value: initial,
|
|
1095
|
-
get(local) {
|
|
1096
|
-
if (!local)
|
|
1097
|
-
return managed;
|
|
1098
|
-
if (context.has(local))
|
|
1099
|
-
return context.get(local);
|
|
1100
|
-
return init(local);
|
|
1101
|
-
},
|
|
1102
|
-
set(next) {
|
|
1103
|
-
managed.source = next;
|
|
1104
|
-
control.state.set(property, next);
|
|
1105
|
-
emit(ANY);
|
|
1106
|
-
},
|
|
1107
|
-
destroy() {
|
|
1108
|
-
observers.clear();
|
|
1109
|
-
}
|
|
1110
992
|
};
|
|
1111
|
-
}
|
|
1112
|
-
class ManagedSet {
|
|
1113
|
-
constructor(source, emit) {
|
|
1114
|
-
this.source = source;
|
|
1115
|
-
this.emit = emit;
|
|
1116
|
-
}
|
|
1117
|
-
watch(_key) { }
|
|
1118
|
-
add(key) {
|
|
1119
|
-
this.source.add(key);
|
|
1120
|
-
this.emit(key);
|
|
1121
|
-
return this;
|
|
1122
|
-
}
|
|
1123
|
-
;
|
|
1124
|
-
delete(key) {
|
|
1125
|
-
this.emit(key);
|
|
1126
|
-
return this.source.delete(key);
|
|
1127
|
-
}
|
|
1128
|
-
;
|
|
1129
|
-
clear() {
|
|
1130
|
-
this.emit(ANY);
|
|
1131
|
-
this.source.clear();
|
|
1132
|
-
}
|
|
1133
|
-
has(key) {
|
|
1134
|
-
this.watch(key);
|
|
1135
|
-
return this.source.has(key);
|
|
1136
|
-
}
|
|
1137
|
-
;
|
|
1138
|
-
values() {
|
|
1139
|
-
this.watch(ANY);
|
|
1140
|
-
return this.source.values();
|
|
1141
|
-
}
|
|
1142
|
-
keys() {
|
|
1143
|
-
this.watch(ANY);
|
|
1144
|
-
return this.source.keys();
|
|
1145
|
-
}
|
|
1146
|
-
entries() {
|
|
1147
|
-
this.watch(ANY);
|
|
1148
|
-
return this.source.entries();
|
|
1149
|
-
}
|
|
1150
|
-
;
|
|
1151
|
-
[Symbol.iterator]() {
|
|
1152
|
-
this.watch(ANY);
|
|
1153
|
-
return this.source[Symbol.iterator]();
|
|
1154
|
-
}
|
|
1155
|
-
;
|
|
1156
|
-
get size() {
|
|
1157
|
-
this.watch(ANY);
|
|
1158
|
-
return this.source.size;
|
|
1159
|
-
}
|
|
1160
993
|
}
|
|
1161
994
|
|
|
1162
|
-
const
|
|
995
|
+
const Parent = new WeakMap();
|
|
996
|
+
const Oops$6 = issues({
|
|
1163
997
|
BadArgument: (type) => `Instruction \`use\` cannot accept argument type of ${type}.`,
|
|
1164
998
|
});
|
|
1165
999
|
function use$1(input, argument) {
|
|
1166
1000
|
return apply(function use(key) {
|
|
1167
1001
|
const { state, subject } = this;
|
|
1168
1002
|
if (typeof input === "function")
|
|
1169
|
-
input =
|
|
1170
|
-
? new input()
|
|
1171
|
-
: input();
|
|
1003
|
+
input = "prototype" in input ? new input() : input();
|
|
1172
1004
|
else if (input && typeof input !== "object")
|
|
1173
|
-
throw Oops$
|
|
1174
|
-
if (input instanceof Map)
|
|
1175
|
-
return
|
|
1176
|
-
if (input instanceof Set)
|
|
1177
|
-
return managedSet(this, key, input);
|
|
1005
|
+
throw Oops$6.BadArgument(typeof input);
|
|
1006
|
+
if (input instanceof Map || input instanceof Set)
|
|
1007
|
+
return keyed(this, key, input);
|
|
1178
1008
|
function onUpdate(next) {
|
|
1179
1009
|
state.set(key, next);
|
|
1180
1010
|
if (next) {
|
|
@@ -1194,6 +1024,25 @@ function use$1(input, argument) {
|
|
|
1194
1024
|
});
|
|
1195
1025
|
}
|
|
1196
1026
|
|
|
1027
|
+
const Oops$5 = issues({
|
|
1028
|
+
Required: (expects, child) => `New ${child} created standalone but requires parent of type ${expects}. Did you remember to create via use(${child})?`,
|
|
1029
|
+
Unexpected: (expects, child, got) => `New ${child} created as child of ${got}, but must be instanceof ${expects}.`,
|
|
1030
|
+
});
|
|
1031
|
+
function has(Expects, required) {
|
|
1032
|
+
return apply(function parent() {
|
|
1033
|
+
const child = this.subject;
|
|
1034
|
+
const value = Parent.get(child);
|
|
1035
|
+
const expected = Expects.name;
|
|
1036
|
+
if (!value) {
|
|
1037
|
+
if (required !== false)
|
|
1038
|
+
throw Oops$5.Required(expected, child);
|
|
1039
|
+
}
|
|
1040
|
+
else if (!(value instanceof Expects))
|
|
1041
|
+
throw Oops$5.Unexpected(expected, child, value);
|
|
1042
|
+
return { value };
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1197
1046
|
class Lookup {
|
|
1198
1047
|
constructor() {
|
|
1199
1048
|
this.table = new Map();
|
|
@@ -1478,12 +1327,12 @@ class MVC extends Model {
|
|
|
1478
1327
|
});
|
|
1479
1328
|
return instance;
|
|
1480
1329
|
}, []);
|
|
1481
|
-
usePeerContext(instance.
|
|
1330
|
+
usePeerContext(instance.is);
|
|
1482
1331
|
return instance;
|
|
1483
1332
|
}
|
|
1484
1333
|
static use(a, b) {
|
|
1485
1334
|
const instance = useModel(this, a, b);
|
|
1486
|
-
usePeerContext(instance.
|
|
1335
|
+
usePeerContext(instance.is);
|
|
1487
1336
|
return instance;
|
|
1488
1337
|
}
|
|
1489
1338
|
/**
|
|
@@ -1627,10 +1476,9 @@ exports.STATE = STATE;
|
|
|
1627
1476
|
exports.WHY = WHY;
|
|
1628
1477
|
exports.act = act;
|
|
1629
1478
|
exports.apply = apply;
|
|
1630
|
-
exports.array = array;
|
|
1631
1479
|
exports["default"] = MVC;
|
|
1632
|
-
exports.
|
|
1633
|
-
exports.
|
|
1480
|
+
exports.get = get;
|
|
1481
|
+
exports.has = has;
|
|
1634
1482
|
exports.put = put;
|
|
1635
1483
|
exports.ref = ref;
|
|
1636
1484
|
exports.set = set;
|