@expressive/mvc 0.14.0 → 0.15.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/lib/index.d.ts +23 -9
- package/lib/index.esm.js +3 -1
- package/lib/index.js +3 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -61,7 +61,10 @@ declare namespace Model {
|
|
|
61
61
|
export { Subscriber };
|
|
62
62
|
/** Including but not limited to T. */
|
|
63
63
|
type Extends<T> = T | (string & Record<never, never>);
|
|
64
|
-
|
|
64
|
+
/** Any typeof Model, using class constructor as the reference. */
|
|
65
|
+
export type Type<T extends Model = Model> = (new (...args: any[]) => T);
|
|
66
|
+
/** A typeof Model, specifically one which may be created without arguments. */
|
|
67
|
+
export type Constructor<T extends Model = Model> = (new () => T) & typeof Model;
|
|
65
68
|
export type Effect<T> = (this: T, argument: T) => Callback | Promise<any> | void;
|
|
66
69
|
/** Exotic value, actual value is contained. */
|
|
67
70
|
export type Ref<T = any> = {
|
|
@@ -105,7 +108,7 @@ declare namespace Model {
|
|
|
105
108
|
export type Get<T, K extends Key<T> = Key<T>> = {
|
|
106
109
|
[P in K]: Value<T[P]>;
|
|
107
110
|
};
|
|
108
|
-
export type Export<T
|
|
111
|
+
export type Export<T> = {
|
|
109
112
|
[P in Key<T>]: Value<T[P]>;
|
|
110
113
|
};
|
|
111
114
|
}
|
|
@@ -386,7 +389,7 @@ declare function use<T extends Model>(from: () => T, required: boolean): T;
|
|
|
386
389
|
/**
|
|
387
390
|
* Create a new child instance of model.
|
|
388
391
|
*/
|
|
389
|
-
declare function use<T extends Model>(Type: Model.
|
|
392
|
+
declare function use<T extends Model>(Type: Model.Constructor<T>, callback?: (i: T) => void): T;
|
|
390
393
|
/**
|
|
391
394
|
* Create a managed child from factory function.
|
|
392
395
|
*/
|
|
@@ -418,8 +421,19 @@ declare function has<T extends Model>(Type: Model.Type<T>, required?: true): T;
|
|
|
418
421
|
declare namespace MVC {
|
|
419
422
|
type EffectCallback<T = MVC> = (found: T) => Callback | void;
|
|
420
423
|
type ForceUpdate = {
|
|
424
|
+
/** Force an update in current component. */
|
|
421
425
|
(): void;
|
|
426
|
+
/**
|
|
427
|
+
* Force an update and again after promise either resolves or rejects.
|
|
428
|
+
* Will return a duplicate of given Promise, which resolves after refresh.
|
|
429
|
+
*/
|
|
422
430
|
<T = void>(passthru?: Promise<T>): Promise<T>;
|
|
431
|
+
/**
|
|
432
|
+
* Force a update while calling async function.
|
|
433
|
+
* A refresh will occur both before and after given function.
|
|
434
|
+
* Any actions performed before first `await` will occur before refresh!
|
|
435
|
+
*/
|
|
436
|
+
<T = void>(invoke?: () => Promise<T>): Promise<T>;
|
|
423
437
|
};
|
|
424
438
|
type TapCallback<T extends Model, R> = (this: T, model: T, update: MVC.ForceUpdate) => R;
|
|
425
439
|
}
|
|
@@ -482,9 +496,9 @@ declare class MVC extends Model {
|
|
|
482
496
|
declare function useContext<T extends Model>(Type: Model.Type<T>, required: false): T | undefined;
|
|
483
497
|
declare function useContext<T extends Model>(Type: Model.Type<T>, required?: boolean): T;
|
|
484
498
|
|
|
485
|
-
declare function useNew<T extends Model>(source: Model.
|
|
486
|
-
declare function useNew<T extends Model>(source: Model.
|
|
487
|
-
declare function useNew<T extends Model>(source: Model.
|
|
499
|
+
declare function useNew<T extends Model>(source: Model.Constructor<T> | (() => T), callback?: (instance: T) => void): T;
|
|
500
|
+
declare function useNew<T extends Model>(source: Model.Constructor<T> | (() => T), watch: Model.Key<T>[], callback?: (instance: T) => void): T;
|
|
501
|
+
declare function useNew<T extends Model>(source: Model.Constructor<T> | (() => T), apply: Model.Compat<T>, keys?: Model.Event<T>[]): T;
|
|
488
502
|
|
|
489
503
|
declare namespace useTap {
|
|
490
504
|
type Source<T extends Model> = T | Model.Type<T> | (() => T | Model.Type<T>);
|
|
@@ -537,7 +551,7 @@ declare namespace Consumer {
|
|
|
537
551
|
declare function Consumer<T extends Class>(props: Consumer.Props<T>): any;
|
|
538
552
|
|
|
539
553
|
declare namespace Provider {
|
|
540
|
-
type Item = Model | Model.
|
|
554
|
+
type Item = Model | Model.Constructor;
|
|
541
555
|
type Multiple<T extends Item = Item> = T[] | {
|
|
542
556
|
[key: string]: T;
|
|
543
557
|
};
|
|
@@ -546,13 +560,13 @@ declare namespace Provider {
|
|
|
546
560
|
for: E;
|
|
547
561
|
fallback?: React.ReactNode;
|
|
548
562
|
children?: React.ReactNode | ((instance: I) => React.ReactNode);
|
|
549
|
-
|
|
563
|
+
use?: Model.Compat<I>;
|
|
550
564
|
};
|
|
551
565
|
type MultipleProps<T extends Item> = {
|
|
552
566
|
for: Multiple<T>;
|
|
553
567
|
fallback?: React.ReactNode;
|
|
554
568
|
children?: React.ReactNode;
|
|
555
|
-
|
|
569
|
+
use?: Model.Compat<Instance<T>>;
|
|
556
570
|
};
|
|
557
571
|
type Props<T extends Item> = MultipleProps<T> | NormalProps<T>;
|
|
558
572
|
}
|
package/lib/index.esm.js
CHANGED
|
@@ -1356,6 +1356,8 @@ function useCompute(source, compute, suspend) {
|
|
|
1356
1356
|
const spy = sub.proxy;
|
|
1357
1357
|
let make = () => compute.call(spy, spy, forceUpdate);
|
|
1358
1358
|
function forceUpdate(passthru) {
|
|
1359
|
+
if (typeof passthru == "function")
|
|
1360
|
+
passthru = passthru();
|
|
1359
1361
|
if (make)
|
|
1360
1362
|
reassign(make());
|
|
1361
1363
|
else
|
|
@@ -1526,7 +1528,7 @@ const Oops = issues({
|
|
|
1526
1528
|
NoType: () => "Provider 'for' prop must be Model, typeof Model or a collection of them."
|
|
1527
1529
|
});
|
|
1528
1530
|
function Provider(props) {
|
|
1529
|
-
const context = useNewContext(props.for, props.
|
|
1531
|
+
const context = useNewContext(props.for, props.use);
|
|
1530
1532
|
return (React.createElement(LookupContext.Provider, { value: context }, props.fallback === false
|
|
1531
1533
|
? props.children
|
|
1532
1534
|
: (React.createElement(Suspense, { fallback: props.fallback || null }, props.children))));
|
package/lib/index.js
CHANGED
|
@@ -1364,6 +1364,8 @@ function useCompute(source, compute, suspend) {
|
|
|
1364
1364
|
const spy = sub.proxy;
|
|
1365
1365
|
let make = () => compute.call(spy, spy, forceUpdate);
|
|
1366
1366
|
function forceUpdate(passthru) {
|
|
1367
|
+
if (typeof passthru == "function")
|
|
1368
|
+
passthru = passthru();
|
|
1367
1369
|
if (make)
|
|
1368
1370
|
reassign(make());
|
|
1369
1371
|
else
|
|
@@ -1534,7 +1536,7 @@ const Oops = issues({
|
|
|
1534
1536
|
NoType: () => "Provider 'for' prop must be Model, typeof Model or a collection of them."
|
|
1535
1537
|
});
|
|
1536
1538
|
function Provider(props) {
|
|
1537
|
-
const context = useNewContext(props.for, props.
|
|
1539
|
+
const context = useNewContext(props.for, props.use);
|
|
1538
1540
|
return (React__default["default"].createElement(LookupContext.Provider, { value: context }, props.fallback === false
|
|
1539
1541
|
? props.children
|
|
1540
1542
|
: (React__default["default"].createElement(React.Suspense, { fallback: props.fallback || null }, props.children))));
|
package/package.json
CHANGED