@expressive/mvc 0.21.8 → 0.22.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 +5 -5
- package/lib/index.esm.js +14 -12
- package/lib/index.js +14 -12
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -77,12 +77,12 @@ declare namespace Control {
|
|
|
77
77
|
render: () => T;
|
|
78
78
|
} | void;
|
|
79
79
|
type GetHook = <T>(adapter: GetAdapter<T>) => T | null;
|
|
80
|
-
type UseAdapter<T extends Model> = (refresh: RequestRefresh) => {
|
|
81
|
-
|
|
80
|
+
type UseAdapter<T extends Model, R> = (refresh: RequestRefresh) => {
|
|
81
|
+
local: T;
|
|
82
82
|
mount: () => (() => void) | void;
|
|
83
|
-
render:
|
|
83
|
+
render: R;
|
|
84
84
|
};
|
|
85
|
-
type UseHook = <T extends Model>(adapter: UseAdapter<T
|
|
85
|
+
type UseHook = <T extends Model, R>(adapter: UseAdapter<T, R>) => R;
|
|
86
86
|
}
|
|
87
87
|
declare class Control<T extends Model = any> {
|
|
88
88
|
subject: T;
|
|
@@ -171,7 +171,7 @@ declare function get$1<T extends Model, R>(this: Model.Type<T>, compute: Model.G
|
|
|
171
171
|
declare function get$1<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, Promise<R>>, expect?: boolean): NoVoid<R> | null;
|
|
172
172
|
declare function get$1<T extends Model, R>(this: Model.Type<T>, compute: Model.GetCallback<T, R>, expect?: boolean): NoVoid<R>;
|
|
173
173
|
|
|
174
|
-
declare function use$1<T extends Model>(this: Model.New<T>, callback?: (instance: T) => void): T;
|
|
174
|
+
declare function use$1<T extends Model>(this: Model.New<T>, callback?: (instance: T) => void, repeat?: boolean): T;
|
|
175
175
|
declare function use$1<T extends Model>(this: Model.New<T>, apply?: Model.Compat<T>, repeat?: boolean): T;
|
|
176
176
|
|
|
177
177
|
type InstanceOf<T> = T extends {
|
package/lib/index.esm.js
CHANGED
|
@@ -296,14 +296,12 @@ const notEqual = (a, b) => (b !== a && (!Array.isArray(a) ||
|
|
|
296
296
|
function use$1(arg1, arg2) {
|
|
297
297
|
const render = Control.use(dispatch => {
|
|
298
298
|
const instance = this.new();
|
|
299
|
-
const
|
|
299
|
+
const local = Control.watch(instance, () => onUpdate);
|
|
300
300
|
const refresh = () => dispatch(x => x + 1);
|
|
301
301
|
let onUpdate;
|
|
302
|
-
let
|
|
303
|
-
if (typeof arg1 == "function")
|
|
304
|
-
arg1(instance);
|
|
302
|
+
let apply = !!arg1;
|
|
305
303
|
return {
|
|
306
|
-
|
|
304
|
+
local,
|
|
307
305
|
mount() {
|
|
308
306
|
onUpdate = refresh;
|
|
309
307
|
return () => {
|
|
@@ -312,15 +310,19 @@ function use$1(arg1, arg2) {
|
|
|
312
310
|
};
|
|
313
311
|
},
|
|
314
312
|
render(props) {
|
|
315
|
-
if (
|
|
313
|
+
if (apply) {
|
|
316
314
|
onUpdate = undefined;
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
315
|
+
if (typeof props == "function")
|
|
316
|
+
props(instance);
|
|
317
|
+
else if (props)
|
|
318
|
+
for (const key in instance)
|
|
319
|
+
if (props.hasOwnProperty(key))
|
|
320
|
+
instance[key] = props[key];
|
|
321
|
+
if (!arg2)
|
|
322
|
+
apply = false;
|
|
321
323
|
instance.on(0).then(() => onUpdate = refresh);
|
|
322
324
|
}
|
|
323
|
-
return
|
|
325
|
+
return local;
|
|
324
326
|
}
|
|
325
327
|
};
|
|
326
328
|
});
|
|
@@ -451,7 +453,7 @@ class Control {
|
|
|
451
453
|
}
|
|
452
454
|
watch(key, output) {
|
|
453
455
|
const { state } = this;
|
|
454
|
-
const { get, set, enumerable } = output;
|
|
456
|
+
const { get, set, enumerable = true } = output;
|
|
455
457
|
const subs = new Set();
|
|
456
458
|
this.observers.set(key, subs);
|
|
457
459
|
if ("value" in output)
|
package/lib/index.js
CHANGED
|
@@ -300,14 +300,12 @@ const notEqual = (a, b) => (b !== a && (!Array.isArray(a) ||
|
|
|
300
300
|
function use$1(arg1, arg2) {
|
|
301
301
|
const render = Control.use(dispatch => {
|
|
302
302
|
const instance = this.new();
|
|
303
|
-
const
|
|
303
|
+
const local = Control.watch(instance, () => onUpdate);
|
|
304
304
|
const refresh = () => dispatch(x => x + 1);
|
|
305
305
|
let onUpdate;
|
|
306
|
-
let
|
|
307
|
-
if (typeof arg1 == "function")
|
|
308
|
-
arg1(instance);
|
|
306
|
+
let apply = !!arg1;
|
|
309
307
|
return {
|
|
310
|
-
|
|
308
|
+
local,
|
|
311
309
|
mount() {
|
|
312
310
|
onUpdate = refresh;
|
|
313
311
|
return () => {
|
|
@@ -316,15 +314,19 @@ function use$1(arg1, arg2) {
|
|
|
316
314
|
};
|
|
317
315
|
},
|
|
318
316
|
render(props) {
|
|
319
|
-
if (
|
|
317
|
+
if (apply) {
|
|
320
318
|
onUpdate = undefined;
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
319
|
+
if (typeof props == "function")
|
|
320
|
+
props(instance);
|
|
321
|
+
else if (props)
|
|
322
|
+
for (const key in instance)
|
|
323
|
+
if (props.hasOwnProperty(key))
|
|
324
|
+
instance[key] = props[key];
|
|
325
|
+
if (!arg2)
|
|
326
|
+
apply = false;
|
|
325
327
|
instance.on(0).then(() => onUpdate = refresh);
|
|
326
328
|
}
|
|
327
|
-
return
|
|
329
|
+
return local;
|
|
328
330
|
}
|
|
329
331
|
};
|
|
330
332
|
});
|
|
@@ -455,7 +457,7 @@ class Control {
|
|
|
455
457
|
}
|
|
456
458
|
watch(key, output) {
|
|
457
459
|
const { state } = this;
|
|
458
|
-
const { get, set, enumerable } = output;
|
|
460
|
+
const { get, set, enumerable = true } = output;
|
|
459
461
|
const subs = new Set();
|
|
460
462
|
this.observers.set(key, subs);
|
|
461
463
|
if ("value" in output)
|
package/package.json
CHANGED