@expressive/mvc 0.50.0 → 0.51.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/dist/index.d.ts +14 -11
- package/dist/index.js +96 -85
- package/dist/index.mjs +96 -85
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ type MaybeAsync<T> = T | Promise<T>;
|
|
|
2
2
|
declare namespace Model {
|
|
3
3
|
/** Any type of Model, using own class constructor as its identifier. */
|
|
4
4
|
type Type<T extends Model = Model> = (abstract new (...args: any[]) => T) & typeof Model;
|
|
5
|
+
/** A Model constructor, but which is not abstract. */
|
|
6
|
+
type Init<T extends Model = Model> = (new (...args: Model.Args<T>) => T) & Omit<typeof Model, never>;
|
|
5
7
|
/**
|
|
6
8
|
* Model constructor callback - is called when Model finishes intializing.
|
|
7
9
|
* Returned function will call when model is destroyed.
|
|
@@ -82,7 +84,7 @@ interface Model {
|
|
|
82
84
|
**/
|
|
83
85
|
is: this;
|
|
84
86
|
}
|
|
85
|
-
declare class Model {
|
|
87
|
+
declare abstract class Model {
|
|
86
88
|
constructor(...args: Model.Args);
|
|
87
89
|
/** Pull current values from state. Flattens all models and exotic values recursively. */
|
|
88
90
|
get(): Model.State<this>;
|
|
@@ -184,14 +186,14 @@ declare class Model {
|
|
|
184
186
|
*
|
|
185
187
|
* @param args - arguments sent to constructor
|
|
186
188
|
*/
|
|
187
|
-
static new<T extends Model>(this: Model.
|
|
189
|
+
static new<T extends Model>(this: Model.Init<T>, ...args: Model.Args<T>): T;
|
|
188
190
|
/**
|
|
189
191
|
* Static equivalent of `x instanceof this`.
|
|
190
192
|
* Determines if provided class is a subtype of this one.
|
|
191
193
|
* If so, language server will make available all static
|
|
192
194
|
* methods and properties of this class.
|
|
193
195
|
*/
|
|
194
|
-
static is<T extends Model.Type>(this: T, maybe:
|
|
196
|
+
static is<T extends Model.Type>(this: T, maybe: unknown): maybe is T;
|
|
195
197
|
/**
|
|
196
198
|
* Register a callback to run when any instance of this Model is updated.
|
|
197
199
|
*/
|
|
@@ -293,7 +295,7 @@ declare function ref<O extends Model, R>(target: O, mapper: (key: Model.Field<O>
|
|
|
293
295
|
*
|
|
294
296
|
* @param callback - Optional callback to synchronously fire when reference is first set or does update.
|
|
295
297
|
*/
|
|
296
|
-
declare function ref<T
|
|
298
|
+
declare function ref<T>(callback?: ref.Callback<T>): ref.Object<T>;
|
|
297
299
|
/**
|
|
298
300
|
* Creates a ref-compatible property.
|
|
299
301
|
* Will persist value, and updates to this are made part of controller event-stream.
|
|
@@ -303,7 +305,7 @@ declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>
|
|
|
303
305
|
* @param callback - Optional callback to synchronously fire when reference is first set or does update.
|
|
304
306
|
* @param ignoreNull - Default `true`. If `false`, will still callback with `null`.
|
|
305
307
|
*/
|
|
306
|
-
declare function ref<T
|
|
308
|
+
declare function ref<T>(callback: ref.Callback<T | null>, ignoreNull: boolean): ref.Object<T>;
|
|
307
309
|
|
|
308
310
|
declare namespace set {
|
|
309
311
|
type Callback<T, S = any> = (this: S, next: T, previous: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
@@ -342,8 +344,8 @@ declare function set<T>(factory: set.Factory<T> | Promise<T>, required?: boolean
|
|
|
342
344
|
declare function set<T>(value: T | undefined, onUpdate: set.Callback<T>): T;
|
|
343
345
|
|
|
344
346
|
declare function use<T = any>(instruction: Model.Instruction): T;
|
|
345
|
-
declare function use<T extends Model>(Type: Model.
|
|
346
|
-
declare function use<T extends Model>(Type: Model.
|
|
347
|
+
declare function use<T extends Model>(Type: Model.Init<T>, required: false): T | undefined;
|
|
348
|
+
declare function use<T extends Model>(Type: Model.Init<T>, ready?: (i: T) => void): T;
|
|
347
349
|
|
|
348
350
|
declare namespace has {
|
|
349
351
|
type Callback<T = any> = (model: T, recipient: Model) => void | boolean | (() => void);
|
|
@@ -364,9 +366,12 @@ declare function effect<T extends {}>(target: T, callback: Effect<Required<T>>,
|
|
|
364
366
|
declare function effect<T extends {}>(target: T, callback: Effect<T>, requireValues?: boolean): () => void;
|
|
365
367
|
|
|
366
368
|
declare namespace Context {
|
|
367
|
-
type Input = Record<string | number, Model | Model.
|
|
369
|
+
type Input = Record<string | number, Model | Model.Init>;
|
|
368
370
|
type Expect = (model: Model) => (() => void) | void;
|
|
369
371
|
}
|
|
372
|
+
interface Context {
|
|
373
|
+
[key: symbol]: Model | Context.Expect | null | undefined;
|
|
374
|
+
}
|
|
370
375
|
declare class Context {
|
|
371
376
|
static get<T extends Model>(on: Model, callback: ((got: Context) => void)): void;
|
|
372
377
|
static get<T extends Model>(on: Model): Context | undefined;
|
|
@@ -379,9 +384,7 @@ declare class Context {
|
|
|
379
384
|
push(inputs?: Context.Input): this;
|
|
380
385
|
pop(): void;
|
|
381
386
|
include(inputs: Context.Input, forEach?: (added: Model, explicit: boolean) => void): void;
|
|
382
|
-
protected add<T extends Model>(input: T | Model.
|
|
383
|
-
protected has<T extends Model>(type: Model.Type<T>, model: T): void;
|
|
384
|
-
protected put<T extends Model>(T: Model.Type<T>, I: T | ((model: T) => void), implicit?: boolean): void;
|
|
387
|
+
protected add<T extends Model>(input: T | Model.Init<T>, implicit?: boolean): T;
|
|
385
388
|
}
|
|
386
389
|
|
|
387
390
|
declare global {
|
package/dist/index.js
CHANGED
|
@@ -155,13 +155,13 @@ function effect(target, callback, requireValues) {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// src/model.ts
|
|
158
|
-
var EXPORT;
|
|
159
158
|
var NAMES = /* @__PURE__ */ new WeakMap();
|
|
160
159
|
var STATE = /* @__PURE__ */ new WeakMap();
|
|
161
160
|
var NOTIFY = /* @__PURE__ */ new WeakMap();
|
|
162
161
|
var PENDING2 = /* @__PURE__ */ new WeakMap();
|
|
163
162
|
var PARENT = /* @__PURE__ */ new WeakMap();
|
|
164
163
|
var METHOD = /* @__PURE__ */ new WeakMap();
|
|
164
|
+
var EXPORT;
|
|
165
165
|
var define = Object.defineProperty;
|
|
166
166
|
var Model = class _Model {
|
|
167
167
|
constructor(...args) {
|
|
@@ -305,6 +305,7 @@ var Model = class _Model {
|
|
|
305
305
|
* @param args - arguments sent to constructor
|
|
306
306
|
*/
|
|
307
307
|
static new(...args) {
|
|
308
|
+
_Model.is(this);
|
|
308
309
|
const instance = new this(...args);
|
|
309
310
|
emit(instance, true);
|
|
310
311
|
return instance;
|
|
@@ -316,6 +317,8 @@ var Model = class _Model {
|
|
|
316
317
|
* methods and properties of this class.
|
|
317
318
|
*/
|
|
318
319
|
static is(maybe) {
|
|
320
|
+
if (maybe === _Model)
|
|
321
|
+
throw new Error("Model is abstract and not a valid type.");
|
|
319
322
|
return typeof maybe == "function" && maybe.prototype instanceof this;
|
|
320
323
|
}
|
|
321
324
|
/**
|
|
@@ -409,9 +412,9 @@ function assign(to, values) {
|
|
|
409
412
|
to[key2] = values[key2];
|
|
410
413
|
}
|
|
411
414
|
function bindMethods(type) {
|
|
412
|
-
let
|
|
413
|
-
if (!
|
|
414
|
-
METHODS.set(type,
|
|
415
|
+
let keys2 = METHODS.get(type);
|
|
416
|
+
if (!keys2) {
|
|
417
|
+
METHODS.set(type, keys2 = bindMethods(Object.getPrototypeOf(type)).slice());
|
|
415
418
|
const desc = Object.getOwnPropertyDescriptors(type.prototype);
|
|
416
419
|
for (const key2 in desc)
|
|
417
420
|
if (key2 != "constructor" && "value" in desc[key2]) {
|
|
@@ -423,7 +426,7 @@ function bindMethods(type) {
|
|
|
423
426
|
};
|
|
424
427
|
var bind = bind2;
|
|
425
428
|
let { value } = desc[key2];
|
|
426
|
-
|
|
429
|
+
keys2.push(key2);
|
|
427
430
|
Object.defineProperty(type.prototype, key2, {
|
|
428
431
|
set: bind2,
|
|
429
432
|
get() {
|
|
@@ -432,7 +435,7 @@ function bindMethods(type) {
|
|
|
432
435
|
});
|
|
433
436
|
}
|
|
434
437
|
}
|
|
435
|
-
return
|
|
438
|
+
return keys2;
|
|
436
439
|
}
|
|
437
440
|
function uid() {
|
|
438
441
|
return (Math.random() * 0.722 + 0.278).toString(36).substring(2, 8).toUpperCase();
|
|
@@ -440,16 +443,21 @@ function uid() {
|
|
|
440
443
|
|
|
441
444
|
// src/context.ts
|
|
442
445
|
var Register = /* @__PURE__ */ new WeakMap();
|
|
443
|
-
var
|
|
444
|
-
var Downstream = /* @__PURE__ */ new WeakMap();
|
|
446
|
+
var Table = /* @__PURE__ */ new Map();
|
|
445
447
|
function key(T, upstream) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
448
|
+
let K = Table.get(T);
|
|
449
|
+
if (!K)
|
|
450
|
+
Table.set(T, K = Symbol(
|
|
451
|
+
typeof T == "symbol" ? "get " + T.description : String(T)
|
|
452
|
+
));
|
|
453
|
+
return upstream ? key(K) : K;
|
|
454
|
+
}
|
|
455
|
+
function keys(from, upstream) {
|
|
456
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
457
|
+
do {
|
|
458
|
+
keys2.add(key(from, upstream));
|
|
459
|
+
} while ((from = Object.getPrototypeOf(from)) !== Model);
|
|
460
|
+
return keys2;
|
|
453
461
|
}
|
|
454
462
|
var Context = class _Context {
|
|
455
463
|
constructor(inputs) {
|
|
@@ -460,18 +468,20 @@ var Context = class _Context {
|
|
|
460
468
|
}
|
|
461
469
|
static get(from, callback) {
|
|
462
470
|
const waiting = Register.get(from);
|
|
463
|
-
if (
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
+
if (waiting instanceof _Context) {
|
|
472
|
+
if (callback)
|
|
473
|
+
callback(waiting);
|
|
474
|
+
return waiting;
|
|
475
|
+
}
|
|
476
|
+
if (callback)
|
|
477
|
+
if (waiting)
|
|
478
|
+
waiting.push(callback);
|
|
479
|
+
else
|
|
480
|
+
Register.set(from, [callback]);
|
|
471
481
|
}
|
|
472
482
|
get(Type, callback) {
|
|
473
483
|
if (callback)
|
|
474
|
-
|
|
484
|
+
Object.defineProperty(this, key(Type, true), { value: callback });
|
|
475
485
|
const result = this[key(Type)];
|
|
476
486
|
if (result === null)
|
|
477
487
|
throw new Error(`Did find ${Type} in context, but multiple were defined.`);
|
|
@@ -525,6 +535,7 @@ var Context = class _Context {
|
|
|
525
535
|
let T;
|
|
526
536
|
let I;
|
|
527
537
|
if (typeof input == "function") {
|
|
538
|
+
Model.is(input);
|
|
528
539
|
T = input;
|
|
529
540
|
I = new input();
|
|
530
541
|
this.cleanup.add(() => I.set(null));
|
|
@@ -532,32 +543,27 @@ var Context = class _Context {
|
|
|
532
543
|
I = input;
|
|
533
544
|
T = I.constructor;
|
|
534
545
|
}
|
|
535
|
-
|
|
536
|
-
this.put(T, I, implicit);
|
|
537
|
-
return I;
|
|
538
|
-
}
|
|
539
|
-
has(type, model) {
|
|
540
|
-
do {
|
|
541
|
-
const K = key(type, true);
|
|
546
|
+
keys(T, true).forEach((K) => {
|
|
542
547
|
const result = this[K];
|
|
543
548
|
if (!result)
|
|
544
|
-
|
|
545
|
-
const callback = result(
|
|
549
|
+
return;
|
|
550
|
+
const callback = result(I);
|
|
546
551
|
if (callback)
|
|
547
552
|
this.cleanup.add(callback);
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
if (waiting instanceof Array)
|
|
551
|
-
waiting.forEach((cb) => cb(this));
|
|
552
|
-
Register.set(model, this);
|
|
553
|
-
}
|
|
554
|
-
put(T, I, implicit) {
|
|
555
|
-
do {
|
|
556
|
-
const K = key(T, typeof I == "function");
|
|
553
|
+
});
|
|
554
|
+
keys(T).forEach((K) => {
|
|
557
555
|
const value = this.hasOwnProperty(K) ? null : I;
|
|
558
556
|
if (value || this[K] !== I && !implicit)
|
|
559
|
-
Object.defineProperty(this, K, {
|
|
560
|
-
|
|
557
|
+
Object.defineProperty(this, K, {
|
|
558
|
+
configurable: true,
|
|
559
|
+
value
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
const waiting = Register.get(I);
|
|
563
|
+
if (waiting instanceof Array)
|
|
564
|
+
waiting.forEach((cb) => cb(this));
|
|
565
|
+
Register.set(I, this);
|
|
566
|
+
return I;
|
|
561
567
|
}
|
|
562
568
|
};
|
|
563
569
|
|
|
@@ -567,8 +573,11 @@ function use(arg1, arg2) {
|
|
|
567
573
|
const token = Symbol("instruction");
|
|
568
574
|
if (Model.is(arg1)) {
|
|
569
575
|
const type = arg1;
|
|
570
|
-
const value = new type();
|
|
571
576
|
arg1 = (key2, subject) => {
|
|
577
|
+
const value = new type();
|
|
578
|
+
const desc = { set: set2 };
|
|
579
|
+
set2(value);
|
|
580
|
+
PARENT.set(value, subject);
|
|
572
581
|
function set2(next) {
|
|
573
582
|
if (next ? !(next instanceof type) : arg2 !== false)
|
|
574
583
|
throw new Error(`${subject}.${key2} expected Model of type ${type} but got ${next && next.constructor}.`);
|
|
@@ -577,8 +586,7 @@ function use(arg1, arg2) {
|
|
|
577
586
|
arg2(next);
|
|
578
587
|
return false;
|
|
579
588
|
}
|
|
580
|
-
|
|
581
|
-
return { set: set2, value };
|
|
589
|
+
return desc;
|
|
582
590
|
};
|
|
583
591
|
}
|
|
584
592
|
INSTRUCT.set(token, arg1);
|
|
@@ -831,7 +839,46 @@ function has(arg1, arg2) {
|
|
|
831
839
|
const update2 = () => {
|
|
832
840
|
subject.set(key2, Object.freeze(Array.from(applied)));
|
|
833
841
|
};
|
|
834
|
-
if (
|
|
842
|
+
if (Model.is(arg1))
|
|
843
|
+
Context.get(subject, (context) => {
|
|
844
|
+
context.get(arg1, (got) => {
|
|
845
|
+
let remove;
|
|
846
|
+
let disconnect;
|
|
847
|
+
if (applied.has(got))
|
|
848
|
+
return;
|
|
849
|
+
const callback = APPLY.get(got);
|
|
850
|
+
if (callback) {
|
|
851
|
+
const after = callback(subject);
|
|
852
|
+
if (after === false)
|
|
853
|
+
return;
|
|
854
|
+
if (typeof after == "function")
|
|
855
|
+
disconnect = after;
|
|
856
|
+
}
|
|
857
|
+
if (typeof arg2 == "function") {
|
|
858
|
+
const done2 = arg2(got, subject);
|
|
859
|
+
if (done2 === false)
|
|
860
|
+
return false;
|
|
861
|
+
remove = () => {
|
|
862
|
+
if (typeof done2 == "function")
|
|
863
|
+
done2();
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
applied.add(got);
|
|
867
|
+
update2();
|
|
868
|
+
const done = () => {
|
|
869
|
+
reset();
|
|
870
|
+
applied.delete(got);
|
|
871
|
+
update2();
|
|
872
|
+
if (disconnect)
|
|
873
|
+
disconnect();
|
|
874
|
+
if (typeof remove == "function")
|
|
875
|
+
remove();
|
|
876
|
+
};
|
|
877
|
+
const reset = got.get(null, done);
|
|
878
|
+
return done;
|
|
879
|
+
});
|
|
880
|
+
});
|
|
881
|
+
else {
|
|
835
882
|
if (APPLY.has(subject))
|
|
836
883
|
throw new Error(`'has' callback can only be used once per model.`);
|
|
837
884
|
APPLY.set(subject, (recipient) => {
|
|
@@ -850,43 +897,7 @@ function has(arg1, arg2) {
|
|
|
850
897
|
remove();
|
|
851
898
|
};
|
|
852
899
|
});
|
|
853
|
-
}
|
|
854
|
-
Context.get(subject, (ctx) => ctx.get(arg1, (got) => {
|
|
855
|
-
let remove;
|
|
856
|
-
let disconnect;
|
|
857
|
-
if (applied.has(got))
|
|
858
|
-
return;
|
|
859
|
-
const callback = APPLY.get(got);
|
|
860
|
-
if (callback) {
|
|
861
|
-
const after = callback(subject);
|
|
862
|
-
if (after === false)
|
|
863
|
-
return;
|
|
864
|
-
if (typeof after == "function")
|
|
865
|
-
disconnect = after;
|
|
866
|
-
}
|
|
867
|
-
if (typeof arg2 == "function") {
|
|
868
|
-
const done2 = arg2(got, subject);
|
|
869
|
-
if (done2 === false)
|
|
870
|
-
return false;
|
|
871
|
-
remove = () => {
|
|
872
|
-
if (typeof done2 == "function")
|
|
873
|
-
done2();
|
|
874
|
-
};
|
|
875
|
-
}
|
|
876
|
-
applied.add(got);
|
|
877
|
-
update2();
|
|
878
|
-
const done = () => {
|
|
879
|
-
reset();
|
|
880
|
-
applied.delete(got);
|
|
881
|
-
update2();
|
|
882
|
-
if (disconnect)
|
|
883
|
-
disconnect();
|
|
884
|
-
if (typeof remove == "function")
|
|
885
|
-
remove();
|
|
886
|
-
};
|
|
887
|
-
const reset = got.get(null, done);
|
|
888
|
-
return done;
|
|
889
|
-
}));
|
|
900
|
+
}
|
|
890
901
|
return { value: [] };
|
|
891
902
|
});
|
|
892
903
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -121,13 +121,13 @@ function effect(target, callback, requireValues) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// src/model.ts
|
|
124
|
-
var EXPORT;
|
|
125
124
|
var NAMES = /* @__PURE__ */ new WeakMap();
|
|
126
125
|
var STATE = /* @__PURE__ */ new WeakMap();
|
|
127
126
|
var NOTIFY = /* @__PURE__ */ new WeakMap();
|
|
128
127
|
var PENDING2 = /* @__PURE__ */ new WeakMap();
|
|
129
128
|
var PARENT = /* @__PURE__ */ new WeakMap();
|
|
130
129
|
var METHOD = /* @__PURE__ */ new WeakMap();
|
|
130
|
+
var EXPORT;
|
|
131
131
|
var define = Object.defineProperty;
|
|
132
132
|
var Model = class _Model {
|
|
133
133
|
constructor(...args) {
|
|
@@ -271,6 +271,7 @@ var Model = class _Model {
|
|
|
271
271
|
* @param args - arguments sent to constructor
|
|
272
272
|
*/
|
|
273
273
|
static new(...args) {
|
|
274
|
+
_Model.is(this);
|
|
274
275
|
const instance = new this(...args);
|
|
275
276
|
emit(instance, true);
|
|
276
277
|
return instance;
|
|
@@ -282,6 +283,8 @@ var Model = class _Model {
|
|
|
282
283
|
* methods and properties of this class.
|
|
283
284
|
*/
|
|
284
285
|
static is(maybe) {
|
|
286
|
+
if (maybe === _Model)
|
|
287
|
+
throw new Error("Model is abstract and not a valid type.");
|
|
285
288
|
return typeof maybe == "function" && maybe.prototype instanceof this;
|
|
286
289
|
}
|
|
287
290
|
/**
|
|
@@ -375,9 +378,9 @@ function assign(to, values) {
|
|
|
375
378
|
to[key2] = values[key2];
|
|
376
379
|
}
|
|
377
380
|
function bindMethods(type) {
|
|
378
|
-
let
|
|
379
|
-
if (!
|
|
380
|
-
METHODS.set(type,
|
|
381
|
+
let keys2 = METHODS.get(type);
|
|
382
|
+
if (!keys2) {
|
|
383
|
+
METHODS.set(type, keys2 = bindMethods(Object.getPrototypeOf(type)).slice());
|
|
381
384
|
const desc = Object.getOwnPropertyDescriptors(type.prototype);
|
|
382
385
|
for (const key2 in desc)
|
|
383
386
|
if (key2 != "constructor" && "value" in desc[key2]) {
|
|
@@ -389,7 +392,7 @@ function bindMethods(type) {
|
|
|
389
392
|
};
|
|
390
393
|
var bind = bind2;
|
|
391
394
|
let { value } = desc[key2];
|
|
392
|
-
|
|
395
|
+
keys2.push(key2);
|
|
393
396
|
Object.defineProperty(type.prototype, key2, {
|
|
394
397
|
set: bind2,
|
|
395
398
|
get() {
|
|
@@ -398,7 +401,7 @@ function bindMethods(type) {
|
|
|
398
401
|
});
|
|
399
402
|
}
|
|
400
403
|
}
|
|
401
|
-
return
|
|
404
|
+
return keys2;
|
|
402
405
|
}
|
|
403
406
|
function uid() {
|
|
404
407
|
return (Math.random() * 0.722 + 0.278).toString(36).substring(2, 8).toUpperCase();
|
|
@@ -406,16 +409,21 @@ function uid() {
|
|
|
406
409
|
|
|
407
410
|
// src/context.ts
|
|
408
411
|
var Register = /* @__PURE__ */ new WeakMap();
|
|
409
|
-
var
|
|
410
|
-
var Downstream = /* @__PURE__ */ new WeakMap();
|
|
412
|
+
var Table = /* @__PURE__ */ new Map();
|
|
411
413
|
function key(T, upstream) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
414
|
+
let K = Table.get(T);
|
|
415
|
+
if (!K)
|
|
416
|
+
Table.set(T, K = Symbol(
|
|
417
|
+
typeof T == "symbol" ? "get " + T.description : String(T)
|
|
418
|
+
));
|
|
419
|
+
return upstream ? key(K) : K;
|
|
420
|
+
}
|
|
421
|
+
function keys(from, upstream) {
|
|
422
|
+
const keys2 = /* @__PURE__ */ new Set();
|
|
423
|
+
do {
|
|
424
|
+
keys2.add(key(from, upstream));
|
|
425
|
+
} while ((from = Object.getPrototypeOf(from)) !== Model);
|
|
426
|
+
return keys2;
|
|
419
427
|
}
|
|
420
428
|
var Context = class _Context {
|
|
421
429
|
constructor(inputs) {
|
|
@@ -426,18 +434,20 @@ var Context = class _Context {
|
|
|
426
434
|
}
|
|
427
435
|
static get(from, callback) {
|
|
428
436
|
const waiting = Register.get(from);
|
|
429
|
-
if (
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
+
if (waiting instanceof _Context) {
|
|
438
|
+
if (callback)
|
|
439
|
+
callback(waiting);
|
|
440
|
+
return waiting;
|
|
441
|
+
}
|
|
442
|
+
if (callback)
|
|
443
|
+
if (waiting)
|
|
444
|
+
waiting.push(callback);
|
|
445
|
+
else
|
|
446
|
+
Register.set(from, [callback]);
|
|
437
447
|
}
|
|
438
448
|
get(Type, callback) {
|
|
439
449
|
if (callback)
|
|
440
|
-
|
|
450
|
+
Object.defineProperty(this, key(Type, true), { value: callback });
|
|
441
451
|
const result = this[key(Type)];
|
|
442
452
|
if (result === null)
|
|
443
453
|
throw new Error(`Did find ${Type} in context, but multiple were defined.`);
|
|
@@ -491,6 +501,7 @@ var Context = class _Context {
|
|
|
491
501
|
let T;
|
|
492
502
|
let I;
|
|
493
503
|
if (typeof input == "function") {
|
|
504
|
+
Model.is(input);
|
|
494
505
|
T = input;
|
|
495
506
|
I = new input();
|
|
496
507
|
this.cleanup.add(() => I.set(null));
|
|
@@ -498,32 +509,27 @@ var Context = class _Context {
|
|
|
498
509
|
I = input;
|
|
499
510
|
T = I.constructor;
|
|
500
511
|
}
|
|
501
|
-
|
|
502
|
-
this.put(T, I, implicit);
|
|
503
|
-
return I;
|
|
504
|
-
}
|
|
505
|
-
has(type, model) {
|
|
506
|
-
do {
|
|
507
|
-
const K = key(type, true);
|
|
512
|
+
keys(T, true).forEach((K) => {
|
|
508
513
|
const result = this[K];
|
|
509
514
|
if (!result)
|
|
510
|
-
|
|
511
|
-
const callback = result(
|
|
515
|
+
return;
|
|
516
|
+
const callback = result(I);
|
|
512
517
|
if (callback)
|
|
513
518
|
this.cleanup.add(callback);
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
if (waiting instanceof Array)
|
|
517
|
-
waiting.forEach((cb) => cb(this));
|
|
518
|
-
Register.set(model, this);
|
|
519
|
-
}
|
|
520
|
-
put(T, I, implicit) {
|
|
521
|
-
do {
|
|
522
|
-
const K = key(T, typeof I == "function");
|
|
519
|
+
});
|
|
520
|
+
keys(T).forEach((K) => {
|
|
523
521
|
const value = this.hasOwnProperty(K) ? null : I;
|
|
524
522
|
if (value || this[K] !== I && !implicit)
|
|
525
|
-
Object.defineProperty(this, K, {
|
|
526
|
-
|
|
523
|
+
Object.defineProperty(this, K, {
|
|
524
|
+
configurable: true,
|
|
525
|
+
value
|
|
526
|
+
});
|
|
527
|
+
});
|
|
528
|
+
const waiting = Register.get(I);
|
|
529
|
+
if (waiting instanceof Array)
|
|
530
|
+
waiting.forEach((cb) => cb(this));
|
|
531
|
+
Register.set(I, this);
|
|
532
|
+
return I;
|
|
527
533
|
}
|
|
528
534
|
};
|
|
529
535
|
|
|
@@ -533,8 +539,11 @@ function use(arg1, arg2) {
|
|
|
533
539
|
const token = Symbol("instruction");
|
|
534
540
|
if (Model.is(arg1)) {
|
|
535
541
|
const type = arg1;
|
|
536
|
-
const value = new type();
|
|
537
542
|
arg1 = (key2, subject) => {
|
|
543
|
+
const value = new type();
|
|
544
|
+
const desc = { set: set2 };
|
|
545
|
+
set2(value);
|
|
546
|
+
PARENT.set(value, subject);
|
|
538
547
|
function set2(next) {
|
|
539
548
|
if (next ? !(next instanceof type) : arg2 !== false)
|
|
540
549
|
throw new Error(`${subject}.${key2} expected Model of type ${type} but got ${next && next.constructor}.`);
|
|
@@ -543,8 +552,7 @@ function use(arg1, arg2) {
|
|
|
543
552
|
arg2(next);
|
|
544
553
|
return false;
|
|
545
554
|
}
|
|
546
|
-
|
|
547
|
-
return { set: set2, value };
|
|
555
|
+
return desc;
|
|
548
556
|
};
|
|
549
557
|
}
|
|
550
558
|
INSTRUCT.set(token, arg1);
|
|
@@ -797,7 +805,46 @@ function has(arg1, arg2) {
|
|
|
797
805
|
const update2 = () => {
|
|
798
806
|
subject.set(key2, Object.freeze(Array.from(applied)));
|
|
799
807
|
};
|
|
800
|
-
if (
|
|
808
|
+
if (Model.is(arg1))
|
|
809
|
+
Context.get(subject, (context) => {
|
|
810
|
+
context.get(arg1, (got) => {
|
|
811
|
+
let remove;
|
|
812
|
+
let disconnect;
|
|
813
|
+
if (applied.has(got))
|
|
814
|
+
return;
|
|
815
|
+
const callback = APPLY.get(got);
|
|
816
|
+
if (callback) {
|
|
817
|
+
const after = callback(subject);
|
|
818
|
+
if (after === false)
|
|
819
|
+
return;
|
|
820
|
+
if (typeof after == "function")
|
|
821
|
+
disconnect = after;
|
|
822
|
+
}
|
|
823
|
+
if (typeof arg2 == "function") {
|
|
824
|
+
const done2 = arg2(got, subject);
|
|
825
|
+
if (done2 === false)
|
|
826
|
+
return false;
|
|
827
|
+
remove = () => {
|
|
828
|
+
if (typeof done2 == "function")
|
|
829
|
+
done2();
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
applied.add(got);
|
|
833
|
+
update2();
|
|
834
|
+
const done = () => {
|
|
835
|
+
reset();
|
|
836
|
+
applied.delete(got);
|
|
837
|
+
update2();
|
|
838
|
+
if (disconnect)
|
|
839
|
+
disconnect();
|
|
840
|
+
if (typeof remove == "function")
|
|
841
|
+
remove();
|
|
842
|
+
};
|
|
843
|
+
const reset = got.get(null, done);
|
|
844
|
+
return done;
|
|
845
|
+
});
|
|
846
|
+
});
|
|
847
|
+
else {
|
|
801
848
|
if (APPLY.has(subject))
|
|
802
849
|
throw new Error(`'has' callback can only be used once per model.`);
|
|
803
850
|
APPLY.set(subject, (recipient) => {
|
|
@@ -816,43 +863,7 @@ function has(arg1, arg2) {
|
|
|
816
863
|
remove();
|
|
817
864
|
};
|
|
818
865
|
});
|
|
819
|
-
}
|
|
820
|
-
Context.get(subject, (ctx) => ctx.get(arg1, (got) => {
|
|
821
|
-
let remove;
|
|
822
|
-
let disconnect;
|
|
823
|
-
if (applied.has(got))
|
|
824
|
-
return;
|
|
825
|
-
const callback = APPLY.get(got);
|
|
826
|
-
if (callback) {
|
|
827
|
-
const after = callback(subject);
|
|
828
|
-
if (after === false)
|
|
829
|
-
return;
|
|
830
|
-
if (typeof after == "function")
|
|
831
|
-
disconnect = after;
|
|
832
|
-
}
|
|
833
|
-
if (typeof arg2 == "function") {
|
|
834
|
-
const done2 = arg2(got, subject);
|
|
835
|
-
if (done2 === false)
|
|
836
|
-
return false;
|
|
837
|
-
remove = () => {
|
|
838
|
-
if (typeof done2 == "function")
|
|
839
|
-
done2();
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
applied.add(got);
|
|
843
|
-
update2();
|
|
844
|
-
const done = () => {
|
|
845
|
-
reset();
|
|
846
|
-
applied.delete(got);
|
|
847
|
-
update2();
|
|
848
|
-
if (disconnect)
|
|
849
|
-
disconnect();
|
|
850
|
-
if (typeof remove == "function")
|
|
851
|
-
remove();
|
|
852
|
-
};
|
|
853
|
-
const reset = got.get(null, done);
|
|
854
|
-
return done;
|
|
855
|
-
}));
|
|
866
|
+
}
|
|
856
867
|
return { value: [] };
|
|
857
868
|
});
|
|
858
869
|
}
|
package/package.json
CHANGED