@expressive/mvc 0.53.5 → 0.53.6
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/esm/context.js +137 -0
- package/dist/esm/context.test.js +211 -0
- package/dist/esm/control.js +182 -0
- package/dist/esm/control.test.js +183 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/instruction/get.js +87 -0
- package/dist/esm/instruction/get.test.js +645 -0
- package/dist/esm/instruction/has.js +73 -0
- package/dist/esm/instruction/has.test.js +354 -0
- package/dist/esm/instruction/ref.js +59 -0
- package/dist/esm/instruction/ref.test.js +281 -0
- package/dist/esm/instruction/set.js +86 -0
- package/dist/esm/instruction/set.test.js +527 -0
- package/dist/esm/instruction/use.js +60 -0
- package/dist/esm/instruction/use.test.js +305 -0
- package/dist/esm/mocks.js +20 -0
- package/dist/esm/model.js +278 -0
- package/dist/esm/model.test.js +1541 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +62 -28
- package/package.json +5 -7
- package/dist/index.mjs +0 -906
package/dist/index.d.ts
CHANGED
|
@@ -16,14 +16,14 @@ declare function addListener<T extends Model>(subject: T, callback: OnUpdate<T>,
|
|
|
16
16
|
declare function createProxy<T extends Model>(from: T, observer: OnAccess<T>): T;
|
|
17
17
|
/**
|
|
18
18
|
* Create a side-effect which will update whenever values accessed change.
|
|
19
|
-
* Callback is called immediately and
|
|
19
|
+
* Callback is called immediately and whenever values are stale.
|
|
20
20
|
*
|
|
21
21
|
* @param target - Instance of Model to observe.
|
|
22
22
|
* @param callback - Function to invoke when values change.
|
|
23
23
|
* @param requireValues - If `true` will throw if accessing a value which is `undefined`.
|
|
24
24
|
*/
|
|
25
25
|
declare function createEffect<T extends Model>(target: T, callback: Effect<Required<T>>, requireValues: true): () => void;
|
|
26
|
-
declare function createEffect<T extends Model>(target: T, callback: Effect<T>,
|
|
26
|
+
declare function createEffect<T extends Model>(target: T, callback: Effect<T>, recursive?: boolean): () => void;
|
|
27
27
|
|
|
28
28
|
declare namespace Model {
|
|
29
29
|
/** Any type of Model, using own class constructor as its identifier. */
|
package/dist/index.js
CHANGED
|
@@ -129,7 +129,7 @@ function watch(from, key2, value) {
|
|
|
129
129
|
const access = OBSERVER.get(from);
|
|
130
130
|
return access ? access(from, key2, value) : value;
|
|
131
131
|
}
|
|
132
|
-
function createEffect(target, callback,
|
|
132
|
+
function createEffect(target, callback, argument) {
|
|
133
133
|
const listeners = LISTENERS.get(target);
|
|
134
134
|
let unset;
|
|
135
135
|
let reset;
|
|
@@ -148,7 +148,7 @@ function createEffect(target, callback, requireValues) {
|
|
|
148
148
|
return reset;
|
|
149
149
|
}
|
|
150
150
|
function access(from, key2, value) {
|
|
151
|
-
if (value === void 0 &&
|
|
151
|
+
if (value === void 0 && argument)
|
|
152
152
|
throw new Error(`${from}.${key2} is required in this context.`);
|
|
153
153
|
const listeners2 = LISTENERS.get(from);
|
|
154
154
|
let listener = listeners2.get(onUpdate);
|
|
@@ -164,9 +164,15 @@ function createEffect(target, callback, requireValues) {
|
|
|
164
164
|
return value;
|
|
165
165
|
}
|
|
166
166
|
try {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
const ctx = context(argument === false);
|
|
168
|
+
const ret = callback.call(subscriber, subscriber);
|
|
169
|
+
const flush = ctx();
|
|
170
|
+
reset = ret === null ? null : invoke;
|
|
171
|
+
unset = (key2) => {
|
|
172
|
+
if (typeof ret == "function")
|
|
173
|
+
ret(key2);
|
|
174
|
+
flush();
|
|
175
|
+
};
|
|
170
176
|
} catch (err) {
|
|
171
177
|
if (err instanceof Promise) {
|
|
172
178
|
reset = void 0;
|
|
@@ -175,6 +181,14 @@ function createEffect(target, callback, requireValues) {
|
|
|
175
181
|
throw err;
|
|
176
182
|
}
|
|
177
183
|
}
|
|
184
|
+
function cleanup() {
|
|
185
|
+
if (unset)
|
|
186
|
+
unset(false);
|
|
187
|
+
reset = null;
|
|
188
|
+
}
|
|
189
|
+
;
|
|
190
|
+
if (EffectContext && argument !== false)
|
|
191
|
+
EffectContext.add(cleanup);
|
|
178
192
|
addListener(target, (key2) => {
|
|
179
193
|
if (key2 === true)
|
|
180
194
|
invoke();
|
|
@@ -183,10 +197,20 @@ function createEffect(target, callback, requireValues) {
|
|
|
183
197
|
if (key2 === null && unset)
|
|
184
198
|
unset(null);
|
|
185
199
|
});
|
|
200
|
+
return cleanup;
|
|
201
|
+
}
|
|
202
|
+
var EffectContext;
|
|
203
|
+
function context(ignore) {
|
|
204
|
+
if (ignore)
|
|
205
|
+
return () => () => {
|
|
206
|
+
};
|
|
207
|
+
const current = EffectContext;
|
|
208
|
+
const ctx = EffectContext = /* @__PURE__ */ new Set();
|
|
186
209
|
return () => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
210
|
+
EffectContext = current;
|
|
211
|
+
return () => {
|
|
212
|
+
ctx.forEach((fn) => fn());
|
|
213
|
+
};
|
|
190
214
|
};
|
|
191
215
|
}
|
|
192
216
|
|
|
@@ -210,7 +234,7 @@ var Model = class {
|
|
|
210
234
|
let pending2 = /* @__PURE__ */ new Set();
|
|
211
235
|
return createEffect(self, (proxy) => {
|
|
212
236
|
const cb = arg1.call(proxy, proxy, pending2);
|
|
213
|
-
return cb === null ?
|
|
237
|
+
return cb === null ? null : (update2) => {
|
|
214
238
|
pending2 = PENDING_KEYS.get(self);
|
|
215
239
|
if (typeof cb == "function")
|
|
216
240
|
cb(update2);
|
|
@@ -314,9 +338,9 @@ function prepare(model) {
|
|
|
314
338
|
Object.getOwnPropertyDescriptors(type.prototype)
|
|
315
339
|
)) {
|
|
316
340
|
let bind2 = function(method = value) {
|
|
317
|
-
const value2 = method.bind(
|
|
341
|
+
const value2 = method.bind(this.is);
|
|
318
342
|
METHOD.set(value2, method);
|
|
319
|
-
define(
|
|
343
|
+
define(this.is, key2, { value: value2, writable: true });
|
|
320
344
|
return value2;
|
|
321
345
|
};
|
|
322
346
|
var bind = bind2;
|
|
@@ -668,8 +692,8 @@ function get(arg0, arg1) {
|
|
|
668
692
|
if (!hasParent) {
|
|
669
693
|
if (arg1 === true)
|
|
670
694
|
throw new Error(`${subject} may only exist as a child of type ${arg0}.`);
|
|
671
|
-
Context.get(subject, (
|
|
672
|
-
const model =
|
|
695
|
+
Context.get(subject, (context2) => {
|
|
696
|
+
const model = context2.get(arg0);
|
|
673
697
|
if (model)
|
|
674
698
|
assign2(model);
|
|
675
699
|
else if (arg1 !== false)
|
|
@@ -706,7 +730,7 @@ function get(arg0, arg1) {
|
|
|
706
730
|
event(subject, key2, true);
|
|
707
731
|
}
|
|
708
732
|
};
|
|
709
|
-
});
|
|
733
|
+
}, false);
|
|
710
734
|
}
|
|
711
735
|
function compute(initial) {
|
|
712
736
|
let next;
|
|
@@ -761,18 +785,23 @@ function ref(arg, arg2) {
|
|
|
761
785
|
else if (typeof arg == "object")
|
|
762
786
|
throw new Error("ref instruction does not support object which is not 'this'");
|
|
763
787
|
else {
|
|
764
|
-
let
|
|
788
|
+
let unset;
|
|
765
789
|
const get2 = () => state[key2];
|
|
766
790
|
const set2 = (value2) => {
|
|
767
791
|
if (!update(subject, key2, value2) || !arg)
|
|
768
792
|
return;
|
|
769
|
-
if (
|
|
770
|
-
|
|
771
|
-
if (value2
|
|
772
|
-
|
|
793
|
+
if (unset)
|
|
794
|
+
unset = void unset(value2);
|
|
795
|
+
if (value2 === null && arg2 !== false)
|
|
796
|
+
return;
|
|
797
|
+
const ctx = context();
|
|
798
|
+
const out = arg.call(subject, value2);
|
|
799
|
+
const flush = ctx();
|
|
800
|
+
unset = (key3) => {
|
|
773
801
|
if (typeof out == "function")
|
|
774
|
-
|
|
775
|
-
|
|
802
|
+
out(key3);
|
|
803
|
+
flush();
|
|
804
|
+
};
|
|
776
805
|
};
|
|
777
806
|
state[key2] = null;
|
|
778
807
|
value = Object.defineProperties(set2, {
|
|
@@ -821,15 +850,20 @@ function set(value, argument) {
|
|
|
821
850
|
} else if (value !== void 0)
|
|
822
851
|
property.value = value;
|
|
823
852
|
if (typeof argument == "function") {
|
|
824
|
-
let
|
|
853
|
+
let unset;
|
|
825
854
|
property.set = function(value2, previous) {
|
|
855
|
+
const ctx = context();
|
|
826
856
|
const out = argument.call(this, value2, previous);
|
|
857
|
+
const flush = ctx();
|
|
827
858
|
if (out === false)
|
|
828
859
|
return out;
|
|
829
|
-
if (typeof
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
860
|
+
if (typeof unset == "function")
|
|
861
|
+
unset(value2);
|
|
862
|
+
unset = (next) => {
|
|
863
|
+
if (typeof out == "function")
|
|
864
|
+
out(next);
|
|
865
|
+
flush();
|
|
866
|
+
};
|
|
833
867
|
};
|
|
834
868
|
} else
|
|
835
869
|
property.set = (value2) => {
|
|
@@ -866,8 +900,8 @@ function has(arg1, arg2) {
|
|
|
866
900
|
update(subject, key2, Object.freeze(Array.from(applied)));
|
|
867
901
|
};
|
|
868
902
|
if (Model.is(arg1))
|
|
869
|
-
Context.get(subject, (
|
|
870
|
-
|
|
903
|
+
Context.get(subject, (context2) => {
|
|
904
|
+
context2.has(arg1, (model) => {
|
|
871
905
|
let remove;
|
|
872
906
|
let disconnect;
|
|
873
907
|
if (applied.has(model))
|
package/package.json
CHANGED
|
@@ -15,15 +15,13 @@
|
|
|
15
15
|
"mvc"
|
|
16
16
|
],
|
|
17
17
|
"main": "dist/index.js",
|
|
18
|
-
"module": "dist/index.mjs",
|
|
18
|
+
"module": "dist/esm/index.mjs",
|
|
19
19
|
"types": "dist/index.d.ts",
|
|
20
20
|
"files": [
|
|
21
|
-
"dist
|
|
22
|
-
"dist/index.mjs",
|
|
23
|
-
"dist/index.d.ts"
|
|
21
|
+
"dist"
|
|
24
22
|
],
|
|
25
23
|
"scripts": {
|
|
26
|
-
"build": "tsup src/index.ts --dts
|
|
24
|
+
"build": "tsc && tsup src/index.ts --dts",
|
|
27
25
|
"test": "tsc --noEmit && jest --collectCoverage",
|
|
28
26
|
"prebuild": "rm -rf dist",
|
|
29
27
|
"preversion": "npm run test && npm run build"
|
|
@@ -33,6 +31,6 @@
|
|
|
33
31
|
"jest": "^27.0.6",
|
|
34
32
|
"tsup": "^8.0.2"
|
|
35
33
|
},
|
|
36
|
-
"version": "0.53.
|
|
37
|
-
"gitHead": "
|
|
34
|
+
"version": "0.53.6",
|
|
35
|
+
"gitHead": "a6564d79b709f3d41c663885d1c0a2e3f8eddd31"
|
|
38
36
|
}
|