as-model 0.1.7 → 0.1.9
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 +17 -4
- package/esm/key/index.js +3 -0
- package/esm/model/index.js +3 -0
- package/esm/store/index.js +3 -0
- package/esm/store/instance.js +1 -1
- package/esm/updater/notifier.js +7 -3
- package/index.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -233,20 +233,24 @@
|
|
|
233
233
|
var dispatches = updater.dispatches, controlled = updater.controlled;
|
|
234
234
|
var dispatchCallbacks = _to_consumable_array(dispatches);
|
|
235
235
|
var state = action.state;
|
|
236
|
+
var nextInstance = model2(state);
|
|
237
|
+
var nextAction = _object_spread_props(_object_spread({}, action), {
|
|
238
|
+
instance: nextInstance
|
|
239
|
+
});
|
|
236
240
|
if (!controlled) {
|
|
237
241
|
updater.mutate(function(u) {
|
|
238
242
|
return _object_spread_props(_object_spread({}, u), {
|
|
239
243
|
state,
|
|
240
|
-
instance:
|
|
244
|
+
instance: nextInstance,
|
|
241
245
|
version: u.version + 1
|
|
242
246
|
});
|
|
243
247
|
});
|
|
244
248
|
}
|
|
245
249
|
try {
|
|
246
250
|
if (typeof config2.batchNotify === "function") {
|
|
247
|
-
config2.batchNotify(dispatchCallbacks,
|
|
251
|
+
config2.batchNotify(dispatchCallbacks, nextAction);
|
|
248
252
|
} else {
|
|
249
|
-
defaultNotifyImplement(dispatchCallbacks,
|
|
253
|
+
defaultNotifyImplement(dispatchCallbacks, nextAction);
|
|
250
254
|
}
|
|
251
255
|
} catch (e) {
|
|
252
256
|
updater.mutate(function(u) {
|
|
@@ -687,7 +691,7 @@
|
|
|
687
691
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
688
692
|
args[_key] = arguments[_key];
|
|
689
693
|
}
|
|
690
|
-
var instance = updater.instance
|
|
694
|
+
var instance = updater.instance;
|
|
691
695
|
var method2 = instance[methodName];
|
|
692
696
|
if (typeof method2 !== "function") {
|
|
693
697
|
throw new Error("Can not change methods in runtime.");
|
|
@@ -1105,6 +1109,9 @@
|
|
|
1105
1109
|
isDestroyed: function isDestroyed() {
|
|
1106
1110
|
return updater.isDestroyed;
|
|
1107
1111
|
},
|
|
1112
|
+
extends: function _extends(e) {
|
|
1113
|
+
return Object.assign(store, e);
|
|
1114
|
+
},
|
|
1108
1115
|
updater,
|
|
1109
1116
|
modelStoreIdentifier
|
|
1110
1117
|
};
|
|
@@ -1121,6 +1128,9 @@
|
|
|
1121
1128
|
var storeConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
1122
1129
|
return createStore(wrapModel, _object_spread({}, config2, storeConfig));
|
|
1123
1130
|
};
|
|
1131
|
+
wrapModel.extends = function extendsKey(e) {
|
|
1132
|
+
return Object.assign(wrapModel, e);
|
|
1133
|
+
};
|
|
1124
1134
|
return wrapModel;
|
|
1125
1135
|
}
|
|
1126
1136
|
createKey.isModelKey = isModelKey;
|
|
@@ -1216,6 +1226,9 @@
|
|
|
1216
1226
|
selector: currentSelector
|
|
1217
1227
|
}));
|
|
1218
1228
|
};
|
|
1229
|
+
modelWrapper.extends = function extendsModelUsage(e) {
|
|
1230
|
+
return Object.assign(modelWrapper, e);
|
|
1231
|
+
};
|
|
1219
1232
|
modelWrapper.selector = currentSelector;
|
|
1220
1233
|
modelWrapper.modelUsageIdentifier = modelUsageIdentifier;
|
|
1221
1234
|
return modelWrapper;
|
package/esm/key/index.js
CHANGED
|
@@ -9,6 +9,9 @@ function createKey(model) {
|
|
|
9
9
|
var storeConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
10
10
|
return createStore(wrapModel, _object_spread({}, config, storeConfig));
|
|
11
11
|
};
|
|
12
|
+
wrapModel.extends = function extendsKey(e) {
|
|
13
|
+
return Object.assign(wrapModel, e);
|
|
14
|
+
};
|
|
12
15
|
return wrapModel;
|
|
13
16
|
}
|
|
14
17
|
createKey.isModelKey = isModelKey;
|
package/esm/model/index.js
CHANGED
|
@@ -30,6 +30,9 @@ function configModel(config) {
|
|
|
30
30
|
selector: currentSelector
|
|
31
31
|
}));
|
|
32
32
|
};
|
|
33
|
+
modelWrapper.extends = function extendsModelUsage(e) {
|
|
34
|
+
return Object.assign(modelWrapper, e);
|
|
35
|
+
};
|
|
33
36
|
modelWrapper.selector = currentSelector;
|
|
34
37
|
modelWrapper.modelUsageIdentifier = modelUsageIdentifier;
|
|
35
38
|
return modelWrapper;
|
package/esm/store/index.js
CHANGED
package/esm/store/instance.js
CHANGED
|
@@ -66,7 +66,7 @@ function wrapToActionMethod(updater, methodName) {
|
|
|
66
66
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
67
67
|
args[_key] = arguments[_key];
|
|
68
68
|
}
|
|
69
|
-
var instance = updater.instance
|
|
69
|
+
var instance = updater.instance;
|
|
70
70
|
var method2 = instance[methodName];
|
|
71
71
|
if (typeof method2 !== "function") {
|
|
72
72
|
throw new Error("Can not change methods in runtime.");
|
package/esm/updater/notifier.js
CHANGED
|
@@ -80,20 +80,24 @@ function generateNotifier(updater, middleWare) {
|
|
|
80
80
|
var dispatches = updater.dispatches, controlled = updater.controlled;
|
|
81
81
|
var dispatchCallbacks = _to_consumable_array(dispatches);
|
|
82
82
|
var state = action.state;
|
|
83
|
+
var nextInstance = model(state);
|
|
84
|
+
var nextAction = _object_spread_props(_object_spread({}, action), {
|
|
85
|
+
instance: nextInstance
|
|
86
|
+
});
|
|
83
87
|
if (!controlled) {
|
|
84
88
|
updater.mutate(function(u) {
|
|
85
89
|
return _object_spread_props(_object_spread({}, u), {
|
|
86
90
|
state,
|
|
87
|
-
instance:
|
|
91
|
+
instance: nextInstance,
|
|
88
92
|
version: u.version + 1
|
|
89
93
|
});
|
|
90
94
|
});
|
|
91
95
|
}
|
|
92
96
|
try {
|
|
93
97
|
if (typeof config.batchNotify === "function") {
|
|
94
|
-
config.batchNotify(dispatchCallbacks,
|
|
98
|
+
config.batchNotify(dispatchCallbacks, nextAction);
|
|
95
99
|
} else {
|
|
96
|
-
defaultNotifyImplement(dispatchCallbacks,
|
|
100
|
+
defaultNotifyImplement(dispatchCallbacks, nextAction);
|
|
97
101
|
}
|
|
98
102
|
} catch (e) {
|
|
99
103
|
updater.mutate(function(u) {
|
package/index.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ export declare interface Store<
|
|
|
84
84
|
callback?: (payload: P | undefined) => P | undefined
|
|
85
85
|
) => P | undefined;
|
|
86
86
|
isDestroyed: () => boolean;
|
|
87
|
+
extends: <E extends Record<string, any>>(e: E) => Store<S, T, R> & E;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
export declare function createStore<
|
|
@@ -105,6 +106,7 @@ export declare interface ModelKey<
|
|
|
105
106
|
> extends Key<S, T, R> {
|
|
106
107
|
(s: S): T;
|
|
107
108
|
createStore: <D extends S>(state?: D) => Store<S, T, R>;
|
|
109
|
+
extends: <E extends Record<string, any>>(e: E) => ModelKey<S, T, R> & E;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
export declare function createKey<
|
|
@@ -147,6 +149,7 @@ export declare interface ModelUsage<
|
|
|
147
149
|
s: C
|
|
148
150
|
) => ModelUsage<S, T, C>;
|
|
149
151
|
selector: R;
|
|
152
|
+
extends: <E extends Record<string, any>>(e: E) => ModelUsage<S, T, R> & E;
|
|
150
153
|
}
|
|
151
154
|
|
|
152
155
|
declare type FieldStructure<R = any> = {
|