as-model 0.1.3 → 0.1.5
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 +28 -7
- package/esm/identifiers/index.js +4 -0
- package/esm/key/index.js +12 -4
- package/esm/store/index.js +3 -2
- package/esm/validation/index.js +14 -4
- package/index.d.ts +27 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -107,6 +107,9 @@
|
|
|
107
107
|
function modelUsageIdentifier() {
|
|
108
108
|
return true;
|
|
109
109
|
}
|
|
110
|
+
function modelStoreIdentifier() {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
110
113
|
|
|
111
114
|
// src/validation/index.ts
|
|
112
115
|
var noStateAModelKey = "no-state-a-model-key";
|
|
@@ -125,9 +128,6 @@
|
|
|
125
128
|
var ins = instance;
|
|
126
129
|
return !!ins[noStateAModelKey];
|
|
127
130
|
}
|
|
128
|
-
var validations = {
|
|
129
|
-
isInstanceFromNoStateModel
|
|
130
|
-
};
|
|
131
131
|
function isModelKey(data) {
|
|
132
132
|
if (!data) {
|
|
133
133
|
return false;
|
|
@@ -140,6 +140,18 @@
|
|
|
140
140
|
}
|
|
141
141
|
return data.modelUsageIdentifier === modelUsageIdentifier && data.modelUsageIdentifier();
|
|
142
142
|
}
|
|
143
|
+
function isModelStore(data) {
|
|
144
|
+
if (!data) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return data.modelStoreIdentifier === modelStoreIdentifier && data.modelStoreIdentifier();
|
|
148
|
+
}
|
|
149
|
+
var validations = {
|
|
150
|
+
isInstanceFromNoStateModel,
|
|
151
|
+
isModelKey,
|
|
152
|
+
isModelStore,
|
|
153
|
+
isModelUsage
|
|
154
|
+
};
|
|
143
155
|
|
|
144
156
|
// src/updater/notifier.ts
|
|
145
157
|
function defaultNotifyImplement(dispatches, action) {
|
|
@@ -1093,7 +1105,8 @@
|
|
|
1093
1105
|
isDestroyed: function isDestroyed() {
|
|
1094
1106
|
return updater.isDestroyed;
|
|
1095
1107
|
},
|
|
1096
|
-
updater
|
|
1108
|
+
updater,
|
|
1109
|
+
modelStoreIdentifier
|
|
1097
1110
|
};
|
|
1098
1111
|
return store;
|
|
1099
1112
|
}
|
|
@@ -1146,18 +1159,26 @@
|
|
|
1146
1159
|
return;
|
|
1147
1160
|
}
|
|
1148
1161
|
storeUnits.forEach(function(un, i) {
|
|
1149
|
-
var
|
|
1150
|
-
if (!
|
|
1162
|
+
var keyLike = keys[i];
|
|
1163
|
+
if (!keyLike) {
|
|
1151
1164
|
return;
|
|
1152
1165
|
}
|
|
1166
|
+
var ifIsModelKey = validations.isModelKey(keyLike);
|
|
1167
|
+
var key = ifIsModelKey ? keyLike : keyLike.key;
|
|
1153
1168
|
Object.assign(un, {
|
|
1154
1169
|
key
|
|
1155
1170
|
});
|
|
1156
1171
|
un.update({
|
|
1157
|
-
model:
|
|
1172
|
+
model: ifIsModelKey ? keyLike.source : keyLike.key.source
|
|
1158
1173
|
});
|
|
1159
1174
|
});
|
|
1160
1175
|
},
|
|
1176
|
+
keys: function keys() {
|
|
1177
|
+
return storeUnits.map(function(param) {
|
|
1178
|
+
var key = param.key;
|
|
1179
|
+
return key;
|
|
1180
|
+
});
|
|
1181
|
+
},
|
|
1161
1182
|
destroy: function destroy2() {
|
|
1162
1183
|
storeUnits.forEach(function(unit) {
|
|
1163
1184
|
unit.destroy();
|
package/esm/identifiers/index.js
CHANGED
package/esm/key/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
2
2
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
3
|
import { createStore, createPrimaryKey } from "../store";
|
|
4
|
-
import { isModelKey } from "../validation";
|
|
4
|
+
import { isModelKey, validations } from "../validation";
|
|
5
5
|
function createKey(model) {
|
|
6
6
|
var config = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
7
7
|
var wrapModel = createPrimaryKey(model, config);
|
|
@@ -47,18 +47,26 @@ function createStores(modelKeys) {
|
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
storeUnits.forEach(function(un, i) {
|
|
50
|
-
var
|
|
51
|
-
if (!
|
|
50
|
+
var keyLike = keys[i];
|
|
51
|
+
if (!keyLike) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
+
var ifIsModelKey = validations.isModelKey(keyLike);
|
|
55
|
+
var key = ifIsModelKey ? keyLike : keyLike.key;
|
|
54
56
|
Object.assign(un, {
|
|
55
57
|
key
|
|
56
58
|
});
|
|
57
59
|
un.update({
|
|
58
|
-
model:
|
|
60
|
+
model: ifIsModelKey ? keyLike.source : keyLike.key.source
|
|
59
61
|
});
|
|
60
62
|
});
|
|
61
63
|
},
|
|
64
|
+
keys: function keys() {
|
|
65
|
+
return storeUnits.map(function(param) {
|
|
66
|
+
var key = param.key;
|
|
67
|
+
return key;
|
|
68
|
+
});
|
|
69
|
+
},
|
|
62
70
|
destroy: function destroy() {
|
|
63
71
|
storeUnits.forEach(function(unit) {
|
|
64
72
|
unit.destroy();
|
package/esm/store/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import { createUpdater } from "../updater";
|
|
5
5
|
import { isModelKey, isModelUsage } from "../validation";
|
|
6
|
-
import { modelKeyIdentifier } from "../identifiers";
|
|
6
|
+
import { modelKeyIdentifier, modelStoreIdentifier } from "../identifiers";
|
|
7
7
|
import { extractInstance, createField as createInstanceField, createMethod as createInstanceMethod } from "./instance";
|
|
8
8
|
function createPrimaryKey(modelFn) {
|
|
9
9
|
var config = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
@@ -82,7 +82,8 @@ function createStore(modelLike) {
|
|
|
82
82
|
isDestroyed: function isDestroyed() {
|
|
83
83
|
return updater.isDestroyed;
|
|
84
84
|
},
|
|
85
|
-
updater
|
|
85
|
+
updater,
|
|
86
|
+
modelStoreIdentifier
|
|
86
87
|
};
|
|
87
88
|
return store;
|
|
88
89
|
}
|
package/esm/validation/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
2
|
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
3
|
-
import { modelKeyIdentifier, modelUsageIdentifier } from "../identifiers";
|
|
3
|
+
import { modelKeyIdentifier, modelStoreIdentifier, modelUsageIdentifier } from "../identifiers";
|
|
4
4
|
var noStateAModelKey = "no-state-a-model-key";
|
|
5
5
|
function createNoStateModel() {
|
|
6
6
|
return function noStateModel(state) {
|
|
@@ -17,9 +17,6 @@ function isInstanceFromNoStateModel(instance) {
|
|
|
17
17
|
var ins = instance;
|
|
18
18
|
return !!ins[noStateAModelKey];
|
|
19
19
|
}
|
|
20
|
-
var validations = {
|
|
21
|
-
isInstanceFromNoStateModel
|
|
22
|
-
};
|
|
23
20
|
function isModelKey(data) {
|
|
24
21
|
if (!data) {
|
|
25
22
|
return false;
|
|
@@ -32,9 +29,22 @@ function isModelUsage(data) {
|
|
|
32
29
|
}
|
|
33
30
|
return data.modelUsageIdentifier === modelUsageIdentifier && data.modelUsageIdentifier();
|
|
34
31
|
}
|
|
32
|
+
function isModelStore(data) {
|
|
33
|
+
if (!data) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return data.modelStoreIdentifier === modelStoreIdentifier && data.modelStoreIdentifier();
|
|
37
|
+
}
|
|
38
|
+
var validations = {
|
|
39
|
+
isInstanceFromNoStateModel,
|
|
40
|
+
isModelKey,
|
|
41
|
+
isModelStore,
|
|
42
|
+
isModelUsage
|
|
43
|
+
};
|
|
35
44
|
export {
|
|
36
45
|
createNoStateModel,
|
|
37
46
|
isModelKey,
|
|
47
|
+
isModelStore,
|
|
38
48
|
isModelUsage,
|
|
39
49
|
validations
|
|
40
50
|
};
|
package/index.d.ts
CHANGED
|
@@ -138,6 +138,7 @@ export declare interface StoreCollection {
|
|
|
138
138
|
key: Key<S, T, R> | StoreIndex<S, T, R>
|
|
139
139
|
) => Store<S, T, R> | null;
|
|
140
140
|
update: (...keys: (ModelKey | StoreIndex)[]) => void;
|
|
141
|
+
keys: () => Key[];
|
|
141
142
|
destroy: () => void;
|
|
142
143
|
}
|
|
143
144
|
|
|
@@ -260,3 +261,29 @@ export declare function config(configuration: Config): {
|
|
|
260
261
|
createStores: typeof createStores;
|
|
261
262
|
model: model;
|
|
262
263
|
};
|
|
264
|
+
|
|
265
|
+
/** validations * */
|
|
266
|
+
export declare const validations: {
|
|
267
|
+
isInstanceFromNoStateModel: (instance: unknown) => boolean;
|
|
268
|
+
isModelKey: <
|
|
269
|
+
S,
|
|
270
|
+
T extends ModelInstance,
|
|
271
|
+
R extends (ins: () => T) => any = (ins: () => T) => T
|
|
272
|
+
>(
|
|
273
|
+
data: unknown
|
|
274
|
+
) => data is ModelKey<S, T, R>;
|
|
275
|
+
isModelStore: <
|
|
276
|
+
S,
|
|
277
|
+
T extends ModelInstance,
|
|
278
|
+
R extends (ins: () => T) => any = (ins: () => T) => T
|
|
279
|
+
>(
|
|
280
|
+
data: unknown
|
|
281
|
+
) => data is Store<S, T, R>;
|
|
282
|
+
isModelUsage: <
|
|
283
|
+
S,
|
|
284
|
+
T extends ModelInstance,
|
|
285
|
+
R extends (ins: () => T) => any = (ins: () => T) => T
|
|
286
|
+
>(
|
|
287
|
+
data: unknown
|
|
288
|
+
) => data is ModelUsage<S, T, R>;
|
|
289
|
+
};
|