@expressive/mvc 0.2.1 → 0.2.4
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 +15 -5
- package/lib/index.esm.js +11 -6
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +10 -5
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -430,19 +430,26 @@ declare class MVC extends Model {
|
|
|
430
430
|
/**
|
|
431
431
|
* **React Hook** - Fetch most instance of this controller from context, if it exists.
|
|
432
432
|
*
|
|
433
|
-
* @param required -
|
|
433
|
+
* @param required - Unless false, will throw where instance cannot be found.
|
|
434
434
|
*/
|
|
435
|
-
static get<T extends Class>(this: T, required?:
|
|
435
|
+
static get<T extends Class>(this: T, required?: boolean): InstanceOf<T>;
|
|
436
436
|
/**
|
|
437
437
|
* **React Hook** - Fetch most instance of this controller from context.
|
|
438
438
|
*
|
|
439
|
-
* @param required -
|
|
439
|
+
* @param required - If false, may return undefined.
|
|
440
440
|
*/
|
|
441
|
-
static get<T extends Class>(this: T, required:
|
|
441
|
+
static get<T extends Class>(this: T, required: false): InstanceOf<T> | undefined;
|
|
442
442
|
/**
|
|
443
443
|
* **React Hook** - Fetch specific value from instance of this controller in context.
|
|
444
444
|
*/
|
|
445
445
|
static get<T extends Class, I extends InstanceOf<T>, K extends Model.Field<I>>(this: T, key: K): I[K];
|
|
446
|
+
/**
|
|
447
|
+
* **React Hook** - Fetch instance.
|
|
448
|
+
*
|
|
449
|
+
* Effect callback will run once if found, throw if not found.
|
|
450
|
+
* Returned function is called on unmount.
|
|
451
|
+
*/
|
|
452
|
+
static get<T extends Class, I extends InstanceOf<T>>(this: T, effect: (found: I) => Callback | void): I;
|
|
446
453
|
/**
|
|
447
454
|
* **React Hook** - Fetch and subscribe to instance of this controller within ambient component.
|
|
448
455
|
*/
|
|
@@ -611,7 +618,10 @@ declare function tap<T extends Class>(Type: T, required?: boolean): InstanceOf<T
|
|
|
611
618
|
declare function useFrom<T extends Stateful, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
612
619
|
declare function useFrom<T extends Stateful, R>(source: (() => T) | T, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
613
620
|
|
|
614
|
-
declare function useLocal<T extends typeof Model>(Type: T,
|
|
621
|
+
declare function useLocal<T extends typeof Model>(Type: T, required: false): InstanceOf<T> | undefined;
|
|
622
|
+
declare function useLocal<T extends typeof Model>(Type: T, arg?: boolean): InstanceOf<T>;
|
|
623
|
+
declare function useLocal<T extends typeof Model, I extends InstanceOf<T>>(Type: T, effect: (found: I) => Callback | void): I;
|
|
624
|
+
declare function useLocal<T extends typeof Model, I extends InstanceOf<T>, K extends Model.Field<I>>(Type: T, key: K): I[K];
|
|
615
625
|
|
|
616
626
|
declare function useModel<T extends Class, I extends InstanceOf<T>>(source: T, watch: Model.Field<I>[], callback?: (instance: I) => void): I;
|
|
617
627
|
declare function useModel<T extends Class, I extends InstanceOf<T>>(source: T, callback?: (instance: I) => void): I;
|
package/lib/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useMemo } from 'react';
|
|
1
|
+
import React, { useLayoutEffect, useState, useMemo } from 'react';
|
|
2
2
|
|
|
3
3
|
/*! *****************************************************************************
|
|
4
4
|
Copyright (c) Microsoft Corporation.
|
|
@@ -1027,9 +1027,14 @@ function useLocal(Type, arg) {
|
|
|
1027
1027
|
const instance = useLookup().get(Type);
|
|
1028
1028
|
if (!instance && arg !== false)
|
|
1029
1029
|
throw Oops$4.NotFound(Type.name);
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1030
|
+
switch (typeof arg) {
|
|
1031
|
+
case "string":
|
|
1032
|
+
return instance[arg];
|
|
1033
|
+
case "function":
|
|
1034
|
+
useLayoutEffect(() => arg(instance), []);
|
|
1035
|
+
default:
|
|
1036
|
+
return instance;
|
|
1037
|
+
}
|
|
1033
1038
|
}
|
|
1034
1039
|
|
|
1035
1040
|
const Oops$3 = issues({
|
|
@@ -1225,8 +1230,8 @@ class MVC extends Model {
|
|
|
1225
1230
|
use(arg, callback) {
|
|
1226
1231
|
return useModel(this, arg, callback);
|
|
1227
1232
|
}
|
|
1228
|
-
static get(
|
|
1229
|
-
return useLocal(this,
|
|
1233
|
+
static get(arg) {
|
|
1234
|
+
return useLocal(this, arg);
|
|
1230
1235
|
}
|
|
1231
1236
|
static tap(key, expect) {
|
|
1232
1237
|
return useTap(this, key, expect);
|