@expressive/mvc 0.7.0 → 0.7.1
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 +14 -2
- package/lib/index.esm.js +14 -8
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +14 -8
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -286,18 +286,30 @@ declare namespace ref {
|
|
|
286
286
|
}
|
|
287
287
|
/** Object with references to all managed values of `T`. */
|
|
288
288
|
type Proxy<T extends Model> = {
|
|
289
|
-
[P in Model.Field<T>]
|
|
289
|
+
[P in Model.Field<T>]-?: Model.Ref<T[P]>;
|
|
290
|
+
};
|
|
291
|
+
type CustomProxy<T extends Model, R> = {
|
|
292
|
+
[P in Model.Field<T>]-?: R;
|
|
290
293
|
};
|
|
291
294
|
}
|
|
292
295
|
/**
|
|
293
296
|
* Creates an object with references to all managed values.
|
|
294
|
-
* Each property
|
|
297
|
+
* Each property is a function to set value in state when invoked.
|
|
295
298
|
*
|
|
296
299
|
* *Properties are simultaneously a ref-function and ref-object, use as needed.*
|
|
297
300
|
*
|
|
298
301
|
* @param target - Source model from which to reference values.
|
|
299
302
|
*/
|
|
300
303
|
declare function ref<T extends Model>(target: T): ref.Proxy<T>;
|
|
304
|
+
/**
|
|
305
|
+
* Creates an object with values based on managed values.
|
|
306
|
+
* Each property will invoke mapper function on first access supply
|
|
307
|
+
* the its return value going forward.
|
|
308
|
+
*
|
|
309
|
+
* @param target - Source model from which to reference values.
|
|
310
|
+
* @param mapper - Function producing the placeholder value for any given property.
|
|
311
|
+
*/
|
|
312
|
+
declare function ref<O extends Model, R>(target: O, mapper: (key: Model.Field<O>) => R): ref.CustomProxy<O, R>;
|
|
301
313
|
/**
|
|
302
314
|
* Creates a ref-compatible property.
|
|
303
315
|
* Will persist value, and updates to this are made part of controller event-stream.
|
package/lib/index.esm.js
CHANGED
|
@@ -798,18 +798,24 @@ function get(arg0, arg1, arg2) {
|
|
|
798
798
|
});
|
|
799
799
|
}
|
|
800
800
|
|
|
801
|
-
function ref(arg) {
|
|
801
|
+
function ref(arg, mapper) {
|
|
802
802
|
return apply(function ref(key) {
|
|
803
803
|
let value = {};
|
|
804
|
-
if (typeof arg
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
804
|
+
if (typeof arg != "object")
|
|
805
|
+
value = createRef(this, key, arg);
|
|
806
|
+
else
|
|
807
|
+
ensure(arg).state.forEach((_val, key) => {
|
|
808
|
+
defineProperty(value, key, mapper ? {
|
|
809
|
+
configurable: true,
|
|
810
|
+
get() {
|
|
811
|
+
const out = mapper(key);
|
|
812
|
+
defineProperty(value, key, { value: out });
|
|
813
|
+
return out;
|
|
814
|
+
}
|
|
815
|
+
} : {
|
|
808
816
|
value: createRef(this, key)
|
|
809
817
|
});
|
|
810
|
-
|
|
811
|
-
else
|
|
812
|
-
value = createRef(this, key, arg);
|
|
818
|
+
});
|
|
813
819
|
return { value, explicit: true };
|
|
814
820
|
});
|
|
815
821
|
}
|