@expressive/mvc 0.9.4 → 0.9.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/lib/index.d.ts +45 -42
- package/lib/index.esm.js +39 -39
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +39 -39
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ declare class Subscriber<T extends {} = any> {
|
|
|
22
22
|
dependant: Set<Listener>;
|
|
23
23
|
watch: Map<any, boolean | (() => true | void)>;
|
|
24
24
|
constructor(parent: Control<T>, onUpdate: Subscriber.OnEvent);
|
|
25
|
-
get using(): Model.
|
|
25
|
+
get using(): Model.Field<T>[];
|
|
26
26
|
assign(apply: Model.Compat<T>, keys?: any): void;
|
|
27
27
|
add(key: any, value?: boolean | Callback): void;
|
|
28
28
|
commit: () => () => void;
|
|
@@ -45,7 +45,7 @@ declare type Debug<T extends {}> = T & {
|
|
|
45
45
|
/** Current subscriber (if present) while used in a live context (e.g. hook or effect). */
|
|
46
46
|
[LOCAL]?: Subscriber<T>;
|
|
47
47
|
/** Current state of this instance. */
|
|
48
|
-
[STATE]?: Model.
|
|
48
|
+
[STATE]?: Model.Export<T>;
|
|
49
49
|
/**
|
|
50
50
|
* Last update causing a refresh to subscribers.
|
|
51
51
|
*
|
|
@@ -78,18 +78,18 @@ declare namespace Model {
|
|
|
78
78
|
*
|
|
79
79
|
* TODO: Should exclude methods
|
|
80
80
|
**/
|
|
81
|
-
export type Field<T,
|
|
81
|
+
export type Field<T, E extends Model = Model> = Exclude<keyof T, keyof E | keyof Debug<{}>> & string;
|
|
82
82
|
/**
|
|
83
83
|
* Including but not limited to `keyof T` which are not methods or defined by base Model.
|
|
84
84
|
**/
|
|
85
|
-
export type Event<T,
|
|
85
|
+
export type Event<T, E extends Model = Model> = Extends<Field<T, E>>;
|
|
86
86
|
/** Object containing managed entries found in T. */
|
|
87
|
-
export type Entries<T,
|
|
88
|
-
[K in Field<T,
|
|
87
|
+
export type Entries<T, E extends Model = Model> = {
|
|
88
|
+
[K in Field<T, E>]: T[K];
|
|
89
89
|
};
|
|
90
90
|
/** Object comperable to data found in T. */
|
|
91
|
-
export type Compat<T,
|
|
92
|
-
[K in Field<T,
|
|
91
|
+
export type Compat<T, E extends Model = Model> = {
|
|
92
|
+
[K in Field<T, E>]?: T[K];
|
|
93
93
|
};
|
|
94
94
|
/** Actual value stored in state. */
|
|
95
95
|
export type Value<R> = R extends Ref<infer T> ? T : R;
|
|
@@ -103,6 +103,9 @@ declare namespace Model {
|
|
|
103
103
|
export type Values<T, K extends Field<T> = Field<T>> = {
|
|
104
104
|
[P in K]: Value<T[P]>;
|
|
105
105
|
};
|
|
106
|
+
export type Export<T, E extends Model = Model> = {
|
|
107
|
+
[P in Field<T, E>]: Value<T[P]>;
|
|
108
|
+
};
|
|
106
109
|
}
|
|
107
110
|
declare class Model {
|
|
108
111
|
/**
|
|
@@ -124,7 +127,7 @@ declare class Model {
|
|
|
124
127
|
on(current?: boolean): Promise<Model.Event<this>[] | null>;
|
|
125
128
|
on(current: true): Promise<Model.Event<this>[]>;
|
|
126
129
|
on(current: null): Promise<null>;
|
|
127
|
-
export(): Model.
|
|
130
|
+
export(): Model.Export<this>;
|
|
128
131
|
export<P extends Model.Field<this>>(select: Iterable<P>): Model.Values<this, P>;
|
|
129
132
|
update(key: Model.Event<this>): PromiseLike<readonly Model.Event<this>[]>;
|
|
130
133
|
update(key: Model.Event<this>, callMethod: boolean): PromiseLike<readonly Model.Event<this>[]>;
|
|
@@ -460,6 +463,39 @@ declare class MVC extends Model {
|
|
|
460
463
|
static meta<T, M extends Class>(this: M, from: (this: M, state: M) => T, expect?: boolean): T;
|
|
461
464
|
}
|
|
462
465
|
|
|
466
|
+
declare function useValue<T extends {}, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
467
|
+
declare function useValue<T extends {}, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
468
|
+
|
|
469
|
+
declare class Lookup {
|
|
470
|
+
private table;
|
|
471
|
+
get local(): Model[];
|
|
472
|
+
private key;
|
|
473
|
+
get(T: Model.Type): any;
|
|
474
|
+
push(): this;
|
|
475
|
+
inject(T: Model.Type, I: Model, writable?: boolean): void;
|
|
476
|
+
pop(): void;
|
|
477
|
+
}
|
|
478
|
+
declare function useContext<T extends Model>(Type: Model.Type<T>, required: false): T | undefined;
|
|
479
|
+
declare function useContext<T extends Model>(Type: Model.Type<T>, arg?: boolean): T;
|
|
480
|
+
declare function useContext<T extends Model>(Type: Model.Type<T>, effect: (found: T) => Callback | void): T;
|
|
481
|
+
declare function useContext<T extends Model, K extends Model.Field<T>>(Type: Model.Type<T>, key: K): T[K];
|
|
482
|
+
|
|
483
|
+
declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), callback?: (instance: T) => void): T;
|
|
484
|
+
declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), watch: Model.Field<T>[], callback?: (instance: T) => void): T;
|
|
485
|
+
declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), apply: Model.Compat<T>, keys?: Model.Event<T>[]): T;
|
|
486
|
+
|
|
487
|
+
declare namespace useTap {
|
|
488
|
+
type Source<T extends Model> = T | Model.Type<T> | (() => T | Model.Type<T>);
|
|
489
|
+
}
|
|
490
|
+
declare function useTap<T extends Model>(source: useTap.Source<T>): T;
|
|
491
|
+
declare function useTap<T extends Model, K extends Model.Field<T>>(source: useTap.Source<T>, path: K, expect: true): Exclude<T[K], undefined>;
|
|
492
|
+
declare function useTap<T extends Model, K extends Model.Field<T>>(source: useTap.Source<T>, path: K, expect?: boolean): T[K];
|
|
493
|
+
declare function useTap<T extends Model, R>(source: useTap.Source<T>, connect: (this: T, model: T) => () => R): R;
|
|
494
|
+
declare function useTap<T extends Model, R>(source: useTap.Source<T>, connect: (this: T, model: T) => (() => R) | null): R | null;
|
|
495
|
+
declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, model: T) => Promise<R> | R, expect: true): Exclude<R, undefined>;
|
|
496
|
+
declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, model: T) => Promise<R>, expect?: boolean): R | undefined;
|
|
497
|
+
declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, model: T) => R, expect?: boolean): R;
|
|
498
|
+
|
|
463
499
|
declare namespace Consumer {
|
|
464
500
|
type HasProps<E extends Class> = {
|
|
465
501
|
/** @deprecated - use for instead */
|
|
@@ -497,20 +533,6 @@ declare namespace Consumer {
|
|
|
497
533
|
}
|
|
498
534
|
declare function Consumer<T extends Class>(props: Consumer.Props<T>): any;
|
|
499
535
|
|
|
500
|
-
declare class Lookup {
|
|
501
|
-
private table;
|
|
502
|
-
get local(): Model[];
|
|
503
|
-
private key;
|
|
504
|
-
get(T: Model.Type): any;
|
|
505
|
-
push(): this;
|
|
506
|
-
inject(T: Model.Type, I: Model, writable?: boolean): void;
|
|
507
|
-
pop(): void;
|
|
508
|
-
}
|
|
509
|
-
declare function useContext<T extends Model>(Type: Model.Type<T>, required: false): T | undefined;
|
|
510
|
-
declare function useContext<T extends Model>(Type: Model.Type<T>, arg?: boolean): T;
|
|
511
|
-
declare function useContext<T extends Model>(Type: Model.Type<T>, effect: (found: T) => Callback | void): T;
|
|
512
|
-
declare function useContext<T extends Model, K extends Model.Field<T>>(Type: Model.Type<T>, key: K): T[K];
|
|
513
|
-
|
|
514
536
|
declare namespace Provider {
|
|
515
537
|
type Item = Model | Model.Type;
|
|
516
538
|
type Multiple<T extends Item = Item> = T[] | {
|
|
@@ -585,23 +607,4 @@ declare function tap<T extends Model>(Type: Model.Type<T>, callback?: (instance?
|
|
|
585
607
|
declare function tap<T extends Model>(Type: Model.Type<T>, required: true): T;
|
|
586
608
|
declare function tap<T extends Model>(Type: Model.Type<T>, required?: boolean): T | undefined;
|
|
587
609
|
|
|
588
|
-
declare function useValue<T extends {}, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
589
|
-
declare function useValue<T extends {}, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
590
|
-
|
|
591
|
-
declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), callback?: (instance: T) => void): T;
|
|
592
|
-
declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), watch: Model.Field<T>[], callback?: (instance: T) => void): T;
|
|
593
|
-
declare function useModel<T extends Model>(source: Model.Type<T> | (() => T), apply: Model.Compat<T>, keys?: Model.Event<T>[]): T;
|
|
594
|
-
|
|
595
|
-
declare namespace useTap {
|
|
596
|
-
type Source<T extends Model> = T | Model.Type<T> | (() => T | Model.Type<T>);
|
|
597
|
-
}
|
|
598
|
-
declare function useTap<T extends Model>(source: useTap.Source<T>): T;
|
|
599
|
-
declare function useTap<T extends Model, K extends Model.Field<T>>(source: useTap.Source<T>, path: K, expect: true): Exclude<T[K], undefined>;
|
|
600
|
-
declare function useTap<T extends Model, K extends Model.Field<T>>(source: useTap.Source<T>, path: K, expect?: boolean): T[K];
|
|
601
|
-
declare function useTap<T extends Model, R>(source: useTap.Source<T>, connect: (this: T, model: T) => () => R): R;
|
|
602
|
-
declare function useTap<T extends Model, R>(source: useTap.Source<T>, connect: (this: T, model: T) => (() => R) | null): R | null;
|
|
603
|
-
declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, model: T) => Promise<R> | R, expect: true): Exclude<R, undefined>;
|
|
604
|
-
declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, model: T) => Promise<R>, expect?: boolean): R | undefined;
|
|
605
|
-
declare function useTap<T extends Model, R>(source: useTap.Source<T>, compute: (this: T, model: T) => R, expect?: boolean): R;
|
|
606
|
-
|
|
607
610
|
export { Consumer, Debug, Global, MVC, MVC as Model, Provider, add, MVC as default, get, has, ref, run, set, tap, use, useContext, useModel, useTap, useValue };
|
package/lib/index.esm.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React, { useState, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
+
const { assign, create, defineProperties, defineProperty, entries, getPrototypeOf, getOwnPropertyNames, getOwnPropertyDescriptor, getOwnPropertySymbols, values } = Object;
|
|
4
|
+
|
|
3
5
|
class Issue extends Error {
|
|
4
6
|
constructor() {
|
|
5
7
|
super(...arguments);
|
|
@@ -17,8 +19,6 @@ function issues(register) {
|
|
|
17
19
|
return Library;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
const { assign, create, defineProperties, defineProperty, entries, getPrototypeOf, getOwnPropertyNames, getOwnPropertyDescriptor, getOwnPropertySymbols, values } = Object;
|
|
21
|
-
|
|
22
22
|
const Oops$e = issues({
|
|
23
23
|
NotReady: (model, key) => `Value ${model}.${key} value is not yet available.`,
|
|
24
24
|
});
|
|
@@ -1364,43 +1364,6 @@ class MVC extends Model {
|
|
|
1364
1364
|
}
|
|
1365
1365
|
}
|
|
1366
1366
|
|
|
1367
|
-
const LOCAL = "$debug local";
|
|
1368
|
-
const STATE = "$debug state";
|
|
1369
|
-
const UPDATE = "$debug update";
|
|
1370
|
-
const CONTROL = "$debug controller";
|
|
1371
|
-
defineProperties(Model.prototype, {
|
|
1372
|
-
[CONTROL]: {
|
|
1373
|
-
get() {
|
|
1374
|
-
return Control.get(this);
|
|
1375
|
-
}
|
|
1376
|
-
},
|
|
1377
|
-
[LOCAL]: {
|
|
1378
|
-
get() {
|
|
1379
|
-
return Subscriber.get(this);
|
|
1380
|
-
}
|
|
1381
|
-
},
|
|
1382
|
-
[STATE]: {
|
|
1383
|
-
get() {
|
|
1384
|
-
const { state } = Control.get(this);
|
|
1385
|
-
const output = {};
|
|
1386
|
-
state.forEach((value, key) => output[key] = value);
|
|
1387
|
-
return output;
|
|
1388
|
-
}
|
|
1389
|
-
},
|
|
1390
|
-
[UPDATE]: {
|
|
1391
|
-
get() {
|
|
1392
|
-
const source = Subscriber.get(this) || Control.get(this);
|
|
1393
|
-
return source && source.latest;
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
});
|
|
1397
|
-
const Debug = {
|
|
1398
|
-
CONTROL,
|
|
1399
|
-
LOCAL,
|
|
1400
|
-
STATE,
|
|
1401
|
-
UPDATE
|
|
1402
|
-
};
|
|
1403
|
-
|
|
1404
1367
|
const Oops$2 = issues({
|
|
1405
1368
|
BadProps: () => `Provider expects either a render function, 'get' or 'has' props.`
|
|
1406
1369
|
});
|
|
@@ -1530,5 +1493,42 @@ class Global extends MVC {
|
|
|
1530
1493
|
}
|
|
1531
1494
|
Global.keepAlive = true;
|
|
1532
1495
|
|
|
1496
|
+
const LOCAL = "$debug local";
|
|
1497
|
+
const STATE = "$debug state";
|
|
1498
|
+
const UPDATE = "$debug update";
|
|
1499
|
+
const CONTROL = "$debug controller";
|
|
1500
|
+
defineProperties(Model.prototype, {
|
|
1501
|
+
[CONTROL]: {
|
|
1502
|
+
get() {
|
|
1503
|
+
return Control.get(this);
|
|
1504
|
+
}
|
|
1505
|
+
},
|
|
1506
|
+
[LOCAL]: {
|
|
1507
|
+
get() {
|
|
1508
|
+
return Subscriber.get(this);
|
|
1509
|
+
}
|
|
1510
|
+
},
|
|
1511
|
+
[STATE]: {
|
|
1512
|
+
get() {
|
|
1513
|
+
const { state } = Control.get(this);
|
|
1514
|
+
const output = {};
|
|
1515
|
+
state.forEach((value, key) => output[key] = value);
|
|
1516
|
+
return output;
|
|
1517
|
+
}
|
|
1518
|
+
},
|
|
1519
|
+
[UPDATE]: {
|
|
1520
|
+
get() {
|
|
1521
|
+
const source = Subscriber.get(this) || Control.get(this);
|
|
1522
|
+
return source && source.latest;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
const Debug = {
|
|
1527
|
+
CONTROL,
|
|
1528
|
+
LOCAL,
|
|
1529
|
+
STATE,
|
|
1530
|
+
UPDATE
|
|
1531
|
+
};
|
|
1532
|
+
|
|
1533
1533
|
export { Consumer, Debug, Global, MVC, MVC as Model, Provider, add, MVC as default, get, has, ref, run, set, tap, use$1 as use, useContext, useModel, useTap, useValue };
|
|
1534
1534
|
//# sourceMappingURL=index.esm.js.map
|