@expressive/mvc 0.30.0 → 0.32.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 +1 -1
- package/lib/index.esm.js +29 -24
- package/lib/index.js +29 -24
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ interface Observable {
|
|
|
71
71
|
get(effect: Model.Effect<this>): Callback;
|
|
72
72
|
set(): Promise<Model.Event<this>[]>;
|
|
73
73
|
set(timeout: number): Promise<Model.Event<this>[] | false>;
|
|
74
|
-
set<T extends Model.Values<this>>(
|
|
74
|
+
set<T extends Model.Values<this>>(from: T, only?: (keyof T)[]): Promise<Model.Event<T>[] | false>;
|
|
75
75
|
set<K extends Model.Key<this>>(key: K, value: Model.Value<this[K]>): Promise<Model.Event<this>[] | false>;
|
|
76
76
|
set<K extends Model.Event<this>>(key: K): Promise<Model.Event<this>[] | false>;
|
|
77
77
|
}
|
package/lib/index.esm.js
CHANGED
|
@@ -42,7 +42,7 @@ function issues(register) {
|
|
|
42
42
|
|
|
43
43
|
const { assign, create, defineProperties, defineProperty, entries, keys, getPrototypeOf, getOwnPropertyDescriptor, getOwnPropertySymbols, values } = Object;
|
|
44
44
|
|
|
45
|
-
const Oops$
|
|
45
|
+
const Oops$8 = issues({
|
|
46
46
|
NotFound: (name) => `Could not find ${name} in context.`
|
|
47
47
|
});
|
|
48
48
|
function get$1(argument) {
|
|
@@ -57,7 +57,7 @@ function get$1(argument) {
|
|
|
57
57
|
? Control.watch(got, k => k ? onUpdate : undefined)
|
|
58
58
|
: got;
|
|
59
59
|
else if (argument !== false)
|
|
60
|
-
throw Oops$
|
|
60
|
+
throw Oops$8.NotFound(this);
|
|
61
61
|
return {
|
|
62
62
|
mount() {
|
|
63
63
|
onUpdate = refresh;
|
|
@@ -73,7 +73,7 @@ function get$1(argument) {
|
|
|
73
73
|
let proxy;
|
|
74
74
|
const found = context.get(this);
|
|
75
75
|
if (!found)
|
|
76
|
-
throw Oops$
|
|
76
|
+
throw Oops$8.NotFound(this);
|
|
77
77
|
function forceUpdate(action) {
|
|
78
78
|
if (typeof action == "function")
|
|
79
79
|
action = action();
|
|
@@ -172,12 +172,12 @@ function use$1(apply, repeat) {
|
|
|
172
172
|
return render(apply);
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
const Oops$
|
|
175
|
+
const Oops$7 = issues({
|
|
176
176
|
NotReady: (model, key) => `Value ${model}.${key} value is not yet available.`,
|
|
177
177
|
Destoryed: () => "Model is destroyed."
|
|
178
178
|
});
|
|
179
179
|
function suspense(source, key) {
|
|
180
|
-
const error = Oops$
|
|
180
|
+
const error = Oops$7.NotReady(source.subject, key);
|
|
181
181
|
const watch = source.observers.get(key);
|
|
182
182
|
const promise = new Promise((resolve, reject) => {
|
|
183
183
|
function onUpdate(key) {
|
|
@@ -189,7 +189,7 @@ function suspense(source, key) {
|
|
|
189
189
|
}
|
|
190
190
|
};
|
|
191
191
|
if (key === null)
|
|
192
|
-
reject(Oops$
|
|
192
|
+
reject(Oops$7.Destoryed());
|
|
193
193
|
}
|
|
194
194
|
watch.add(onUpdate);
|
|
195
195
|
});
|
|
@@ -221,7 +221,7 @@ function mayRetry(fn) {
|
|
|
221
221
|
return compute();
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
const Oops$
|
|
224
|
+
const Oops$6 = issues({
|
|
225
225
|
BadCallback: () => `Callback for effect-callback may only return a function.`
|
|
226
226
|
});
|
|
227
227
|
function createEffect(source, callback) {
|
|
@@ -239,7 +239,7 @@ function createEffect(source, callback) {
|
|
|
239
239
|
if (unSet instanceof Promise)
|
|
240
240
|
unSet = undefined;
|
|
241
241
|
if (unSet && typeof unSet !== "function")
|
|
242
|
-
throw Oops$
|
|
242
|
+
throw Oops$6.BadCallback();
|
|
243
243
|
});
|
|
244
244
|
if (output instanceof Promise) {
|
|
245
245
|
output.finally(() => busy = false);
|
|
@@ -269,7 +269,7 @@ function createValueEffect(callback, ignoreNull) {
|
|
|
269
269
|
if (typeof out == "function")
|
|
270
270
|
unSet = out;
|
|
271
271
|
else
|
|
272
|
-
throw Oops$
|
|
272
|
+
throw Oops$6.BadCallback();
|
|
273
273
|
};
|
|
274
274
|
}
|
|
275
275
|
|
|
@@ -425,7 +425,7 @@ function uid() {
|
|
|
425
425
|
return (Math.random() * 0.722 + 0.278).toString(36).substring(2, 8).toUpperCase();
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
-
const Oops$
|
|
428
|
+
const Oops$5 = issues({
|
|
429
429
|
BadAssignment: (parent, expected, got) => `${parent} expected Model of type ${expected} but got ${got}.`,
|
|
430
430
|
});
|
|
431
431
|
const REGISTER = new WeakMap();
|
|
@@ -553,9 +553,9 @@ function control(subject, ready) {
|
|
|
553
553
|
return () => done && done();
|
|
554
554
|
}
|
|
555
555
|
if (pending && ready) {
|
|
556
|
-
PENDING$1.delete(control);
|
|
557
556
|
for (const key in control.subject)
|
|
558
557
|
control.add(key);
|
|
558
|
+
PENDING$1.delete(control);
|
|
559
559
|
pending.forEach(cb => cb(control));
|
|
560
560
|
}
|
|
561
561
|
return control;
|
|
@@ -586,7 +586,7 @@ function setRecursive(on, key, value) {
|
|
|
586
586
|
control(next, true);
|
|
587
587
|
return true;
|
|
588
588
|
}
|
|
589
|
-
throw Oops$
|
|
589
|
+
throw Oops$5.BadAssignment(`${on.subject}.${key}`, value.constructor, next);
|
|
590
590
|
};
|
|
591
591
|
on.watch(key, { set });
|
|
592
592
|
set(value);
|
|
@@ -616,7 +616,7 @@ function apply(instruction) {
|
|
|
616
616
|
return placeholder;
|
|
617
617
|
}
|
|
618
618
|
|
|
619
|
-
const Oops$
|
|
619
|
+
const Oops$4 = issues({
|
|
620
620
|
DuplicatePending: (key) => `Invoked action ${key} but one is already active.`
|
|
621
621
|
});
|
|
622
622
|
function run(task) {
|
|
@@ -624,7 +624,7 @@ function run(task) {
|
|
|
624
624
|
let pending = false;
|
|
625
625
|
const invoke = (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
626
626
|
if (pending)
|
|
627
|
-
return Promise.reject(Oops$
|
|
627
|
+
return Promise.reject(Oops$4.DuplicatePending(key));
|
|
628
628
|
pending = true;
|
|
629
629
|
control.update(key);
|
|
630
630
|
try {
|
|
@@ -646,7 +646,7 @@ function run(task) {
|
|
|
646
646
|
});
|
|
647
647
|
}
|
|
648
648
|
|
|
649
|
-
const Oops$
|
|
649
|
+
const Oops$3 = issues({
|
|
650
650
|
PeerNotAllowed: (model, property) => `Attempted to use an instruction result (probably use or get) as computed source for ${model}.${property}. This is not allowed.`,
|
|
651
651
|
Failed: (parent, property, initial) => `An exception was thrown while ${initial ? "initializing" : "refreshing"} ${parent}.${property}.`,
|
|
652
652
|
Required: (expects, child) => `New ${child} created standalone but requires parent of type ${expects}.`,
|
|
@@ -657,7 +657,7 @@ function get(arg0, arg1) {
|
|
|
657
657
|
return apply((key, control) => {
|
|
658
658
|
let { subject } = control;
|
|
659
659
|
if (typeof arg0 == "symbol")
|
|
660
|
-
throw Oops$
|
|
660
|
+
throw Oops$3.PeerNotAllowed(subject, key);
|
|
661
661
|
let source = cb => cb(subject);
|
|
662
662
|
if (arg0 instanceof Model)
|
|
663
663
|
subject = arg0;
|
|
@@ -665,7 +665,7 @@ function get(arg0, arg1) {
|
|
|
665
665
|
const hasParent = parent(subject);
|
|
666
666
|
if (!hasParent) {
|
|
667
667
|
if (arg1 === true)
|
|
668
|
-
throw Oops$
|
|
668
|
+
throw Oops$3.Required(arg0, subject);
|
|
669
669
|
const fetch = Control.has(subject);
|
|
670
670
|
source = got => {
|
|
671
671
|
fetch(context => {
|
|
@@ -673,14 +673,14 @@ function get(arg0, arg1) {
|
|
|
673
673
|
if (model)
|
|
674
674
|
got(model);
|
|
675
675
|
else if (arg1 !== false)
|
|
676
|
-
throw Oops$
|
|
676
|
+
throw Oops$3.AmbientRequired(arg0, subject);
|
|
677
677
|
});
|
|
678
678
|
};
|
|
679
679
|
}
|
|
680
680
|
else if (!arg0 || hasParent instanceof arg0)
|
|
681
681
|
subject = hasParent;
|
|
682
682
|
else
|
|
683
|
-
throw Oops$
|
|
683
|
+
throw Oops$3.Unexpected(arg0, subject, hasParent);
|
|
684
684
|
}
|
|
685
685
|
else if (typeof arg0 == "function")
|
|
686
686
|
arg1 = arg0.call(subject, key, subject);
|
|
@@ -723,7 +723,7 @@ function computed(parent, key, source, setter) {
|
|
|
723
723
|
next = setter.call(proxy, proxy);
|
|
724
724
|
}
|
|
725
725
|
catch (err) {
|
|
726
|
-
Oops$
|
|
726
|
+
Oops$3.Failed(parent.subject, key, initial).warn();
|
|
727
727
|
if (initial)
|
|
728
728
|
throw err;
|
|
729
729
|
console.error(err);
|
|
@@ -779,11 +779,18 @@ function flushComputed() {
|
|
|
779
779
|
}
|
|
780
780
|
Control.before.add(flushComputed);
|
|
781
781
|
|
|
782
|
+
const Oops$2 = issues({
|
|
783
|
+
BadRefObject: () => `ref instruction does not support object which is not 'this'`
|
|
784
|
+
});
|
|
782
785
|
function ref(arg, arg2) {
|
|
783
786
|
return apply((key, source) => {
|
|
784
787
|
let value = {};
|
|
785
|
-
if (typeof arg
|
|
786
|
-
|
|
788
|
+
if (typeof arg != "object")
|
|
789
|
+
value = createRef(source, key, arg && createValueEffect(arg, arg2 !== false));
|
|
790
|
+
else if (arg !== source.subject)
|
|
791
|
+
throw Oops$2.BadRefObject();
|
|
792
|
+
else
|
|
793
|
+
for (const key in source.state)
|
|
787
794
|
defineProperty(value, key, typeof arg2 == "function" ? {
|
|
788
795
|
configurable: true,
|
|
789
796
|
get() {
|
|
@@ -794,8 +801,6 @@ function ref(arg, arg2) {
|
|
|
794
801
|
} : {
|
|
795
802
|
value: createRef(source, key)
|
|
796
803
|
});
|
|
797
|
-
else
|
|
798
|
-
value = createRef(source, key, arg && createValueEffect(arg, arg2 !== false));
|
|
799
804
|
source.state[key] = undefined;
|
|
800
805
|
source.observers.set(key, new Set());
|
|
801
806
|
defineProperty(source.subject, key, { value });
|
package/lib/index.js
CHANGED
|
@@ -46,7 +46,7 @@ function issues(register) {
|
|
|
46
46
|
|
|
47
47
|
const { assign, create, defineProperties, defineProperty, entries, keys, getPrototypeOf, getOwnPropertyDescriptor, getOwnPropertySymbols, values } = Object;
|
|
48
48
|
|
|
49
|
-
const Oops$
|
|
49
|
+
const Oops$8 = issues({
|
|
50
50
|
NotFound: (name) => `Could not find ${name} in context.`
|
|
51
51
|
});
|
|
52
52
|
function get$1(argument) {
|
|
@@ -61,7 +61,7 @@ function get$1(argument) {
|
|
|
61
61
|
? Control.watch(got, k => k ? onUpdate : undefined)
|
|
62
62
|
: got;
|
|
63
63
|
else if (argument !== false)
|
|
64
|
-
throw Oops$
|
|
64
|
+
throw Oops$8.NotFound(this);
|
|
65
65
|
return {
|
|
66
66
|
mount() {
|
|
67
67
|
onUpdate = refresh;
|
|
@@ -77,7 +77,7 @@ function get$1(argument) {
|
|
|
77
77
|
let proxy;
|
|
78
78
|
const found = context.get(this);
|
|
79
79
|
if (!found)
|
|
80
|
-
throw Oops$
|
|
80
|
+
throw Oops$8.NotFound(this);
|
|
81
81
|
function forceUpdate(action) {
|
|
82
82
|
if (typeof action == "function")
|
|
83
83
|
action = action();
|
|
@@ -176,12 +176,12 @@ function use$1(apply, repeat) {
|
|
|
176
176
|
return render(apply);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
const Oops$
|
|
179
|
+
const Oops$7 = issues({
|
|
180
180
|
NotReady: (model, key) => `Value ${model}.${key} value is not yet available.`,
|
|
181
181
|
Destoryed: () => "Model is destroyed."
|
|
182
182
|
});
|
|
183
183
|
function suspense(source, key) {
|
|
184
|
-
const error = Oops$
|
|
184
|
+
const error = Oops$7.NotReady(source.subject, key);
|
|
185
185
|
const watch = source.observers.get(key);
|
|
186
186
|
const promise = new Promise((resolve, reject) => {
|
|
187
187
|
function onUpdate(key) {
|
|
@@ -193,7 +193,7 @@ function suspense(source, key) {
|
|
|
193
193
|
}
|
|
194
194
|
};
|
|
195
195
|
if (key === null)
|
|
196
|
-
reject(Oops$
|
|
196
|
+
reject(Oops$7.Destoryed());
|
|
197
197
|
}
|
|
198
198
|
watch.add(onUpdate);
|
|
199
199
|
});
|
|
@@ -225,7 +225,7 @@ function mayRetry(fn) {
|
|
|
225
225
|
return compute();
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
const Oops$
|
|
228
|
+
const Oops$6 = issues({
|
|
229
229
|
BadCallback: () => `Callback for effect-callback may only return a function.`
|
|
230
230
|
});
|
|
231
231
|
function createEffect(source, callback) {
|
|
@@ -243,7 +243,7 @@ function createEffect(source, callback) {
|
|
|
243
243
|
if (unSet instanceof Promise)
|
|
244
244
|
unSet = undefined;
|
|
245
245
|
if (unSet && typeof unSet !== "function")
|
|
246
|
-
throw Oops$
|
|
246
|
+
throw Oops$6.BadCallback();
|
|
247
247
|
});
|
|
248
248
|
if (output instanceof Promise) {
|
|
249
249
|
output.finally(() => busy = false);
|
|
@@ -273,7 +273,7 @@ function createValueEffect(callback, ignoreNull) {
|
|
|
273
273
|
if (typeof out == "function")
|
|
274
274
|
unSet = out;
|
|
275
275
|
else
|
|
276
|
-
throw Oops$
|
|
276
|
+
throw Oops$6.BadCallback();
|
|
277
277
|
};
|
|
278
278
|
}
|
|
279
279
|
|
|
@@ -429,7 +429,7 @@ function uid() {
|
|
|
429
429
|
return (Math.random() * 0.722 + 0.278).toString(36).substring(2, 8).toUpperCase();
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
-
const Oops$
|
|
432
|
+
const Oops$5 = issues({
|
|
433
433
|
BadAssignment: (parent, expected, got) => `${parent} expected Model of type ${expected} but got ${got}.`,
|
|
434
434
|
});
|
|
435
435
|
const REGISTER = new WeakMap();
|
|
@@ -557,9 +557,9 @@ function control(subject, ready) {
|
|
|
557
557
|
return () => done && done();
|
|
558
558
|
}
|
|
559
559
|
if (pending && ready) {
|
|
560
|
-
PENDING$1.delete(control);
|
|
561
560
|
for (const key in control.subject)
|
|
562
561
|
control.add(key);
|
|
562
|
+
PENDING$1.delete(control);
|
|
563
563
|
pending.forEach(cb => cb(control));
|
|
564
564
|
}
|
|
565
565
|
return control;
|
|
@@ -590,7 +590,7 @@ function setRecursive(on, key, value) {
|
|
|
590
590
|
control(next, true);
|
|
591
591
|
return true;
|
|
592
592
|
}
|
|
593
|
-
throw Oops$
|
|
593
|
+
throw Oops$5.BadAssignment(`${on.subject}.${key}`, value.constructor, next);
|
|
594
594
|
};
|
|
595
595
|
on.watch(key, { set });
|
|
596
596
|
set(value);
|
|
@@ -620,7 +620,7 @@ function apply(instruction) {
|
|
|
620
620
|
return placeholder;
|
|
621
621
|
}
|
|
622
622
|
|
|
623
|
-
const Oops$
|
|
623
|
+
const Oops$4 = issues({
|
|
624
624
|
DuplicatePending: (key) => `Invoked action ${key} but one is already active.`
|
|
625
625
|
});
|
|
626
626
|
function run(task) {
|
|
@@ -628,7 +628,7 @@ function run(task) {
|
|
|
628
628
|
let pending = false;
|
|
629
629
|
const invoke = (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
630
630
|
if (pending)
|
|
631
|
-
return Promise.reject(Oops$
|
|
631
|
+
return Promise.reject(Oops$4.DuplicatePending(key));
|
|
632
632
|
pending = true;
|
|
633
633
|
control.update(key);
|
|
634
634
|
try {
|
|
@@ -650,7 +650,7 @@ function run(task) {
|
|
|
650
650
|
});
|
|
651
651
|
}
|
|
652
652
|
|
|
653
|
-
const Oops$
|
|
653
|
+
const Oops$3 = issues({
|
|
654
654
|
PeerNotAllowed: (model, property) => `Attempted to use an instruction result (probably use or get) as computed source for ${model}.${property}. This is not allowed.`,
|
|
655
655
|
Failed: (parent, property, initial) => `An exception was thrown while ${initial ? "initializing" : "refreshing"} ${parent}.${property}.`,
|
|
656
656
|
Required: (expects, child) => `New ${child} created standalone but requires parent of type ${expects}.`,
|
|
@@ -661,7 +661,7 @@ function get(arg0, arg1) {
|
|
|
661
661
|
return apply((key, control) => {
|
|
662
662
|
let { subject } = control;
|
|
663
663
|
if (typeof arg0 == "symbol")
|
|
664
|
-
throw Oops$
|
|
664
|
+
throw Oops$3.PeerNotAllowed(subject, key);
|
|
665
665
|
let source = cb => cb(subject);
|
|
666
666
|
if (arg0 instanceof Model)
|
|
667
667
|
subject = arg0;
|
|
@@ -669,7 +669,7 @@ function get(arg0, arg1) {
|
|
|
669
669
|
const hasParent = parent(subject);
|
|
670
670
|
if (!hasParent) {
|
|
671
671
|
if (arg1 === true)
|
|
672
|
-
throw Oops$
|
|
672
|
+
throw Oops$3.Required(arg0, subject);
|
|
673
673
|
const fetch = Control.has(subject);
|
|
674
674
|
source = got => {
|
|
675
675
|
fetch(context => {
|
|
@@ -677,14 +677,14 @@ function get(arg0, arg1) {
|
|
|
677
677
|
if (model)
|
|
678
678
|
got(model);
|
|
679
679
|
else if (arg1 !== false)
|
|
680
|
-
throw Oops$
|
|
680
|
+
throw Oops$3.AmbientRequired(arg0, subject);
|
|
681
681
|
});
|
|
682
682
|
};
|
|
683
683
|
}
|
|
684
684
|
else if (!arg0 || hasParent instanceof arg0)
|
|
685
685
|
subject = hasParent;
|
|
686
686
|
else
|
|
687
|
-
throw Oops$
|
|
687
|
+
throw Oops$3.Unexpected(arg0, subject, hasParent);
|
|
688
688
|
}
|
|
689
689
|
else if (typeof arg0 == "function")
|
|
690
690
|
arg1 = arg0.call(subject, key, subject);
|
|
@@ -727,7 +727,7 @@ function computed(parent, key, source, setter) {
|
|
|
727
727
|
next = setter.call(proxy, proxy);
|
|
728
728
|
}
|
|
729
729
|
catch (err) {
|
|
730
|
-
Oops$
|
|
730
|
+
Oops$3.Failed(parent.subject, key, initial).warn();
|
|
731
731
|
if (initial)
|
|
732
732
|
throw err;
|
|
733
733
|
console.error(err);
|
|
@@ -783,11 +783,18 @@ function flushComputed() {
|
|
|
783
783
|
}
|
|
784
784
|
Control.before.add(flushComputed);
|
|
785
785
|
|
|
786
|
+
const Oops$2 = issues({
|
|
787
|
+
BadRefObject: () => `ref instruction does not support object which is not 'this'`
|
|
788
|
+
});
|
|
786
789
|
function ref(arg, arg2) {
|
|
787
790
|
return apply((key, source) => {
|
|
788
791
|
let value = {};
|
|
789
|
-
if (typeof arg
|
|
790
|
-
|
|
792
|
+
if (typeof arg != "object")
|
|
793
|
+
value = createRef(source, key, arg && createValueEffect(arg, arg2 !== false));
|
|
794
|
+
else if (arg !== source.subject)
|
|
795
|
+
throw Oops$2.BadRefObject();
|
|
796
|
+
else
|
|
797
|
+
for (const key in source.state)
|
|
791
798
|
defineProperty(value, key, typeof arg2 == "function" ? {
|
|
792
799
|
configurable: true,
|
|
793
800
|
get() {
|
|
@@ -798,8 +805,6 @@ function ref(arg, arg2) {
|
|
|
798
805
|
} : {
|
|
799
806
|
value: createRef(source, key)
|
|
800
807
|
});
|
|
801
|
-
else
|
|
802
|
-
value = createRef(source, key, arg && createValueEffect(arg, arg2 !== false));
|
|
803
808
|
source.state[key] = undefined;
|
|
804
809
|
source.observers.set(key, new Set());
|
|
805
810
|
defineProperty(source.subject, key, { value });
|
package/package.json
CHANGED