@expressive/mvc 0.53.3 → 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 +76 -44
- package/package.json +6 -7
- package/dist/index.mjs +0 -908
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
|
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
20
|
// src/index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
23
|
Context: () => Context,
|
|
24
24
|
Model: () => Model,
|
|
25
25
|
addListener: () => addListener,
|
|
@@ -32,7 +32,7 @@ __export(src_exports, {
|
|
|
32
32
|
set: () => set,
|
|
33
33
|
use: () => use
|
|
34
34
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// src/control.ts
|
|
38
38
|
var onReady = () => null;
|
|
@@ -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);
|
|
@@ -300,10 +324,8 @@ function prepare(model) {
|
|
|
300
324
|
while (T.name) {
|
|
301
325
|
for (const cb of NOTIFY.get(T) || [])
|
|
302
326
|
addListener(model, cb);
|
|
303
|
-
if (T === Model)
|
|
304
|
-
|
|
305
|
-
else
|
|
306
|
-
chain.unshift(T);
|
|
327
|
+
if (T === Model) break;
|
|
328
|
+
else chain.unshift(T);
|
|
307
329
|
T = Object.getPrototypeOf(T);
|
|
308
330
|
}
|
|
309
331
|
for (const type of chain) {
|
|
@@ -316,9 +338,9 @@ function prepare(model) {
|
|
|
316
338
|
Object.getOwnPropertyDescriptors(type.prototype)
|
|
317
339
|
)) {
|
|
318
340
|
let bind2 = function(method = value) {
|
|
319
|
-
const value2 = method.bind(
|
|
341
|
+
const value2 = method.bind(this.is);
|
|
320
342
|
METHOD.set(value2, method);
|
|
321
|
-
define(
|
|
343
|
+
define(this.is, key2, { value: value2, writable: true });
|
|
322
344
|
return value2;
|
|
323
345
|
};
|
|
324
346
|
var bind = bind2;
|
|
@@ -670,8 +692,8 @@ function get(arg0, arg1) {
|
|
|
670
692
|
if (!hasParent) {
|
|
671
693
|
if (arg1 === true)
|
|
672
694
|
throw new Error(`${subject} may only exist as a child of type ${arg0}.`);
|
|
673
|
-
Context.get(subject, (
|
|
674
|
-
const model =
|
|
695
|
+
Context.get(subject, (context2) => {
|
|
696
|
+
const model = context2.get(arg0);
|
|
675
697
|
if (model)
|
|
676
698
|
assign2(model);
|
|
677
699
|
else if (arg1 !== false)
|
|
@@ -708,7 +730,7 @@ function get(arg0, arg1) {
|
|
|
708
730
|
event(subject, key2, true);
|
|
709
731
|
}
|
|
710
732
|
};
|
|
711
|
-
});
|
|
733
|
+
}, false);
|
|
712
734
|
}
|
|
713
735
|
function compute(initial) {
|
|
714
736
|
let next;
|
|
@@ -763,18 +785,23 @@ function ref(arg, arg2) {
|
|
|
763
785
|
else if (typeof arg == "object")
|
|
764
786
|
throw new Error("ref instruction does not support object which is not 'this'");
|
|
765
787
|
else {
|
|
766
|
-
let
|
|
788
|
+
let unset;
|
|
767
789
|
const get2 = () => state[key2];
|
|
768
790
|
const set2 = (value2) => {
|
|
769
791
|
if (!update(subject, key2, value2) || !arg)
|
|
770
792
|
return;
|
|
771
|
-
if (
|
|
772
|
-
|
|
773
|
-
if (value2
|
|
774
|
-
|
|
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) => {
|
|
775
801
|
if (typeof out == "function")
|
|
776
|
-
|
|
777
|
-
|
|
802
|
+
out(key3);
|
|
803
|
+
flush();
|
|
804
|
+
};
|
|
778
805
|
};
|
|
779
806
|
state[key2] = null;
|
|
780
807
|
value = Object.defineProperties(set2, {
|
|
@@ -789,7 +816,7 @@ function ref(arg, arg2) {
|
|
|
789
816
|
// src/instruction/set.ts
|
|
790
817
|
function set(value, argument) {
|
|
791
818
|
return use((key2, subject) => {
|
|
792
|
-
const
|
|
819
|
+
const property = {};
|
|
793
820
|
if (typeof value == "function" || value instanceof Promise) {
|
|
794
821
|
let init3 = function() {
|
|
795
822
|
if (typeof value == "function")
|
|
@@ -799,14 +826,14 @@ function set(value, argument) {
|
|
|
799
826
|
console.warn(`Generating initial value for ${subject}.${key2} failed.`);
|
|
800
827
|
throw err;
|
|
801
828
|
}
|
|
802
|
-
|
|
829
|
+
property.get = argument === true;
|
|
803
830
|
if (value instanceof Promise) {
|
|
804
831
|
value.then((value2) => {
|
|
805
832
|
update(subject, key2, value2);
|
|
806
833
|
return value2;
|
|
807
834
|
}).catch((err) => {
|
|
808
835
|
event(subject, key2);
|
|
809
|
-
|
|
836
|
+
property.get = () => {
|
|
810
837
|
throw err;
|
|
811
838
|
};
|
|
812
839
|
});
|
|
@@ -819,26 +846,31 @@ function set(value, argument) {
|
|
|
819
846
|
if (argument)
|
|
820
847
|
init3();
|
|
821
848
|
else
|
|
822
|
-
|
|
849
|
+
property.get = init3;
|
|
823
850
|
} else if (value !== void 0)
|
|
824
|
-
|
|
851
|
+
property.value = value;
|
|
825
852
|
if (typeof argument == "function") {
|
|
826
|
-
let
|
|
827
|
-
|
|
853
|
+
let unset;
|
|
854
|
+
property.set = function(value2, previous) {
|
|
855
|
+
const ctx = context();
|
|
828
856
|
const out = argument.call(this, value2, previous);
|
|
857
|
+
const flush = ctx();
|
|
829
858
|
if (out === false)
|
|
830
859
|
return out;
|
|
831
|
-
if (typeof
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
860
|
+
if (typeof unset == "function")
|
|
861
|
+
unset(value2);
|
|
862
|
+
unset = (next) => {
|
|
863
|
+
if (typeof out == "function")
|
|
864
|
+
out(next);
|
|
865
|
+
flush();
|
|
866
|
+
};
|
|
835
867
|
};
|
|
836
868
|
} else
|
|
837
|
-
|
|
838
|
-
|
|
869
|
+
property.set = (value2) => {
|
|
870
|
+
property.get = void 0;
|
|
839
871
|
update(subject, key2, value2);
|
|
840
872
|
};
|
|
841
|
-
return
|
|
873
|
+
return property;
|
|
842
874
|
});
|
|
843
875
|
}
|
|
844
876
|
function attempt(fn) {
|
|
@@ -868,8 +900,8 @@ function has(arg1, arg2) {
|
|
|
868
900
|
update(subject, key2, Object.freeze(Array.from(applied)));
|
|
869
901
|
};
|
|
870
902
|
if (Model.is(arg1))
|
|
871
|
-
Context.get(subject, (
|
|
872
|
-
|
|
903
|
+
Context.get(subject, (context2) => {
|
|
904
|
+
context2.has(arg1, (model) => {
|
|
873
905
|
let remove;
|
|
874
906
|
let disconnect;
|
|
875
907
|
if (applied.has(model))
|
package/package.json
CHANGED
|
@@ -15,23 +15,22 @@
|
|
|
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"
|
|
30
28
|
},
|
|
31
29
|
"devDependencies": {
|
|
30
|
+
"@types/node": "^18.19.0",
|
|
32
31
|
"jest": "^27.0.6",
|
|
33
32
|
"tsup": "^8.0.2"
|
|
34
33
|
},
|
|
35
|
-
"version": "0.53.
|
|
36
|
-
"gitHead": "
|
|
34
|
+
"version": "0.53.6",
|
|
35
|
+
"gitHead": "a6564d79b709f3d41c663885d1c0a2e3f8eddd31"
|
|
37
36
|
}
|