@expressive/mvc 0.2.4 → 0.3.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 +43 -47
- package/lib/index.esm.js +144 -117
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +144 -116
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ declare function array<T = any>(): T[];
|
|
|
23
23
|
type Callback = () => void;
|
|
24
24
|
type Class = new (...args: any[]) => any;
|
|
25
25
|
type InstanceOf<T> = T extends { prototype: infer U } ? U : never;
|
|
26
|
-
type RequestCallback<T extends string = string> = (keys: readonly T[]) => void;
|
|
27
26
|
|
|
28
27
|
declare type Listener = {
|
|
29
28
|
commit(): void;
|
|
@@ -136,7 +135,7 @@ declare class Model {
|
|
|
136
135
|
constructor();
|
|
137
136
|
get [STATE](): this;
|
|
138
137
|
get [WHY](): readonly string[] | undefined;
|
|
139
|
-
on<P = Model.Event<this>>(event: (key: P) =>
|
|
138
|
+
on<P = Model.Event<this>>(event: (key: P) => Callback | void): Callback;
|
|
140
139
|
on<P = Model.Event<this>>(keys: [], listener: Model.OnUpdate<this, P>, squash?: boolean, once?: boolean): Callback;
|
|
141
140
|
on<P = Model.Event<this>>(keys: [], listener: (keys: P[]) => void, squash: true, once?: boolean): Callback;
|
|
142
141
|
on(keys: [], listener: unknown, squash: boolean, once?: boolean): Callback;
|
|
@@ -186,16 +185,16 @@ declare class Model {
|
|
|
186
185
|
}
|
|
187
186
|
|
|
188
187
|
declare namespace Controller {
|
|
189
|
-
type OnEvent<T = any> = (key: Model.Event<T>, source: Controller) => RequestCallback | void;
|
|
190
188
|
type OnValue<T = any, S = Model.Values<T>> = (this: T, value: any, state: S) => boolean | void;
|
|
189
|
+
type OnEvent<T = any> = (key: Model.Event<T>, source: Controller) => Callback | void;
|
|
191
190
|
}
|
|
192
191
|
declare class Controller<T extends Stateful = any> {
|
|
193
192
|
subject: T;
|
|
194
193
|
proxy: Model.Entries<T>;
|
|
195
194
|
state: Model.Values<T, Exclude<keyof T & string, keyof Model>>;
|
|
196
195
|
frame: Set<string>;
|
|
197
|
-
waiting: Set<RequestCallback<string>>;
|
|
198
196
|
onDestroy: Set<Callback>;
|
|
197
|
+
private waiting;
|
|
199
198
|
protected followers: Set<Model.Controller.OnEvent<any>>;
|
|
200
199
|
constructor(subject: T);
|
|
201
200
|
start(): void;
|
|
@@ -203,13 +202,13 @@ declare class Controller<T extends Stateful = any> {
|
|
|
203
202
|
manage(key: Model.Field<T>, value: any): void;
|
|
204
203
|
ref(key: Model.Field<T>, handler?: Controller.OnValue<T>): (value: any) => void;
|
|
205
204
|
addListener(listener: Controller.OnEvent<T>): () => void;
|
|
206
|
-
emit(keys: readonly Model.Event<T>[]): void;
|
|
207
205
|
update(key: Model.Event<T>, value?: any): void;
|
|
206
|
+
flush(): void;
|
|
208
207
|
requestUpdate(): PromiseLike<readonly Model.Event<T>[] | false>;
|
|
209
208
|
requestUpdate(strict: true): Promise<readonly Model.Event<T>[]>;
|
|
210
209
|
requestUpdate(strict: false): Promise<false>;
|
|
211
210
|
requestUpdate(strict: boolean): Promise<readonly Model.Event<T>[] | false>;
|
|
212
|
-
requestUpdate(callback:
|
|
211
|
+
requestUpdate(callback: Callback): void;
|
|
213
212
|
}
|
|
214
213
|
|
|
215
214
|
/**
|
|
@@ -301,30 +300,10 @@ declare function ref<T extends Model>(target: T): ref.Proxy<T>;
|
|
|
301
300
|
declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>;
|
|
302
301
|
declare function ref<T, S>(callback?: ref.Callback<T, S>): ref.Object<T>;
|
|
303
302
|
|
|
304
|
-
declare namespace set {
|
|
303
|
+
declare namespace set$1 {
|
|
305
304
|
type Factory<T, S = unknown> = (this: S, key: string, subject: S) => T;
|
|
306
305
|
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
307
306
|
}
|
|
308
|
-
/**
|
|
309
|
-
* Set property with a placeholder.
|
|
310
|
-
*
|
|
311
|
-
* Property cannot be accessed until it is defined. If accessed while undefined, a hybrid
|
|
312
|
-
* `Promise`/`Error` (ala: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.
|
|
313
|
-
*/
|
|
314
|
-
declare function set<T = any>(): T;
|
|
315
|
-
/**
|
|
316
|
-
* Set property with starting value `undefined`.
|
|
317
|
-
*
|
|
318
|
-
* If required and accessed while still empty, React Suspense will be thrown.
|
|
319
|
-
* Property will reject any assignment of undefined.
|
|
320
|
-
*
|
|
321
|
-
* @param value - Starting value of host property (undefined).
|
|
322
|
-
* @param required - Property will suspend callee if undefined at time of access.
|
|
323
|
-
*/
|
|
324
|
-
declare function set<T>(value: undefined, required: false): T | undefined;
|
|
325
|
-
declare function set<T>(value: undefined, required?: boolean): T;
|
|
326
|
-
declare function set<T>(value: undefined, onUpdate: set.Callback<T>): T | undefined;
|
|
327
|
-
declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T | undefined;
|
|
328
307
|
/**
|
|
329
308
|
* Set property with an async function.
|
|
330
309
|
*
|
|
@@ -340,12 +319,12 @@ declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T |
|
|
|
340
319
|
* @param factory - Callback run to derrive property value.
|
|
341
320
|
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
342
321
|
*/
|
|
343
|
-
declare function
|
|
344
|
-
declare function
|
|
345
|
-
declare function
|
|
346
|
-
declare function
|
|
347
|
-
declare function
|
|
348
|
-
declare function
|
|
322
|
+
declare function put<T>(factory: set$1.Factory<Promise<T>>, required: false): T | undefined;
|
|
323
|
+
declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required: false): T | undefined;
|
|
324
|
+
declare function put<T>(factory: set$1.Factory<Promise<T>>, required?: boolean): T;
|
|
325
|
+
declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required?: boolean): T;
|
|
326
|
+
declare function put<T>(value: set$1.Factory<Promise<T>>, onUpdate: set$1.Callback<T>): T;
|
|
327
|
+
declare function put<T, S>(value: set$1.Factory<Promise<T>, S>, onUpdate: set$1.Callback<T, S>): T;
|
|
349
328
|
/**
|
|
350
329
|
* Set property with a factory function.
|
|
351
330
|
*
|
|
@@ -358,24 +337,41 @@ declare function set<T, S>(value: set.Factory<Promise<T>, S>, onUpdate: set.Call
|
|
|
358
337
|
* @param factory - Callback run to derrive property value.
|
|
359
338
|
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
360
339
|
*/
|
|
361
|
-
declare function
|
|
362
|
-
declare function
|
|
363
|
-
declare function
|
|
364
|
-
declare function
|
|
365
|
-
declare function
|
|
366
|
-
declare function
|
|
340
|
+
declare function put<T>(factory: set$1.Factory<T>, required: false): T | undefined;
|
|
341
|
+
declare function put<T, S>(factory: set$1.Factory<T, S>, required: false): T | undefined;
|
|
342
|
+
declare function put<T>(factory: set$1.Factory<T>, required?: boolean): T;
|
|
343
|
+
declare function put<T, S>(factory: set$1.Factory<T, S>, required?: boolean): T;
|
|
344
|
+
declare function put<T>(value: set$1.Factory<T>, onUpdate: set$1.Callback<T>): T;
|
|
345
|
+
declare function put<T, S>(value: set$1.Factory<T, S>, onUpdate: set$1.Callback<T, S>): T;
|
|
367
346
|
/**
|
|
368
347
|
* Assign a property with result of a promise.
|
|
369
348
|
*/
|
|
370
|
-
declare function
|
|
371
|
-
declare function
|
|
372
|
-
declare function
|
|
349
|
+
declare function put<T>(factory: Promise<T>, required: false): T | undefined;
|
|
350
|
+
declare function put<T>(factory: Promise<T>, required?: boolean): T;
|
|
351
|
+
declare function put<T>(value: Promise<T>, onUpdate: set$1.Callback<T>): T;
|
|
373
352
|
/**
|
|
374
353
|
* Assign a property.
|
|
375
354
|
*/
|
|
376
|
-
declare function
|
|
377
|
-
declare function
|
|
355
|
+
declare function put<T>(factory: T, required: false): T | undefined;
|
|
356
|
+
declare function put<T>(factory: T, required?: boolean): T;
|
|
357
|
+
declare function put<T>(value: T, onUpdate: set$1.Callback<T>): T;
|
|
358
|
+
|
|
359
|
+
declare namespace set {
|
|
360
|
+
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Set property with a placeholder.
|
|
364
|
+
*
|
|
365
|
+
* Property cannot be accessed until it is defined. If accessed while undefined, a hybrid
|
|
366
|
+
* `Promise`/`Error` (ala: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.
|
|
367
|
+
*/
|
|
368
|
+
declare function set<T = any>(): T;
|
|
369
|
+
declare function set<T>(onUpdate: set.Callback<T>): T;
|
|
370
|
+
declare function set<T, S>(onUpdate: set.Callback<T, S>): T;
|
|
371
|
+
declare function set<T>(value: undefined, onUpdate: set.Callback<T>): T;
|
|
372
|
+
declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T;
|
|
378
373
|
declare function set<T>(value: T, onUpdate: set.Callback<T>): T;
|
|
374
|
+
declare function set<T, S>(value: T, onUpdate: set.Callback<T, S>): T;
|
|
379
375
|
|
|
380
376
|
/**
|
|
381
377
|
* Create a placeholder for specified Model type.
|
|
@@ -574,13 +570,13 @@ declare class Global extends MVC {
|
|
|
574
570
|
*
|
|
575
571
|
* @param required - If false, may return undefined.
|
|
576
572
|
*/
|
|
577
|
-
static get<T extends Class>(this: T, required
|
|
573
|
+
static get<T extends Class>(this: T, required: false): InstanceOf<T> | undefined;
|
|
578
574
|
/**
|
|
579
575
|
* **React Hook** - Fetch most instance of this controller from context.
|
|
580
576
|
*
|
|
581
577
|
* @param required - Unless false, will throw where instance cannot be found.
|
|
582
578
|
*/
|
|
583
|
-
static get<T extends Class>(this: T, required
|
|
579
|
+
static get<T extends Class>(this: T, required?: boolean): InstanceOf<T>;
|
|
584
580
|
/**
|
|
585
581
|
* **React Hook** - Fetch specific value from instance of this controller in context.
|
|
586
582
|
*/
|
|
@@ -643,4 +639,4 @@ declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T
|
|
|
643
639
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
644
640
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
645
641
|
|
|
646
|
-
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, array, MVC as default, from, parent, ref, set, tap, use, useFrom, useLocal, useModel, useTap };
|
|
642
|
+
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, array, MVC as default, from, parent, put, ref, set, tap, use, useFrom, useLocal, useModel, useTap };
|
package/lib/index.esm.js
CHANGED
|
@@ -140,6 +140,9 @@ function applyUpdate(subject, keys) {
|
|
|
140
140
|
UPDATE.delete(subject);
|
|
141
141
|
}, 0);
|
|
142
142
|
};
|
|
143
|
+
}
|
|
144
|
+
function getUpdate(subject) {
|
|
145
|
+
return UPDATE.get(subject);
|
|
143
146
|
}
|
|
144
147
|
|
|
145
148
|
const CONTROL = Symbol("CONTROL");
|
|
@@ -171,21 +174,30 @@ class Model {
|
|
|
171
174
|
return control(this, control => {
|
|
172
175
|
if (typeof select == "function")
|
|
173
176
|
return control.addListener(select);
|
|
174
|
-
const
|
|
177
|
+
const selection = typeof select == "string" ? [select] :
|
|
175
178
|
!select.length ? getOwnPropertyNames(control.state) :
|
|
176
179
|
select;
|
|
177
|
-
ensure(control,
|
|
180
|
+
ensure(control, selection);
|
|
178
181
|
const callback = squash
|
|
179
|
-
?
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
? () => {
|
|
183
|
+
handler.call(this, getUpdate(this));
|
|
184
|
+
}
|
|
185
|
+
: () => {
|
|
186
|
+
getUpdate(this)
|
|
187
|
+
.filter(k => selection.includes(k))
|
|
188
|
+
.forEach(k => {
|
|
189
|
+
handler.call(this, control.state[k], k);
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
const onEvent = once
|
|
193
|
+
? () => {
|
|
194
|
+
remove();
|
|
195
|
+
callback();
|
|
196
|
+
}
|
|
185
197
|
: callback;
|
|
186
198
|
const remove = control.addListener(key => {
|
|
187
|
-
if (
|
|
188
|
-
return
|
|
199
|
+
if (selection.includes(key))
|
|
200
|
+
return onEvent;
|
|
189
201
|
});
|
|
190
202
|
return remove;
|
|
191
203
|
});
|
|
@@ -201,7 +213,7 @@ class Model {
|
|
|
201
213
|
const effect = createEffect(callback);
|
|
202
214
|
return control(this, control => {
|
|
203
215
|
let busy = false;
|
|
204
|
-
let inject = this.
|
|
216
|
+
let inject = this.is;
|
|
205
217
|
const invoke = () => {
|
|
206
218
|
if (busy)
|
|
207
219
|
return;
|
|
@@ -306,6 +318,7 @@ class Subscriber {
|
|
|
306
318
|
this.watch = {};
|
|
307
319
|
const parent = target instanceof Controller
|
|
308
320
|
? target : control(target);
|
|
321
|
+
const subject = parent.subject;
|
|
309
322
|
const proxy = create(parent.proxy);
|
|
310
323
|
let reset;
|
|
311
324
|
define(proxy, LOCAL, this);
|
|
@@ -324,8 +337,10 @@ class Subscriber {
|
|
|
324
337
|
if (typeof handler == "function")
|
|
325
338
|
handler();
|
|
326
339
|
const notify = this.onUpdate(key, parent);
|
|
327
|
-
const getWhy = (
|
|
328
|
-
|
|
340
|
+
const getWhy = () => {
|
|
341
|
+
const update = getUpdate(subject);
|
|
342
|
+
const applicable = update.filter(k => k in this.watch);
|
|
343
|
+
reset = applyUpdate(proxy, applicable);
|
|
329
344
|
};
|
|
330
345
|
if (notify) {
|
|
331
346
|
parent.requestUpdate(getWhy);
|
|
@@ -410,9 +425,9 @@ function from(source, arg1, arg2) {
|
|
|
410
425
|
}
|
|
411
426
|
}
|
|
412
427
|
function defer(_key, from) {
|
|
413
|
-
let pending = KEYS.get(from);
|
|
428
|
+
let pending = KEYS.get(from.frame);
|
|
414
429
|
if (!pending)
|
|
415
|
-
KEYS.set(from, pending = []);
|
|
430
|
+
KEYS.set(from.frame, pending = []);
|
|
416
431
|
if (info.parent !== from)
|
|
417
432
|
update();
|
|
418
433
|
else {
|
|
@@ -466,19 +481,17 @@ function ensure(on, keys) {
|
|
|
466
481
|
getter(true);
|
|
467
482
|
}
|
|
468
483
|
}
|
|
469
|
-
function flush(
|
|
470
|
-
const
|
|
471
|
-
const pending = KEYS.get(on);
|
|
484
|
+
function flush(frame) {
|
|
485
|
+
const pending = KEYS.get(frame);
|
|
472
486
|
if (!pending)
|
|
473
487
|
return;
|
|
474
488
|
while (pending.length) {
|
|
475
|
-
const why = [...handled];
|
|
476
489
|
const compute = pending.shift();
|
|
477
490
|
const { key } = INFO.get(compute);
|
|
478
|
-
if (!
|
|
479
|
-
compute(
|
|
491
|
+
if (!frame.has(key))
|
|
492
|
+
compute();
|
|
480
493
|
}
|
|
481
|
-
KEYS.delete(
|
|
494
|
+
KEYS.delete(frame);
|
|
482
495
|
}
|
|
483
496
|
|
|
484
497
|
const Oops$9 = issues({
|
|
@@ -492,41 +505,41 @@ class Controller {
|
|
|
492
505
|
this.subject = subject;
|
|
493
506
|
this.state = {};
|
|
494
507
|
this.frame = new Set();
|
|
495
|
-
this.waiting = new Set();
|
|
496
508
|
this.onDestroy = new Set();
|
|
509
|
+
this.waiting = new Set();
|
|
497
510
|
this.followers = new Set();
|
|
498
511
|
this.proxy = Object.create(subject);
|
|
499
512
|
}
|
|
500
513
|
start() {
|
|
501
514
|
READY.add(this);
|
|
502
515
|
for (const key in this.subject) {
|
|
503
|
-
const { value
|
|
504
|
-
if (typeof
|
|
516
|
+
const { value } = getOwnPropertyDescriptor(this.subject, key);
|
|
517
|
+
if (typeof value == "function")
|
|
505
518
|
continue;
|
|
506
|
-
if (typeof
|
|
507
|
-
const instruction = PENDING.get(
|
|
519
|
+
if (typeof value == "symbol") {
|
|
520
|
+
const instruction = PENDING.get(value);
|
|
508
521
|
if (instruction)
|
|
509
522
|
instruction.call(this, key, this);
|
|
510
523
|
continue;
|
|
511
524
|
}
|
|
512
|
-
this.manage(key,
|
|
525
|
+
this.manage(key, value);
|
|
513
526
|
}
|
|
514
|
-
this.
|
|
527
|
+
this.flush();
|
|
515
528
|
}
|
|
516
529
|
stop() {
|
|
517
530
|
this.followers.clear();
|
|
518
531
|
this.onDestroy.forEach(x => x());
|
|
519
532
|
}
|
|
520
533
|
manage(key, value) {
|
|
521
|
-
const {
|
|
522
|
-
state[key] = value;
|
|
534
|
+
const { state } = this;
|
|
523
535
|
const set = this.ref(key);
|
|
524
|
-
|
|
536
|
+
state[key] = value;
|
|
537
|
+
defineProperty(this.subject, key, {
|
|
525
538
|
enumerable: false,
|
|
526
539
|
get: () => state[key],
|
|
527
540
|
set
|
|
528
541
|
});
|
|
529
|
-
defineProperty(proxy, key, {
|
|
542
|
+
defineProperty(this.proxy, key, {
|
|
530
543
|
enumerable: false,
|
|
531
544
|
get() {
|
|
532
545
|
const local = this[LOCAL];
|
|
@@ -558,53 +571,56 @@ class Controller {
|
|
|
558
571
|
this.followers.delete(listener);
|
|
559
572
|
};
|
|
560
573
|
}
|
|
561
|
-
emit(keys) {
|
|
562
|
-
const waiting = [...this.waiting];
|
|
563
|
-
this.waiting.clear();
|
|
564
|
-
applyUpdate(this.subject, keys)();
|
|
565
|
-
for (const callback of waiting)
|
|
566
|
-
try {
|
|
567
|
-
callback(keys);
|
|
568
|
-
}
|
|
569
|
-
catch (err) {
|
|
570
|
-
console.error(err);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
574
|
update(key, value) {
|
|
575
|
+
const { frame } = this;
|
|
574
576
|
if (1 in arguments)
|
|
575
577
|
this.state[key] = value;
|
|
576
|
-
if (
|
|
577
|
-
return;
|
|
578
|
-
if (!this.frame.size)
|
|
578
|
+
if (!frame.size)
|
|
579
579
|
setTimeout(() => {
|
|
580
|
-
flush(
|
|
581
|
-
|
|
582
|
-
this.frame.clear();
|
|
583
|
-
this.emit(keys);
|
|
580
|
+
flush(frame);
|
|
581
|
+
this.flush();
|
|
584
582
|
}, 0);
|
|
585
|
-
|
|
583
|
+
else if (frame.has(key))
|
|
584
|
+
return;
|
|
585
|
+
frame.add(key);
|
|
586
586
|
for (const callback of this.followers) {
|
|
587
587
|
const event = callback(key, this);
|
|
588
588
|
if (typeof event == "function")
|
|
589
589
|
this.waiting.add(event);
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
|
+
flush() {
|
|
593
|
+
const waiting = Array.from(this.waiting);
|
|
594
|
+
const keys = Array.from(this.frame);
|
|
595
|
+
this.frame.clear();
|
|
596
|
+
this.waiting.clear();
|
|
597
|
+
applyUpdate(this.subject, keys)();
|
|
598
|
+
for (const callback of waiting)
|
|
599
|
+
try {
|
|
600
|
+
callback();
|
|
601
|
+
}
|
|
602
|
+
catch (err) {
|
|
603
|
+
console.error(err);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
592
606
|
requestUpdate(arg) {
|
|
607
|
+
const { frame, subject, waiting } = this;
|
|
593
608
|
if (typeof arg == "function") {
|
|
594
|
-
|
|
609
|
+
waiting.add(arg);
|
|
595
610
|
return;
|
|
596
611
|
}
|
|
597
|
-
if (arg === true
|
|
612
|
+
if (!frame.size && arg === true)
|
|
598
613
|
return Promise.reject(Oops$9.StrictUpdate());
|
|
599
614
|
return {
|
|
600
615
|
then: (callback) => {
|
|
601
|
-
if (callback)
|
|
602
|
-
if (this.frame.size || arg !== false)
|
|
603
|
-
this.waiting.add(callback);
|
|
604
|
-
else
|
|
605
|
-
callback(false);
|
|
606
|
-
else
|
|
616
|
+
if (!callback)
|
|
607
617
|
throw Oops$9.NoChaining();
|
|
618
|
+
if (frame.size || arg !== false)
|
|
619
|
+
waiting.add(() => {
|
|
620
|
+
callback(getUpdate(subject));
|
|
621
|
+
});
|
|
622
|
+
else
|
|
623
|
+
callback(false);
|
|
608
624
|
}
|
|
609
625
|
};
|
|
610
626
|
}
|
|
@@ -827,65 +843,60 @@ const Oops$7 = issues({
|
|
|
827
843
|
NotReady: (model, key) => `Value ${model}.${key} value is not yet available.`,
|
|
828
844
|
Failed: (model, key) => `Generating initial value for ${model}.${key} failed.`
|
|
829
845
|
});
|
|
830
|
-
function
|
|
846
|
+
function put(factory, argument) {
|
|
831
847
|
return apply(function set(key) {
|
|
832
848
|
const { subject, state } = this;
|
|
833
849
|
const required = argument === true || argument === undefined;
|
|
834
850
|
let set;
|
|
835
851
|
let get;
|
|
836
|
-
let
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
pending =
|
|
848
|
-
|
|
849
|
-
.then(val => state[key] = val)
|
|
850
|
-
.finally(() => {
|
|
851
|
-
pending = undefined;
|
|
852
|
-
this.update(key);
|
|
853
|
-
});
|
|
854
|
-
return;
|
|
855
|
-
}
|
|
856
|
-
return state[key] = output;
|
|
857
|
-
};
|
|
858
|
-
const suspend = () => {
|
|
859
|
-
if (required === false)
|
|
860
|
-
return undefined;
|
|
861
|
-
const issue = Oops$7.NotReady(subject, key);
|
|
862
|
-
Object.assign(pending, {
|
|
863
|
-
message: issue.message,
|
|
864
|
-
stack: issue.stack
|
|
852
|
+
let pending;
|
|
853
|
+
let error;
|
|
854
|
+
const init = () => {
|
|
855
|
+
const output = typeof factory == "function" ?
|
|
856
|
+
mayRetry(() => factory.call(subject, key, subject)) :
|
|
857
|
+
factory;
|
|
858
|
+
if (output instanceof Promise) {
|
|
859
|
+
pending = output
|
|
860
|
+
.catch(err => error = err)
|
|
861
|
+
.then(val => state[key] = val)
|
|
862
|
+
.finally(() => {
|
|
863
|
+
pending = undefined;
|
|
864
|
+
this.update(key);
|
|
865
865
|
});
|
|
866
|
-
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
}
|
|
888
|
-
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
return state[key] = output;
|
|
869
|
+
};
|
|
870
|
+
const suspend = () => {
|
|
871
|
+
if (required === false)
|
|
872
|
+
return undefined;
|
|
873
|
+
const issue = Oops$7.NotReady(subject, key);
|
|
874
|
+
Object.assign(pending, {
|
|
875
|
+
message: issue.message,
|
|
876
|
+
stack: issue.stack
|
|
877
|
+
});
|
|
878
|
+
throw pending;
|
|
879
|
+
};
|
|
880
|
+
if (required)
|
|
881
|
+
try {
|
|
882
|
+
init();
|
|
883
|
+
}
|
|
884
|
+
catch (err) {
|
|
885
|
+
Oops$7.Failed(subject, key).warn();
|
|
886
|
+
throw err;
|
|
887
|
+
}
|
|
888
|
+
get = () => {
|
|
889
|
+
if (pending)
|
|
890
|
+
return suspend();
|
|
891
|
+
if (error)
|
|
892
|
+
throw error;
|
|
893
|
+
if (key in state)
|
|
894
|
+
return state[key];
|
|
895
|
+
let output = init();
|
|
896
|
+
return pending
|
|
897
|
+
? suspend()
|
|
898
|
+
: output;
|
|
899
|
+
};
|
|
889
900
|
if (typeof argument == "function")
|
|
890
901
|
set = createValueEffect(argument);
|
|
891
902
|
else
|
|
@@ -895,8 +906,24 @@ function set(factory, argument) {
|
|
|
895
906
|
};
|
|
896
907
|
return {
|
|
897
908
|
set,
|
|
898
|
-
get
|
|
899
|
-
|
|
909
|
+
get
|
|
910
|
+
};
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function set(value, argument) {
|
|
915
|
+
if (!(1 in arguments)) {
|
|
916
|
+
argument = value;
|
|
917
|
+
value = undefined;
|
|
918
|
+
}
|
|
919
|
+
return apply(function set(key) {
|
|
920
|
+
if (value !== undefined)
|
|
921
|
+
this.state[key] = value;
|
|
922
|
+
return {
|
|
923
|
+
suspense: true,
|
|
924
|
+
set: typeof argument == "function"
|
|
925
|
+
? createValueEffect(argument)
|
|
926
|
+
: undefined
|
|
900
927
|
};
|
|
901
928
|
});
|
|
902
929
|
}
|
|
@@ -1388,5 +1415,5 @@ class Global extends MVC {
|
|
|
1388
1415
|
}
|
|
1389
1416
|
}
|
|
1390
1417
|
|
|
1391
|
-
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, WHY, act, apply, array, MVC as default, from, parent, ref, set, tap, use$1 as use, useFrom, useLocal, useModel, useTap };
|
|
1418
|
+
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, WHY, act, apply, array, MVC as default, from, parent, put, ref, set, tap, use$1 as use, useFrom, useLocal, useModel, useTap };
|
|
1392
1419
|
//# sourceMappingURL=index.esm.js.map
|