@expressive/mvc 0.36.1 → 0.36.3
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/index.d.ts +4 -2
- package/dist/index.js +26 -13
- package/dist/index.mjs +26 -13
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,11 @@ declare namespace Model {
|
|
|
5
5
|
type New<T extends Model = Model> = (new () => T) & typeof Model;
|
|
6
6
|
/** Subset of `keyof T` which are not methods or defined by base Model U. **/
|
|
7
7
|
type Field<T> = Exclude<keyof T, keyof Model>;
|
|
8
|
+
/** Any valid key for controller, including but not limited to keyof T. */
|
|
8
9
|
type Key<T> = Field<T> | (string & {}) | number | symbol;
|
|
10
|
+
/** Value for a given property managed by a controller. */
|
|
9
11
|
type Value<T extends Model, K extends Key<T>> = K extends keyof T ? T[K] extends Ref<infer V> ? V : T[K] : unknown;
|
|
12
|
+
type Event<T extends Model> = (this: T, key: unknown, source: T) => (() => void) | void | null;
|
|
10
13
|
type OnUpdate<T extends Model, K extends Key<T>> = (this: T, value: Value<T, K>, key: K, thisArg: K) => void;
|
|
11
14
|
/** Export/Import compatible value for a given property in a Model. */
|
|
12
15
|
type Export<R> = R extends Ref<infer T> ? T : R extends Model ? State<R> : R;
|
|
@@ -28,8 +31,7 @@ declare namespace Model {
|
|
|
28
31
|
current: T | null;
|
|
29
32
|
};
|
|
30
33
|
/** A callback function which is subscribed to parent and updates when values change. */
|
|
31
|
-
type Effect<T> = (this: T,
|
|
32
|
-
type Event<T extends Model> = (this: T, key: unknown, source: T) => (() => void) | void | null;
|
|
34
|
+
type Effect<T> = (this: T, current: T, updated: Set<Model.Key<T>>) => ((update: boolean | null) => void) | Promise<void> | null | void;
|
|
33
35
|
namespace Instruction {
|
|
34
36
|
type Getter<T> = (source: Model) => T;
|
|
35
37
|
type Setter<T> = (value: T, previous: T) => boolean | void | (() => T);
|
package/dist/index.js
CHANGED
|
@@ -181,8 +181,17 @@ var Model = class _Model {
|
|
|
181
181
|
}
|
|
182
182
|
get(arg1, arg2) {
|
|
183
183
|
const self = this.is;
|
|
184
|
-
if (typeof arg1 == "function")
|
|
185
|
-
|
|
184
|
+
if (typeof arg1 == "function") {
|
|
185
|
+
let pending = /* @__PURE__ */ new Set();
|
|
186
|
+
return effect(self, (state) => {
|
|
187
|
+
const cb = arg1.call(state, state, pending);
|
|
188
|
+
return cb === null ? null : (update2) => {
|
|
189
|
+
pending = PENDING2.get(self);
|
|
190
|
+
if (typeof cb == "function")
|
|
191
|
+
return cb(update2);
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
}
|
|
186
195
|
if (arg1 === void 0)
|
|
187
196
|
return extract(self);
|
|
188
197
|
if (typeof arg2 == "function") {
|
|
@@ -326,17 +335,19 @@ function update(subject, key, value, silent) {
|
|
|
326
335
|
return;
|
|
327
336
|
push(subject, key);
|
|
328
337
|
}
|
|
329
|
-
function push(subject, key) {
|
|
338
|
+
function push(subject, key, silent) {
|
|
330
339
|
let pending = PENDING2.get(subject);
|
|
331
340
|
if (!pending) {
|
|
332
341
|
PENDING2.set(subject, pending = /* @__PURE__ */ new Set());
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
342
|
+
if (!silent)
|
|
343
|
+
queue(() => {
|
|
344
|
+
event(subject, false);
|
|
345
|
+
PENDING2.delete(subject);
|
|
346
|
+
});
|
|
337
347
|
}
|
|
338
348
|
pending.add(key);
|
|
339
|
-
|
|
349
|
+
if (!silent)
|
|
350
|
+
event(subject, key);
|
|
340
351
|
}
|
|
341
352
|
function extract(from) {
|
|
342
353
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
@@ -366,7 +377,9 @@ function add(instruction) {
|
|
|
366
377
|
}
|
|
367
378
|
Model.on((_, subject) => {
|
|
368
379
|
const state = STATE.get(subject);
|
|
369
|
-
Object.entries(
|
|
380
|
+
Object.entries(
|
|
381
|
+
Object.getOwnPropertyDescriptors(subject)
|
|
382
|
+
).forEach(([key, { value }]) => {
|
|
370
383
|
const instruction = INSTRUCT.get(value);
|
|
371
384
|
if (!instruction)
|
|
372
385
|
return;
|
|
@@ -559,10 +572,10 @@ function compute(subject, key, source, setter) {
|
|
|
559
572
|
compute2(true);
|
|
560
573
|
else if (STALE.delete(compute2))
|
|
561
574
|
compute2();
|
|
562
|
-
return (
|
|
563
|
-
if (
|
|
575
|
+
return (didUpdate) => {
|
|
576
|
+
if (didUpdate) {
|
|
564
577
|
STALE.add(compute2);
|
|
565
|
-
subject
|
|
578
|
+
push(subject, key, true);
|
|
566
579
|
}
|
|
567
580
|
};
|
|
568
581
|
});
|
|
@@ -577,7 +590,7 @@ function compute(subject, key, source, setter) {
|
|
|
577
590
|
throw err;
|
|
578
591
|
console.error(err);
|
|
579
592
|
}
|
|
580
|
-
subject
|
|
593
|
+
update(subject, key, next, !isAsync);
|
|
581
594
|
}
|
|
582
595
|
return () => {
|
|
583
596
|
if (!proxy) {
|
package/dist/index.mjs
CHANGED
|
@@ -148,8 +148,17 @@ var Model = class _Model {
|
|
|
148
148
|
}
|
|
149
149
|
get(arg1, arg2) {
|
|
150
150
|
const self = this.is;
|
|
151
|
-
if (typeof arg1 == "function")
|
|
152
|
-
|
|
151
|
+
if (typeof arg1 == "function") {
|
|
152
|
+
let pending = /* @__PURE__ */ new Set();
|
|
153
|
+
return effect(self, (state) => {
|
|
154
|
+
const cb = arg1.call(state, state, pending);
|
|
155
|
+
return cb === null ? null : (update2) => {
|
|
156
|
+
pending = PENDING2.get(self);
|
|
157
|
+
if (typeof cb == "function")
|
|
158
|
+
return cb(update2);
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
153
162
|
if (arg1 === void 0)
|
|
154
163
|
return extract(self);
|
|
155
164
|
if (typeof arg2 == "function") {
|
|
@@ -293,17 +302,19 @@ function update(subject, key, value, silent) {
|
|
|
293
302
|
return;
|
|
294
303
|
push(subject, key);
|
|
295
304
|
}
|
|
296
|
-
function push(subject, key) {
|
|
305
|
+
function push(subject, key, silent) {
|
|
297
306
|
let pending = PENDING2.get(subject);
|
|
298
307
|
if (!pending) {
|
|
299
308
|
PENDING2.set(subject, pending = /* @__PURE__ */ new Set());
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
309
|
+
if (!silent)
|
|
310
|
+
queue(() => {
|
|
311
|
+
event(subject, false);
|
|
312
|
+
PENDING2.delete(subject);
|
|
313
|
+
});
|
|
304
314
|
}
|
|
305
315
|
pending.add(key);
|
|
306
|
-
|
|
316
|
+
if (!silent)
|
|
317
|
+
event(subject, key);
|
|
307
318
|
}
|
|
308
319
|
function extract(from) {
|
|
309
320
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
@@ -333,7 +344,9 @@ function add(instruction) {
|
|
|
333
344
|
}
|
|
334
345
|
Model.on((_, subject) => {
|
|
335
346
|
const state = STATE.get(subject);
|
|
336
|
-
Object.entries(
|
|
347
|
+
Object.entries(
|
|
348
|
+
Object.getOwnPropertyDescriptors(subject)
|
|
349
|
+
).forEach(([key, { value }]) => {
|
|
337
350
|
const instruction = INSTRUCT.get(value);
|
|
338
351
|
if (!instruction)
|
|
339
352
|
return;
|
|
@@ -526,10 +539,10 @@ function compute(subject, key, source, setter) {
|
|
|
526
539
|
compute2(true);
|
|
527
540
|
else if (STALE.delete(compute2))
|
|
528
541
|
compute2();
|
|
529
|
-
return (
|
|
530
|
-
if (
|
|
542
|
+
return (didUpdate) => {
|
|
543
|
+
if (didUpdate) {
|
|
531
544
|
STALE.add(compute2);
|
|
532
|
-
subject
|
|
545
|
+
push(subject, key, true);
|
|
533
546
|
}
|
|
534
547
|
};
|
|
535
548
|
});
|
|
@@ -544,7 +557,7 @@ function compute(subject, key, source, setter) {
|
|
|
544
557
|
throw err;
|
|
545
558
|
console.error(err);
|
|
546
559
|
}
|
|
547
|
-
subject
|
|
560
|
+
update(subject, key, next, !isAsync);
|
|
548
561
|
}
|
|
549
562
|
return () => {
|
|
550
563
|
if (!proxy) {
|
package/package.json
CHANGED