@expressive/mvc 0.21.7 → 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 +27 -17
- package/lib/index.js +27 -17
- 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)
|
|
@@ -866,18 +868,26 @@ function set(value, argument) {
|
|
|
866
868
|
return getter();
|
|
867
869
|
};
|
|
868
870
|
}
|
|
871
|
+
let setter = typeof argument == "function"
|
|
872
|
+
? createValueEffect(argument)
|
|
873
|
+
: undefined;
|
|
869
874
|
if (value !== undefined)
|
|
870
875
|
state[key] = value;
|
|
876
|
+
else if (setter) {
|
|
877
|
+
const effect = setter;
|
|
878
|
+
setter = function (value) {
|
|
879
|
+
if (!(key in state))
|
|
880
|
+
state[key] = undefined;
|
|
881
|
+
return effect.call(this, value);
|
|
882
|
+
};
|
|
883
|
+
}
|
|
871
884
|
return {
|
|
872
885
|
get: () => {
|
|
873
886
|
if (key in state)
|
|
874
887
|
return state[key];
|
|
875
|
-
|
|
876
|
-
throw suspense(control, key);
|
|
888
|
+
throw suspense(control, key);
|
|
877
889
|
},
|
|
878
|
-
set:
|
|
879
|
-
? createValueEffect(argument)
|
|
880
|
-
: undefined
|
|
890
|
+
set: setter
|
|
881
891
|
};
|
|
882
892
|
});
|
|
883
893
|
}
|
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)
|
|
@@ -870,18 +872,26 @@ function set(value, argument) {
|
|
|
870
872
|
return getter();
|
|
871
873
|
};
|
|
872
874
|
}
|
|
875
|
+
let setter = typeof argument == "function"
|
|
876
|
+
? createValueEffect(argument)
|
|
877
|
+
: undefined;
|
|
873
878
|
if (value !== undefined)
|
|
874
879
|
state[key] = value;
|
|
880
|
+
else if (setter) {
|
|
881
|
+
const effect = setter;
|
|
882
|
+
setter = function (value) {
|
|
883
|
+
if (!(key in state))
|
|
884
|
+
state[key] = undefined;
|
|
885
|
+
return effect.call(this, value);
|
|
886
|
+
};
|
|
887
|
+
}
|
|
875
888
|
return {
|
|
876
889
|
get: () => {
|
|
877
890
|
if (key in state)
|
|
878
891
|
return state[key];
|
|
879
|
-
|
|
880
|
-
throw suspense(control, key);
|
|
892
|
+
throw suspense(control, key);
|
|
881
893
|
},
|
|
882
|
-
set:
|
|
883
|
-
? createValueEffect(argument)
|
|
884
|
-
: undefined
|
|
894
|
+
set: setter
|
|
885
895
|
};
|
|
886
896
|
});
|
|
887
897
|
}
|
package/package.json
CHANGED