as-model 0.1.20 → 0.1.21
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/dist/index.js +9 -5
- package/esm/store/index.js +2 -2
- package/esm/updater/index.js +10 -3
- package/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -604,7 +604,10 @@
|
|
|
604
604
|
updater.mutate(function(u, effect) {
|
|
605
605
|
var _args_model;
|
|
606
606
|
var model2 = (_args_model = args.model) !== null && _args_model !== void 0 ? _args_model : u.model;
|
|
607
|
-
var
|
|
607
|
+
var hasState = Object.prototype.hasOwnProperty.call(args, "state");
|
|
608
|
+
var hasInitialState = Object.prototype.hasOwnProperty.call(args, "initialState");
|
|
609
|
+
var state = hasState ? args.state : u.state;
|
|
610
|
+
var isInitialize = !u.initialized || hasInitialState;
|
|
608
611
|
var token = createToken();
|
|
609
612
|
if (u.controlled) {
|
|
610
613
|
var instance = model2(state);
|
|
@@ -620,8 +623,9 @@
|
|
|
620
623
|
if (!u.initialized && !("state" in args)) {
|
|
621
624
|
throw new Error("The updater has not been initialized, it should be updated with a state for initializing.");
|
|
622
625
|
}
|
|
623
|
-
if (
|
|
624
|
-
var
|
|
626
|
+
if (isInitialize) {
|
|
627
|
+
var initialState = hasInitialState ? args.initialState : state;
|
|
628
|
+
var instance1 = model2(initialState);
|
|
625
629
|
var initializedUpdater = createInitializedUpdater(u, middleWare);
|
|
626
630
|
return _object_spread(_object_spread_props(_object_spread({}, u), {
|
|
627
631
|
model: model2,
|
|
@@ -1194,7 +1198,7 @@
|
|
|
1194
1198
|
getInstance,
|
|
1195
1199
|
update: function update(args) {
|
|
1196
1200
|
var updateArgs = args !== null && args !== void 0 ? args : {};
|
|
1197
|
-
if (
|
|
1201
|
+
if (updateArgs.key) {
|
|
1198
1202
|
var updatingKey = updateArgs.key, updatingModel = updateArgs.model, rest = _object_without_properties(updateArgs, [
|
|
1199
1203
|
"key",
|
|
1200
1204
|
"model"
|
|
@@ -1205,7 +1209,7 @@
|
|
|
1205
1209
|
store.key = updatingKey;
|
|
1206
1210
|
return;
|
|
1207
1211
|
}
|
|
1208
|
-
if (
|
|
1212
|
+
if (updateArgs.model) {
|
|
1209
1213
|
var updatingKey1 = updateArgs.key, updatingModel1 = updateArgs.model, rest1 = _object_without_properties(updateArgs, [
|
|
1210
1214
|
"key",
|
|
1211
1215
|
"model"
|
package/esm/store/index.js
CHANGED
|
@@ -103,13 +103,13 @@ function createStore(modelLike, config = {}) {
|
|
|
103
103
|
getInstance,
|
|
104
104
|
update(args) {
|
|
105
105
|
const updateArgs = args != null ? args : {};
|
|
106
|
-
if (
|
|
106
|
+
if (updateArgs.key) {
|
|
107
107
|
const _a = updateArgs, { key: updatingKey, model: updatingModel } = _a, rest = __objRest(_a, ["key", "model"]);
|
|
108
108
|
updater.update(__spreadProps(__spreadValues({}, rest), { model: updatingKey.source }));
|
|
109
109
|
store.key = updatingKey;
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
if (
|
|
112
|
+
if (updateArgs.model) {
|
|
113
113
|
const _b = updateArgs, { key: updatingKey, model: updatingModel } = _b, rest = __objRest(_b, ["key", "model"]);
|
|
114
114
|
updater.update(__spreadProps(__spreadValues({}, rest), { model: updatingModel }));
|
|
115
115
|
store.key = createPrimaryKey(updatingModel, config);
|
package/esm/updater/index.js
CHANGED
|
@@ -37,7 +37,13 @@ function createUpdateFn(updater, middleWare) {
|
|
|
37
37
|
updater.mutate((u, effect) => {
|
|
38
38
|
var _a;
|
|
39
39
|
const model = (_a = args.model) != null ? _a : u.model;
|
|
40
|
-
const
|
|
40
|
+
const hasState = Object.prototype.hasOwnProperty.call(args, "state");
|
|
41
|
+
const hasInitialState = Object.prototype.hasOwnProperty.call(
|
|
42
|
+
args,
|
|
43
|
+
"initialState"
|
|
44
|
+
);
|
|
45
|
+
const state = hasState ? args.state : u.state;
|
|
46
|
+
const isInitialize = !u.initialized || hasInitialState;
|
|
41
47
|
const token = createToken();
|
|
42
48
|
if (u.controlled) {
|
|
43
49
|
const instance = model(state);
|
|
@@ -51,8 +57,9 @@ function createUpdateFn(updater, middleWare) {
|
|
|
51
57
|
"The updater has not been initialized, it should be updated with a state for initializing."
|
|
52
58
|
);
|
|
53
59
|
}
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
60
|
+
if (isInitialize) {
|
|
61
|
+
const initialState = hasInitialState ? args.initialState : state;
|
|
62
|
+
const instance = model(initialState);
|
|
56
63
|
const initializedUpdater = createInitializedUpdater(u, middleWare);
|
|
57
64
|
return __spreadValues(__spreadProps(__spreadValues({}, u), {
|
|
58
65
|
model,
|
package/index.d.ts
CHANGED