@expressive/mvc 0.2.6 → 0.3.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 +36 -39
- package/lib/index.esm.js +67 -56
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +67 -55
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -300,30 +300,10 @@ declare function ref<T extends Model>(target: T): ref.Proxy<T>;
|
|
|
300
300
|
declare function ref<T = HTMLElement>(callback?: ref.Callback<T>): ref.Object<T>;
|
|
301
301
|
declare function ref<T, S>(callback?: ref.Callback<T, S>): ref.Object<T>;
|
|
302
302
|
|
|
303
|
-
declare namespace set {
|
|
303
|
+
declare namespace set$1 {
|
|
304
304
|
type Factory<T, S = unknown> = (this: S, key: string, subject: S) => T;
|
|
305
305
|
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
306
306
|
}
|
|
307
|
-
/**
|
|
308
|
-
* Set property with a placeholder.
|
|
309
|
-
*
|
|
310
|
-
* Property cannot be accessed until it is defined. If accessed while undefined, a hybrid
|
|
311
|
-
* `Promise`/`Error` (ala: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.
|
|
312
|
-
*/
|
|
313
|
-
declare function set<T = any>(): T;
|
|
314
|
-
/**
|
|
315
|
-
* Set property with starting value `undefined`.
|
|
316
|
-
*
|
|
317
|
-
* If required and accessed while still empty, React Suspense will be thrown.
|
|
318
|
-
* Property will reject any assignment of undefined.
|
|
319
|
-
*
|
|
320
|
-
* @param value - Starting value of host property (undefined).
|
|
321
|
-
* @param required - Property will suspend callee if undefined at time of access.
|
|
322
|
-
*/
|
|
323
|
-
declare function set<T>(value: undefined, required: false): T | undefined;
|
|
324
|
-
declare function set<T>(value: undefined, required?: boolean): T;
|
|
325
|
-
declare function set<T>(value: undefined, onUpdate: set.Callback<T>): T | undefined;
|
|
326
|
-
declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T | undefined;
|
|
327
307
|
/**
|
|
328
308
|
* Set property with an async function.
|
|
329
309
|
*
|
|
@@ -339,12 +319,12 @@ declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T |
|
|
|
339
319
|
* @param factory - Callback run to derrive property value.
|
|
340
320
|
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
341
321
|
*/
|
|
342
|
-
declare function
|
|
343
|
-
declare function
|
|
344
|
-
declare function
|
|
345
|
-
declare function
|
|
346
|
-
declare function
|
|
347
|
-
declare function
|
|
322
|
+
declare function put<T>(factory: set$1.Factory<Promise<T>>, required: false): T | undefined;
|
|
323
|
+
declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required: false): T | undefined;
|
|
324
|
+
declare function put<T>(factory: set$1.Factory<Promise<T>>, required?: boolean): T;
|
|
325
|
+
declare function put<T, S>(factory: set$1.Factory<Promise<T>, S>, required?: boolean): T;
|
|
326
|
+
declare function put<T>(value: set$1.Factory<Promise<T>>, onUpdate: set$1.Callback<T>): T;
|
|
327
|
+
declare function put<T, S>(value: set$1.Factory<Promise<T>, S>, onUpdate: set$1.Callback<T, S>): T;
|
|
348
328
|
/**
|
|
349
329
|
* Set property with a factory function.
|
|
350
330
|
*
|
|
@@ -357,24 +337,41 @@ declare function set<T, S>(value: set.Factory<Promise<T>, S>, onUpdate: set.Call
|
|
|
357
337
|
* @param factory - Callback run to derrive property value.
|
|
358
338
|
* @param required - (default: true) Run factory immediately on creation, otherwise on access.
|
|
359
339
|
*/
|
|
360
|
-
declare function
|
|
361
|
-
declare function
|
|
362
|
-
declare function
|
|
363
|
-
declare function
|
|
364
|
-
declare function
|
|
365
|
-
declare function
|
|
340
|
+
declare function put<T>(factory: set$1.Factory<T>, required: false): T | undefined;
|
|
341
|
+
declare function put<T, S>(factory: set$1.Factory<T, S>, required: false): T | undefined;
|
|
342
|
+
declare function put<T>(factory: set$1.Factory<T>, required?: boolean): T;
|
|
343
|
+
declare function put<T, S>(factory: set$1.Factory<T, S>, required?: boolean): T;
|
|
344
|
+
declare function put<T>(value: set$1.Factory<T>, onUpdate: set$1.Callback<T>): T;
|
|
345
|
+
declare function put<T, S>(value: set$1.Factory<T, S>, onUpdate: set$1.Callback<T, S>): T;
|
|
366
346
|
/**
|
|
367
347
|
* Assign a property with result of a promise.
|
|
368
348
|
*/
|
|
369
|
-
declare function
|
|
370
|
-
declare function
|
|
371
|
-
declare function
|
|
349
|
+
declare function put<T>(factory: Promise<T>, required: false): T | undefined;
|
|
350
|
+
declare function put<T>(factory: Promise<T>, required?: boolean): T;
|
|
351
|
+
declare function put<T>(value: Promise<T>, onUpdate: set$1.Callback<T>): T;
|
|
372
352
|
/**
|
|
373
353
|
* Assign a property.
|
|
374
354
|
*/
|
|
375
|
-
declare function
|
|
376
|
-
declare function
|
|
355
|
+
declare function put<T>(factory: T, required: false): T | undefined;
|
|
356
|
+
declare function put<T>(factory: T, required?: boolean): T;
|
|
357
|
+
declare function put<T>(value: T, onUpdate: set$1.Callback<T>): T;
|
|
358
|
+
|
|
359
|
+
declare namespace set {
|
|
360
|
+
type Callback<T, S = any> = (this: S, argument: T) => ((next: T) => void) | Promise<any> | void | boolean;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Set property with a placeholder.
|
|
364
|
+
*
|
|
365
|
+
* Property cannot be accessed until it is defined. If accessed while undefined, a hybrid
|
|
366
|
+
* `Promise`/`Error` (ala: [Suspense](https://reactjs.org/docs/concurrent-mode-suspense.html)) will be thrown.
|
|
367
|
+
*/
|
|
368
|
+
declare function set<T = any>(): T;
|
|
369
|
+
declare function set<T>(onUpdate: set.Callback<T>): T;
|
|
370
|
+
declare function set<T, S>(onUpdate: set.Callback<T, S>): T;
|
|
371
|
+
declare function set<T>(value: undefined, onUpdate: set.Callback<T>): T;
|
|
372
|
+
declare function set<T, S>(value: undefined, onUpdate: set.Callback<T, S>): T;
|
|
377
373
|
declare function set<T>(value: T, onUpdate: set.Callback<T>): T;
|
|
374
|
+
declare function set<T, S>(value: T, onUpdate: set.Callback<T, S>): T;
|
|
378
375
|
|
|
379
376
|
/**
|
|
380
377
|
* Create a placeholder for specified Model type.
|
|
@@ -642,4 +639,4 @@ declare function useTap<T extends Stateful, K extends Model.Field<T>>(source: T
|
|
|
642
639
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect: true): Exclude<R, undefined>;
|
|
643
640
|
declare function useTap<T extends Stateful, R>(source: T | (() => T) | useTap.Tappable, compute: (this: T, from: T) => R, expect?: boolean): R;
|
|
644
641
|
|
|
645
|
-
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, array, MVC as default, from, parent, ref, set, tap, use, useFrom, useLocal, useModel, useTap };
|
|
642
|
+
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, Stateful, WHY, act, apply, array, MVC as default, from, parent, put, ref, set, tap, use, useFrom, useLocal, useModel, useTap };
|
package/lib/index.esm.js
CHANGED
|
@@ -843,65 +843,60 @@ const Oops$7 = issues({
|
|
|
843
843
|
NotReady: (model, key) => `Value ${model}.${key} value is not yet available.`,
|
|
844
844
|
Failed: (model, key) => `Generating initial value for ${model}.${key} failed.`
|
|
845
845
|
});
|
|
846
|
-
function
|
|
846
|
+
function put(factory, argument) {
|
|
847
847
|
return apply(function set(key) {
|
|
848
848
|
const { subject, state } = this;
|
|
849
849
|
const required = argument === true || argument === undefined;
|
|
850
850
|
let set;
|
|
851
851
|
let get;
|
|
852
|
-
let
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
pending =
|
|
864
|
-
|
|
865
|
-
.then(val => state[key] = val)
|
|
866
|
-
.finally(() => {
|
|
867
|
-
pending = undefined;
|
|
868
|
-
this.update(key);
|
|
869
|
-
});
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
return state[key] = output;
|
|
873
|
-
};
|
|
874
|
-
const suspend = () => {
|
|
875
|
-
if (required === false)
|
|
876
|
-
return undefined;
|
|
877
|
-
const issue = Oops$7.NotReady(subject, key);
|
|
878
|
-
Object.assign(pending, {
|
|
879
|
-
message: issue.message,
|
|
880
|
-
stack: issue.stack
|
|
852
|
+
let pending;
|
|
853
|
+
let error;
|
|
854
|
+
const init = () => {
|
|
855
|
+
const output = typeof factory == "function" ?
|
|
856
|
+
mayRetry(() => factory.call(subject, key, subject)) :
|
|
857
|
+
factory;
|
|
858
|
+
if (output instanceof Promise) {
|
|
859
|
+
pending = output
|
|
860
|
+
.catch(err => error = err)
|
|
861
|
+
.then(val => state[key] = val)
|
|
862
|
+
.finally(() => {
|
|
863
|
+
pending = undefined;
|
|
864
|
+
this.update(key);
|
|
881
865
|
});
|
|
882
|
-
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
904
|
-
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
return state[key] = output;
|
|
869
|
+
};
|
|
870
|
+
const suspend = () => {
|
|
871
|
+
if (required === false)
|
|
872
|
+
return undefined;
|
|
873
|
+
const issue = Oops$7.NotReady(subject, key);
|
|
874
|
+
Object.assign(pending, {
|
|
875
|
+
message: issue.message,
|
|
876
|
+
stack: issue.stack
|
|
877
|
+
});
|
|
878
|
+
throw pending;
|
|
879
|
+
};
|
|
880
|
+
if (required)
|
|
881
|
+
try {
|
|
882
|
+
init();
|
|
883
|
+
}
|
|
884
|
+
catch (err) {
|
|
885
|
+
Oops$7.Failed(subject, key).warn();
|
|
886
|
+
throw err;
|
|
887
|
+
}
|
|
888
|
+
get = () => {
|
|
889
|
+
if (pending)
|
|
890
|
+
return suspend();
|
|
891
|
+
if (error)
|
|
892
|
+
throw error;
|
|
893
|
+
if (key in state)
|
|
894
|
+
return state[key];
|
|
895
|
+
let output = init();
|
|
896
|
+
return pending
|
|
897
|
+
? suspend()
|
|
898
|
+
: output;
|
|
899
|
+
};
|
|
905
900
|
if (typeof argument == "function")
|
|
906
901
|
set = createValueEffect(argument);
|
|
907
902
|
else
|
|
@@ -911,8 +906,24 @@ function set(factory, argument) {
|
|
|
911
906
|
};
|
|
912
907
|
return {
|
|
913
908
|
set,
|
|
914
|
-
get
|
|
915
|
-
|
|
909
|
+
get
|
|
910
|
+
};
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function set(value, argument) {
|
|
915
|
+
if (!(1 in arguments)) {
|
|
916
|
+
argument = value;
|
|
917
|
+
value = undefined;
|
|
918
|
+
}
|
|
919
|
+
return apply(function set(key) {
|
|
920
|
+
if (value !== undefined)
|
|
921
|
+
this.state[key] = value;
|
|
922
|
+
return {
|
|
923
|
+
suspense: true,
|
|
924
|
+
set: typeof argument == "function"
|
|
925
|
+
? createValueEffect(argument)
|
|
926
|
+
: undefined
|
|
916
927
|
};
|
|
917
928
|
});
|
|
918
929
|
}
|
|
@@ -1404,5 +1415,5 @@ class Global extends MVC {
|
|
|
1404
1415
|
}
|
|
1405
1416
|
}
|
|
1406
1417
|
|
|
1407
|
-
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, WHY, act, apply, array, MVC as default, from, parent, ref, set, tap, use$1 as use, useFrom, useLocal, useModel, useTap };
|
|
1418
|
+
export { CONTROL, Consumer, Global, LOCAL, MVC as Model, Provider, STATE, WHY, act, apply, array, MVC as default, from, parent, put, ref, set, tap, use$1 as use, useFrom, useLocal, useModel, useTap };
|
|
1408
1419
|
//# sourceMappingURL=index.esm.js.map
|