@expressive/mvc 0.6.3 → 0.7.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/lib/index.d.ts +27 -21
- package/lib/index.esm.js +66 -71
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +66 -71
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -204,22 +204,6 @@ class Model {
|
|
|
204
204
|
defineProperty(this, "is", {
|
|
205
205
|
value: this
|
|
206
206
|
});
|
|
207
|
-
defineProperty(this, "set", {
|
|
208
|
-
configurable: true,
|
|
209
|
-
get: () => {
|
|
210
|
-
const controller = ensure(this);
|
|
211
|
-
const value = (key, value) => {
|
|
212
|
-
controller.state.set(key, value);
|
|
213
|
-
controller.update(key);
|
|
214
|
-
};
|
|
215
|
-
for (const key of controller.state.keys())
|
|
216
|
-
defineProperty(value, key, {
|
|
217
|
-
value: controller.ref(key)
|
|
218
|
-
});
|
|
219
|
-
defineProperty(this, "set", { value });
|
|
220
|
-
return value;
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
207
|
}
|
|
224
208
|
get [STATE]() {
|
|
225
209
|
return this.export();
|
|
@@ -482,8 +466,11 @@ class Controller {
|
|
|
482
466
|
return;
|
|
483
467
|
if (typeof value == "symbol") {
|
|
484
468
|
const instruction = PENDING.get(value);
|
|
485
|
-
if (instruction)
|
|
469
|
+
if (instruction) {
|
|
470
|
+
delete subject[key];
|
|
471
|
+
PENDING.delete(value);
|
|
486
472
|
instruction.call(this, key, this);
|
|
473
|
+
}
|
|
487
474
|
return;
|
|
488
475
|
}
|
|
489
476
|
state.set(key, value);
|
|
@@ -587,9 +574,6 @@ function apply(fn, label) {
|
|
|
587
574
|
const placeholder = Symbol(`${name} instruction`);
|
|
588
575
|
function setup(key) {
|
|
589
576
|
const { subject, state } = this;
|
|
590
|
-
const control = this;
|
|
591
|
-
PENDING.delete(placeholder);
|
|
592
|
-
delete subject[key];
|
|
593
577
|
let output = fn.call(this, key, this);
|
|
594
578
|
if (typeof output == "function")
|
|
595
579
|
output = { get: output };
|
|
@@ -612,6 +596,7 @@ function apply(fn, label) {
|
|
|
612
596
|
destroy();
|
|
613
597
|
});
|
|
614
598
|
}
|
|
599
|
+
const control = this;
|
|
615
600
|
defineProperty(subject, key, {
|
|
616
601
|
enumerable: output.enumerable,
|
|
617
602
|
set: onSet !== false
|
|
@@ -805,7 +790,7 @@ function get(arg0, arg1, arg2) {
|
|
|
805
790
|
throw new Error(`Factory argument cannot be ${arg1}`);
|
|
806
791
|
getter = computeMode(this, source, setter, key, computeRequired);
|
|
807
792
|
};
|
|
808
|
-
if (typeof arg0 == "function" &&
|
|
793
|
+
if (typeof arg0 == "function" && computeRequired)
|
|
809
794
|
try {
|
|
810
795
|
init();
|
|
811
796
|
}
|
|
@@ -821,18 +806,34 @@ function get(arg0, arg1, arg2) {
|
|
|
821
806
|
});
|
|
822
807
|
}
|
|
823
808
|
|
|
824
|
-
function ref(
|
|
809
|
+
function ref(arg, mapper) {
|
|
825
810
|
return apply(function ref(key) {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
811
|
+
let value = {};
|
|
812
|
+
if (typeof arg != "object")
|
|
813
|
+
value = createRef(this, key, arg);
|
|
814
|
+
else
|
|
815
|
+
ensure(arg).state.forEach((_val, key) => {
|
|
816
|
+
defineProperty(value, key, mapper ? {
|
|
817
|
+
configurable: true,
|
|
818
|
+
get() {
|
|
819
|
+
const out = mapper(key);
|
|
820
|
+
defineProperty(value, key, { value: out });
|
|
821
|
+
return out;
|
|
822
|
+
}
|
|
823
|
+
} : {
|
|
824
|
+
value: createRef(this, key)
|
|
825
|
+
});
|
|
826
|
+
});
|
|
827
|
+
return { value, explicit: true };
|
|
835
828
|
});
|
|
829
|
+
}
|
|
830
|
+
function createRef(src, key, cb) {
|
|
831
|
+
const refObjectFunction = src.ref(key, cb && createValueEffect(cb));
|
|
832
|
+
defineProperty(refObjectFunction, "current", {
|
|
833
|
+
set: refObjectFunction,
|
|
834
|
+
get: () => src.state.get(key)
|
|
835
|
+
});
|
|
836
|
+
return refObjectFunction;
|
|
836
837
|
}
|
|
837
838
|
|
|
838
839
|
function set(value, argument) {
|
|
@@ -929,12 +930,15 @@ function createProxy(emit, watch) {
|
|
|
929
930
|
assign(proxy, {
|
|
930
931
|
from,
|
|
931
932
|
delete(key) {
|
|
933
|
+
// TODO: this commit's fix needs tests.
|
|
934
|
+
// Was not cause by coverage.
|
|
935
|
+
const out = from.delete(key);
|
|
932
936
|
emit(key);
|
|
933
|
-
return
|
|
937
|
+
return out;
|
|
934
938
|
},
|
|
935
939
|
clear() {
|
|
936
|
-
emit(ANY);
|
|
937
940
|
from.clear();
|
|
941
|
+
emit(ANY);
|
|
938
942
|
},
|
|
939
943
|
has(key) {
|
|
940
944
|
watch(this, key);
|
|
@@ -1114,26 +1118,10 @@ class Lookup {
|
|
|
1114
1118
|
get(T) {
|
|
1115
1119
|
return this[this.key(T)];
|
|
1116
1120
|
}
|
|
1117
|
-
push(
|
|
1118
|
-
|
|
1119
|
-
if (I instanceof Model || typeof I == "function")
|
|
1120
|
-
next.register(I);
|
|
1121
|
-
else
|
|
1122
|
-
for (const i of values(I))
|
|
1123
|
-
next.register(i);
|
|
1124
|
-
return next;
|
|
1121
|
+
push() {
|
|
1122
|
+
return create(this);
|
|
1125
1123
|
}
|
|
1126
|
-
|
|
1127
|
-
let writable = true;
|
|
1128
|
-
let T;
|
|
1129
|
-
if (I instanceof Model) {
|
|
1130
|
-
T = I.constructor;
|
|
1131
|
-
writable = false;
|
|
1132
|
-
}
|
|
1133
|
-
else {
|
|
1134
|
-
T = I;
|
|
1135
|
-
I = I.create();
|
|
1136
|
-
}
|
|
1124
|
+
inject(T, I, writable) {
|
|
1137
1125
|
do {
|
|
1138
1126
|
const key = this.key(T);
|
|
1139
1127
|
const conflict = this.hasOwnProperty(key);
|
|
@@ -1144,7 +1132,6 @@ class Lookup {
|
|
|
1144
1132
|
});
|
|
1145
1133
|
T = getPrototypeOf(T);
|
|
1146
1134
|
} while (T !== Model);
|
|
1147
|
-
return I;
|
|
1148
1135
|
}
|
|
1149
1136
|
pop() {
|
|
1150
1137
|
for (const key of getOwnPropertySymbols(this)) {
|
|
@@ -1427,7 +1414,28 @@ const Oops$1 = issues({
|
|
|
1427
1414
|
function Provider(props) {
|
|
1428
1415
|
if ("of" in props)
|
|
1429
1416
|
throw Oops$1.PropDeprecated();
|
|
1430
|
-
const
|
|
1417
|
+
const from = useLookup();
|
|
1418
|
+
const context = React__default["default"].useMemo(() => {
|
|
1419
|
+
const I = props.for;
|
|
1420
|
+
if (!I)
|
|
1421
|
+
throw Oops$1.NoType();
|
|
1422
|
+
const layer = from.push();
|
|
1423
|
+
function register(I) {
|
|
1424
|
+
if (I instanceof Model)
|
|
1425
|
+
layer.inject(I.constructor, I, false);
|
|
1426
|
+
else
|
|
1427
|
+
layer.inject(I, I.create(), true);
|
|
1428
|
+
}
|
|
1429
|
+
if (I instanceof Model || typeof I == "function")
|
|
1430
|
+
register(I);
|
|
1431
|
+
else
|
|
1432
|
+
values(I).forEach(register);
|
|
1433
|
+
for (const instance of layer.local)
|
|
1434
|
+
if (instance)
|
|
1435
|
+
for (const apply of getPending(instance))
|
|
1436
|
+
apply(layer);
|
|
1437
|
+
return layer;
|
|
1438
|
+
}, []);
|
|
1431
1439
|
const render = props.children;
|
|
1432
1440
|
useAppliedProps(context, props);
|
|
1433
1441
|
React__default["default"].useLayoutEffect(() => () => context.pop(), []);
|
|
@@ -1435,19 +1443,6 @@ function Provider(props) {
|
|
|
1435
1443
|
? React__default["default"].createElement(RenderFunction, { context, render })
|
|
1436
1444
|
: render);
|
|
1437
1445
|
}
|
|
1438
|
-
function useNewContext(inject) {
|
|
1439
|
-
const from = useLookup();
|
|
1440
|
-
return React__default["default"].useMemo(() => {
|
|
1441
|
-
if (!inject)
|
|
1442
|
-
throw Oops$1.NoType();
|
|
1443
|
-
const context = from.push(inject);
|
|
1444
|
-
for (const instance of context.local)
|
|
1445
|
-
if (instance)
|
|
1446
|
-
for (const apply of getPending(instance))
|
|
1447
|
-
apply(context);
|
|
1448
|
-
return context;
|
|
1449
|
-
}, []);
|
|
1450
|
-
}
|
|
1451
1446
|
function useAppliedProps(within, props) {
|
|
1452
1447
|
const update = React__default["default"].useMemo(() => {
|
|
1453
1448
|
const targets = within.local;
|
|
@@ -1480,11 +1475,11 @@ const Oops = issues({
|
|
|
1480
1475
|
const Active = new WeakMap();
|
|
1481
1476
|
class Global extends MVC {
|
|
1482
1477
|
static create(...args) {
|
|
1483
|
-
|
|
1484
|
-
if (Active.has(Type))
|
|
1478
|
+
if (Active.has(this))
|
|
1485
1479
|
throw Oops.AlreadyExists(this.name);
|
|
1486
|
-
const instance =
|
|
1487
|
-
|
|
1480
|
+
const instance = new this(...args);
|
|
1481
|
+
ensure(instance);
|
|
1482
|
+
Active.set(this, instance);
|
|
1488
1483
|
return instance;
|
|
1489
1484
|
}
|
|
1490
1485
|
/**
|