@akanjs/store 0.0.97 → 0.0.99
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/index.cjs +17 -0
- package/index.js +1 -17
- package/package.json +4 -4
- package/src/index.cjs +18 -0
- package/src/index.js +2 -18
- package/src/{storeDecorators.mjs → storeDecorators.cjs} +106 -103
- package/src/storeDecorators.js +103 -106
- package/src/types.cjs +15 -0
- package/src/types.js +0 -15
- package/index.mjs +0 -1
- package/src/index.mjs +0 -2
- package/src/types.mjs +0 -0
package/index.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var store_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(store_exports);
|
|
17
|
+
__reExport(store_exports, require("./src"), module.exports);
|
package/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var store_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(store_exports);
|
|
17
|
-
__reExport(store_exports, require("./src"), module.exports);
|
|
1
|
+
export * from "./src";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/store",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"type": "
|
|
3
|
+
"version": "0.0.99",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
|
23
|
-
"require": "./index.
|
|
24
|
-
"import": "./index.
|
|
23
|
+
"require": "./index.cjs",
|
|
24
|
+
"import": "./index.js"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"esbuild": {
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./types"), module.exports);
|
|
18
|
+
__reExport(src_exports, require("./storeDecorators"), module.exports);
|
package/src/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var src_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(src_exports);
|
|
17
|
-
__reExport(src_exports, require("./types"), module.exports);
|
|
18
|
-
__reExport(src_exports, require("./storeDecorators"), module.exports);
|
|
1
|
+
export * from "./types";
|
|
2
|
+
export * from "./storeDecorators";
|
|
@@ -1,29 +1,44 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var storeDecorators_exports = {};
|
|
20
|
+
__export(storeDecorators_exports, {
|
|
21
|
+
MixStore: () => MixStore,
|
|
22
|
+
Store: () => Store,
|
|
23
|
+
Toast: () => Toast,
|
|
24
|
+
createActions: () => createActions,
|
|
25
|
+
createState: () => createState,
|
|
26
|
+
makeStore: () => makeStore,
|
|
27
|
+
rootStoreOf: () => rootStoreOf,
|
|
28
|
+
scalarStateOf: () => scalarStateOf,
|
|
29
|
+
st: () => st,
|
|
30
|
+
stateOf: () => stateOf
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(storeDecorators_exports);
|
|
33
|
+
var import_base = require("@akanjs/base");
|
|
34
|
+
var import_common = require("@akanjs/common");
|
|
35
|
+
var import_constant = require("@akanjs/constant");
|
|
36
|
+
var import_dictionary = require("@akanjs/dictionary");
|
|
37
|
+
var import_signal = require("@akanjs/signal");
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var import_zustand = require("zustand");
|
|
40
|
+
var import_middleware = require("zustand/middleware");
|
|
41
|
+
var import_immer = require("zustand/middleware/immer");
|
|
27
42
|
const st = {};
|
|
28
43
|
class StoreStorage {
|
|
29
44
|
}
|
|
@@ -43,7 +58,7 @@ const getStoreNames = () => {
|
|
|
43
58
|
return storeNames;
|
|
44
59
|
};
|
|
45
60
|
const createState = (gql) => {
|
|
46
|
-
const [fieldName, className] = [lowerlize(gql.refName), capitalize(gql.refName)];
|
|
61
|
+
const [fieldName, className] = [(0, import_common.lowerlize)(gql.refName), (0, import_common.capitalize)(gql.refName)];
|
|
47
62
|
const names = {
|
|
48
63
|
model: fieldName,
|
|
49
64
|
Model: className,
|
|
@@ -79,7 +94,7 @@ const createState = (gql) => {
|
|
|
79
94
|
[names.modelOperation]: "sleep"
|
|
80
95
|
};
|
|
81
96
|
const sliceState = gql.slices.reduce((acc, { sliceName, defaultArgs }) => {
|
|
82
|
-
const SliceName = capitalize(sliceName);
|
|
97
|
+
const SliceName = (0, import_common.capitalize)(sliceName);
|
|
83
98
|
const namesOfSlice = {
|
|
84
99
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
85
100
|
//clusterInSelf Cluster
|
|
@@ -97,11 +112,11 @@ const createState = (gql) => {
|
|
|
97
112
|
};
|
|
98
113
|
const singleSliceState = {
|
|
99
114
|
[namesOfSlice.defaultModel]: { ...gql[names.defaultModel] },
|
|
100
|
-
[namesOfSlice.modelList]: new DataList(),
|
|
115
|
+
[namesOfSlice.modelList]: new import_base.DataList(),
|
|
101
116
|
[namesOfSlice.modelListLoading]: true,
|
|
102
|
-
[namesOfSlice.modelInitList]: new DataList(),
|
|
117
|
+
[namesOfSlice.modelInitList]: new import_base.DataList(),
|
|
103
118
|
[namesOfSlice.modelInitAt]: /* @__PURE__ */ new Date(0),
|
|
104
|
-
[namesOfSlice.modelSelection]: new DataList(),
|
|
119
|
+
[namesOfSlice.modelSelection]: new import_base.DataList(),
|
|
105
120
|
[namesOfSlice.modelInsight]: gql[names.defaultModelInsight],
|
|
106
121
|
[namesOfSlice.lastPageOfModel]: 1,
|
|
107
122
|
[namesOfSlice.pageOfModel]: 1,
|
|
@@ -119,10 +134,10 @@ const createActions = (gql) => {
|
|
|
119
134
|
return { ...formSetterActions, ...baseActions };
|
|
120
135
|
};
|
|
121
136
|
const makeFormSetter = (gql) => {
|
|
122
|
-
const fileGql = getGqlOnStorage("file");
|
|
123
|
-
const [fieldName, className] = [lowerlize(gql.refName), capitalize(gql.refName)];
|
|
124
|
-
const modelRef = getFullModelRef(gql.refName);
|
|
125
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
137
|
+
const fileGql = (0, import_signal.getGqlOnStorage)("file");
|
|
138
|
+
const [fieldName, className] = [(0, import_common.lowerlize)(gql.refName), (0, import_common.capitalize)(gql.refName)];
|
|
139
|
+
const modelRef = (0, import_constant.getFullModelRef)(gql.refName);
|
|
140
|
+
const fieldMetas = (0, import_constant.getFieldMetas)(modelRef);
|
|
126
141
|
const names = {
|
|
127
142
|
model: fieldName,
|
|
128
143
|
Model: className,
|
|
@@ -133,12 +148,12 @@ const makeFormSetter = (gql) => {
|
|
|
133
148
|
const baseSetAction = {
|
|
134
149
|
[names.writeOnModel]: function(path, value) {
|
|
135
150
|
this.set((state) => {
|
|
136
|
-
pathSet(state[names.modelForm], path, value);
|
|
151
|
+
(0, import_common.pathSet)(state[names.modelForm], path, value);
|
|
137
152
|
});
|
|
138
153
|
}
|
|
139
154
|
};
|
|
140
155
|
const fieldSetAction = fieldMetas.reduce((acc, fieldMeta) => {
|
|
141
|
-
const [fieldKeyName, classKeyName] = [lowerlize(fieldMeta.key), capitalize(fieldMeta.key)];
|
|
156
|
+
const [fieldKeyName, classKeyName] = [(0, import_common.lowerlize)(fieldMeta.key), (0, import_common.capitalize)(fieldMeta.key)];
|
|
142
157
|
const namesOfField = {
|
|
143
158
|
field: fieldKeyName,
|
|
144
159
|
Field: classKeyName,
|
|
@@ -151,7 +166,7 @@ const makeFormSetter = (gql) => {
|
|
|
151
166
|
const singleFieldSetAction = {
|
|
152
167
|
[namesOfField.setFieldOnModel]: function(value) {
|
|
153
168
|
this.set((state) => {
|
|
154
|
-
const setValue = fieldMeta.isClass ? immerify(fieldMeta.modelRef, value) : value;
|
|
169
|
+
const setValue = fieldMeta.isClass ? (0, import_signal.immerify)(fieldMeta.modelRef, value) : value;
|
|
155
170
|
state[names.modelForm][namesOfField.field] = setValue;
|
|
156
171
|
});
|
|
157
172
|
},
|
|
@@ -162,7 +177,7 @@ const makeFormSetter = (gql) => {
|
|
|
162
177
|
if (options.limit && options.limit <= length)
|
|
163
178
|
return;
|
|
164
179
|
const idx = options.idx ?? length;
|
|
165
|
-
const setValue = fieldMeta.isClass ? immerify(fieldMeta.modelRef, value) : value;
|
|
180
|
+
const setValue = fieldMeta.isClass ? (0, import_signal.immerify)(fieldMeta.modelRef, value) : value;
|
|
166
181
|
this.set((state) => {
|
|
167
182
|
state[names.modelForm][namesOfField.field] = [
|
|
168
183
|
...form[namesOfField.field].slice(0, idx),
|
|
@@ -236,9 +251,9 @@ const makeFormSetter = (gql) => {
|
|
|
236
251
|
return Object.assign(fieldSetAction, baseSetAction);
|
|
237
252
|
};
|
|
238
253
|
const makeActions = (gql) => {
|
|
239
|
-
const [fieldName, className] = [lowerlize(gql.refName), capitalize(gql.refName)];
|
|
240
|
-
const modelRef = getFullModelRef(className);
|
|
241
|
-
const lightModelRef = getLightModelRef(modelRef);
|
|
254
|
+
const [fieldName, className] = [(0, import_common.lowerlize)(gql.refName), (0, import_common.capitalize)(gql.refName)];
|
|
255
|
+
const modelRef = (0, import_constant.getFullModelRef)(className);
|
|
256
|
+
const lightModelRef = (0, import_constant.getLightModelRef)(modelRef);
|
|
242
257
|
const names = {
|
|
243
258
|
model: fieldName,
|
|
244
259
|
_model: `_${fieldName}`,
|
|
@@ -290,7 +305,7 @@ const makeActions = (gql) => {
|
|
|
290
305
|
};
|
|
291
306
|
const baseAction = {
|
|
292
307
|
[names.createModelInForm]: async function({ idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
|
|
293
|
-
const SliceName = capitalize(sliceName);
|
|
308
|
+
const SliceName = (0, import_common.capitalize)(sliceName);
|
|
294
309
|
const namesOfSlice = {
|
|
295
310
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
296
311
|
modelList: sliceName.replace(names.model, names.modelList),
|
|
@@ -308,13 +323,13 @@ const makeActions = (gql) => {
|
|
|
308
323
|
return;
|
|
309
324
|
this.set({ [names.modelLoading]: true });
|
|
310
325
|
const model = await gql[names.createModel](modelInput, { onError });
|
|
311
|
-
const newModelList = modelListLoading ? modelList : new DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
|
|
326
|
+
const newModelList = modelListLoading ? modelList : new import_base.DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
|
|
312
327
|
const newModelInsight = gql[names.crystalizeInsight]({
|
|
313
328
|
...modelInsight,
|
|
314
329
|
count: modelInsight.count + 1
|
|
315
330
|
});
|
|
316
331
|
this.set({
|
|
317
|
-
[names.modelForm]: immerify(modelRef, defaultModel),
|
|
332
|
+
[names.modelForm]: (0, import_signal.immerify)(modelRef, defaultModel),
|
|
318
333
|
[names.model]: model,
|
|
319
334
|
[names.modelLoading]: false,
|
|
320
335
|
[namesOfSlice.modelList]: newModelList,
|
|
@@ -326,7 +341,7 @@ const makeActions = (gql) => {
|
|
|
326
341
|
await onSuccess?.(model);
|
|
327
342
|
},
|
|
328
343
|
[names.updateModelInForm]: async function({ path, modal, sliceName = names.model, onError, onSuccess } = {}) {
|
|
329
|
-
const SliceName = capitalize(sliceName);
|
|
344
|
+
const SliceName = (0, import_common.capitalize)(sliceName);
|
|
330
345
|
const namesOfSlice = {
|
|
331
346
|
defaultModel: SliceName.replace(names.Model, names.defaultModel)
|
|
332
347
|
};
|
|
@@ -344,7 +359,7 @@ const makeActions = (gql) => {
|
|
|
344
359
|
});
|
|
345
360
|
this.set({
|
|
346
361
|
...model?.id === updatedModel.id ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: /* @__PURE__ */ new Date() } : {},
|
|
347
|
-
[names.modelForm]: immerify(modelRef, defaultModel),
|
|
362
|
+
[names.modelForm]: (0, import_signal.immerify)(modelRef, defaultModel),
|
|
348
363
|
[names.modelModal]: modal ?? null,
|
|
349
364
|
...typeof path === "string" && path ? { [path]: updatedModel } : {}
|
|
350
365
|
});
|
|
@@ -359,13 +374,13 @@ const makeActions = (gql) => {
|
|
|
359
374
|
const modelListLoading = currentState2[namesOfSlice2.modelListLoading];
|
|
360
375
|
if (modelListLoading || !modelList.has(updatedModel.id))
|
|
361
376
|
return;
|
|
362
|
-
const newModelList = new DataList(modelList).set(updatedLightModel);
|
|
377
|
+
const newModelList = new import_base.DataList(modelList).set(updatedLightModel);
|
|
363
378
|
this.set({ [namesOfSlice2.modelList]: newModelList });
|
|
364
379
|
});
|
|
365
380
|
await onSuccess?.(updatedModel);
|
|
366
381
|
},
|
|
367
382
|
[names.createModel]: async function(data, { idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
|
|
368
|
-
const SliceName = capitalize(sliceName);
|
|
383
|
+
const SliceName = (0, import_common.capitalize)(sliceName);
|
|
369
384
|
const namesOfSlice = {
|
|
370
385
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
371
386
|
modelList: sliceName.replace(names.model, names.modelList),
|
|
@@ -381,7 +396,7 @@ const makeActions = (gql) => {
|
|
|
381
396
|
return;
|
|
382
397
|
this.set({ [names.modelLoading]: true });
|
|
383
398
|
const model = await gql[names.createModel](modelInput, { onError });
|
|
384
|
-
const newModelList = modelListLoading ? modelList : new DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
|
|
399
|
+
const newModelList = modelListLoading ? modelList : new import_base.DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
|
|
385
400
|
const newModelInsight = gql[names.crystalizeInsight]({
|
|
386
401
|
...modelInsight,
|
|
387
402
|
count: modelInsight.count + 1
|
|
@@ -422,7 +437,7 @@ const makeActions = (gql) => {
|
|
|
422
437
|
const modelListLoading = currentState2[namesOfSlice.modelListLoading];
|
|
423
438
|
if (modelListLoading || !modelList.has(updatedModel.id))
|
|
424
439
|
return;
|
|
425
|
-
const newModelList = new DataList(modelList).set(updatedLightModel);
|
|
440
|
+
const newModelList = new import_base.DataList(modelList).set(updatedLightModel);
|
|
426
441
|
this.set({ [namesOfSlice.modelList]: newModelList });
|
|
427
442
|
});
|
|
428
443
|
await onSuccess?.(updatedModel);
|
|
@@ -448,14 +463,14 @@ const makeActions = (gql) => {
|
|
|
448
463
|
const modelInsight = currentState[namesOfSlice.modelInsight];
|
|
449
464
|
if (modelListLoading || !modelList.has(model.id))
|
|
450
465
|
return;
|
|
451
|
-
const newModelList = new DataList(modelList);
|
|
466
|
+
const newModelList = new import_base.DataList(modelList);
|
|
452
467
|
if (model.removedAt) {
|
|
453
468
|
newModelList.delete(id);
|
|
454
469
|
const newModelInsight = gql[names.crystalizeInsight]({
|
|
455
470
|
...modelInsight,
|
|
456
471
|
count: modelInsight.count - 1
|
|
457
472
|
});
|
|
458
|
-
const newModelSelection = new DataList(modelSelection);
|
|
473
|
+
const newModelSelection = new import_base.DataList(modelSelection);
|
|
459
474
|
newModelSelection.delete(id);
|
|
460
475
|
this.set({
|
|
461
476
|
[namesOfSlice.modelList]: newModelList,
|
|
@@ -491,15 +506,15 @@ const makeActions = (gql) => {
|
|
|
491
506
|
this.set({ [names.modelSubmit]: { ...modelSubmit, loading: false, times: modelSubmit.times + 1 } });
|
|
492
507
|
},
|
|
493
508
|
[names.newModel]: function(partial = {}, { modal, setDefault, sliceName = names.model } = {}) {
|
|
494
|
-
const SliceName = capitalize(sliceName);
|
|
509
|
+
const SliceName = (0, import_common.capitalize)(sliceName);
|
|
495
510
|
const namesOfSlice = {
|
|
496
511
|
defaultModel: SliceName.replace(names.Model, names.defaultModel)
|
|
497
512
|
};
|
|
498
513
|
const currentState = this.get();
|
|
499
514
|
const defaultModel = currentState[namesOfSlice.defaultModel];
|
|
500
515
|
this.set({
|
|
501
|
-
[names.modelForm]: immerify(modelRef, { ...defaultModel, ...partial }),
|
|
502
|
-
[namesOfSlice.defaultModel]: setDefault ? immerify(modelRef, { ...defaultModel, ...partial }) : defaultModel,
|
|
516
|
+
[names.modelForm]: (0, import_signal.immerify)(modelRef, { ...defaultModel, ...partial }),
|
|
517
|
+
[namesOfSlice.defaultModel]: setDefault ? (0, import_signal.immerify)(modelRef, { ...defaultModel, ...partial }) : defaultModel,
|
|
503
518
|
[names.model]: null,
|
|
504
519
|
[names.modelModal]: modal ?? "edit",
|
|
505
520
|
[names.modelFormLoading]: false
|
|
@@ -512,7 +527,7 @@ const makeActions = (gql) => {
|
|
|
512
527
|
state[names.modelForm].id = id;
|
|
513
528
|
});
|
|
514
529
|
const model = await gql[names.model](id, { onError });
|
|
515
|
-
const modelForm = deepObjectify(model);
|
|
530
|
+
const modelForm = (0, import_common.deepObjectify)(model);
|
|
516
531
|
this.set({
|
|
517
532
|
[names.model]: model,
|
|
518
533
|
[names.modelFormLoading]: false,
|
|
@@ -542,7 +557,7 @@ const makeActions = (gql) => {
|
|
|
542
557
|
const modelListLoading = currentState2[namesOfSlice.modelListLoading];
|
|
543
558
|
if (modelListLoading || !modelList.has(updatedModel.id))
|
|
544
559
|
return;
|
|
545
|
-
const newModelList = new DataList(modelList).set(updatedLightModel);
|
|
560
|
+
const newModelList = new import_base.DataList(modelList).set(updatedLightModel);
|
|
546
561
|
this.set({ [namesOfSlice.modelList]: newModelList });
|
|
547
562
|
});
|
|
548
563
|
},
|
|
@@ -582,14 +597,14 @@ const makeActions = (gql) => {
|
|
|
582
597
|
this.set({
|
|
583
598
|
[names.model]: model ?? null,
|
|
584
599
|
[names.modelViewAt]: /* @__PURE__ */ new Date(0),
|
|
585
|
-
[names.modelForm]: immerify(modelRef, defaultModel),
|
|
600
|
+
[names.modelForm]: (0, import_signal.immerify)(modelRef, defaultModel),
|
|
586
601
|
[names.modelModal]: null
|
|
587
602
|
});
|
|
588
603
|
return model ?? null;
|
|
589
604
|
}
|
|
590
605
|
};
|
|
591
606
|
const sliceAction = gql.slices.reduce((acc, { sliceName, argLength }) => {
|
|
592
|
-
const SliceName = capitalize(sliceName);
|
|
607
|
+
const SliceName = (0, import_common.capitalize)(sliceName);
|
|
593
608
|
const namesOfSlice = {
|
|
594
609
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
595
610
|
modelInsight: sliceName.replace(names.model, names.modelInsight),
|
|
@@ -617,7 +632,7 @@ const makeActions = (gql) => {
|
|
|
617
632
|
const initArgLength = Math.min(args.length, argLength);
|
|
618
633
|
const initForm = { invalidate: false, ...args[argLength] ?? {} };
|
|
619
634
|
const queryArgs = new Array(initArgLength).fill(null).map((_, i) => args[i]);
|
|
620
|
-
const defaultModel = immerify(modelRef, { ...gql[names.defaultModel], ...initForm.default ?? {} });
|
|
635
|
+
const defaultModel = (0, import_signal.immerify)(modelRef, { ...gql[names.defaultModel], ...initForm.default ?? {} });
|
|
621
636
|
this.set({ [names.defaultModel]: defaultModel });
|
|
622
637
|
await this[namesOfSlice.refreshModel](
|
|
623
638
|
...initArgLength === argLength ? [...queryArgs, initForm] : queryArgs
|
|
@@ -643,7 +658,7 @@ const makeActions = (gql) => {
|
|
|
643
658
|
const pageOfModel = currentState[namesOfSlice.pageOfModel];
|
|
644
659
|
const limitOfModel = currentState[namesOfSlice.limitOfModel];
|
|
645
660
|
const sortOfModel = currentState[namesOfSlice.sortOfModel];
|
|
646
|
-
if (!invalidate && !["sleep", "reset"].includes(modelOperation) && isQueryEqual(queryArgs, queryArgsOfModel) && page === pageOfModel && limit === limitOfModel && isQueryEqual(sort, sortOfModel))
|
|
661
|
+
if (!invalidate && !["sleep", "reset"].includes(modelOperation) && (0, import_common.isQueryEqual)(queryArgs, queryArgsOfModel) && page === pageOfModel && limit === limitOfModel && (0, import_common.isQueryEqual)(sort, sortOfModel))
|
|
647
662
|
return;
|
|
648
663
|
else
|
|
649
664
|
this.set({ [namesOfSlice.modelListLoading]: true });
|
|
@@ -659,7 +674,7 @@ const makeActions = (gql) => {
|
|
|
659
674
|
onError: initForm.onError
|
|
660
675
|
})
|
|
661
676
|
]);
|
|
662
|
-
const modelList = new DataList(modelDataList);
|
|
677
|
+
const modelList = new import_base.DataList(modelDataList);
|
|
663
678
|
this.set({
|
|
664
679
|
[namesOfSlice.modelList]: modelList,
|
|
665
680
|
[namesOfSlice.modelListLoading]: false,
|
|
@@ -679,13 +694,13 @@ const makeActions = (gql) => {
|
|
|
679
694
|
const currentState = this.get();
|
|
680
695
|
const modelSelection = currentState[namesOfSlice.modelSelection];
|
|
681
696
|
if (refresh)
|
|
682
|
-
this.set({ [namesOfSlice.modelSelection]: new DataList(models) });
|
|
697
|
+
this.set({ [namesOfSlice.modelSelection]: new import_base.DataList(models) });
|
|
683
698
|
else if (remove) {
|
|
684
|
-
const newModelSelection = new DataList(modelSelection);
|
|
699
|
+
const newModelSelection = new import_base.DataList(modelSelection);
|
|
685
700
|
models.map((model2) => newModelSelection.delete(model2.id));
|
|
686
701
|
this.set({ [namesOfSlice.modelSelection]: newModelSelection });
|
|
687
702
|
} else {
|
|
688
|
-
this.set({ [namesOfSlice.modelSelection]: new DataList([...modelSelection.values, ...models]) });
|
|
703
|
+
this.set({ [namesOfSlice.modelSelection]: new import_base.DataList([...modelSelection.values, ...models]) });
|
|
689
704
|
}
|
|
690
705
|
},
|
|
691
706
|
[namesOfSlice.setPageOfModel]: async function(page, options) {
|
|
@@ -704,7 +719,7 @@ const makeActions = (gql) => {
|
|
|
704
719
|
sortOfModel,
|
|
705
720
|
options
|
|
706
721
|
);
|
|
707
|
-
const modelList = new DataList(modelDataList);
|
|
722
|
+
const modelList = new import_base.DataList(modelDataList);
|
|
708
723
|
this.set({
|
|
709
724
|
[namesOfSlice.modelList]: modelList,
|
|
710
725
|
[namesOfSlice.pageOfModel]: page,
|
|
@@ -728,7 +743,7 @@ const makeActions = (gql) => {
|
|
|
728
743
|
sortOfModel,
|
|
729
744
|
options
|
|
730
745
|
);
|
|
731
|
-
const newModelList = new DataList(
|
|
746
|
+
const newModelList = new import_base.DataList(
|
|
732
747
|
addFront ? [...modelDataList, ...modelList] : [...modelList, ...modelDataList]
|
|
733
748
|
);
|
|
734
749
|
this.set({ [namesOfSlice.modelList]: newModelList, [namesOfSlice.pageOfModel]: page });
|
|
@@ -751,7 +766,7 @@ const makeActions = (gql) => {
|
|
|
751
766
|
sortOfModel,
|
|
752
767
|
options
|
|
753
768
|
);
|
|
754
|
-
const modelList = new DataList(modelDataList);
|
|
769
|
+
const modelList = new import_base.DataList(modelDataList);
|
|
755
770
|
this.set({
|
|
756
771
|
[namesOfSlice.modelList]: modelList,
|
|
757
772
|
[namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limit) + 1, 1),
|
|
@@ -766,8 +781,8 @@ const makeActions = (gql) => {
|
|
|
766
781
|
const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
|
|
767
782
|
const limitOfModel = currentState[namesOfSlice.limitOfModel];
|
|
768
783
|
const sortOfModel = currentState[namesOfSlice.sortOfModel];
|
|
769
|
-
if (isQueryEqual(queryArgsOfModel, queryArgs)) {
|
|
770
|
-
Logger.trace(`${namesOfSlice.queryArgsOfModel} store-level cache hit`);
|
|
784
|
+
if ((0, import_common.isQueryEqual)(queryArgsOfModel, queryArgs)) {
|
|
785
|
+
import_common.Logger.trace(`${namesOfSlice.queryArgsOfModel} store-level cache hit`);
|
|
771
786
|
return;
|
|
772
787
|
}
|
|
773
788
|
this.set({ [namesOfSlice.modelListLoading]: true });
|
|
@@ -781,7 +796,7 @@ const makeActions = (gql) => {
|
|
|
781
796
|
),
|
|
782
797
|
gql[namesOfSlice.modelInsight](...queryArgs, options)
|
|
783
798
|
]);
|
|
784
|
-
const modelList = new DataList(modelDataList);
|
|
799
|
+
const modelList = new import_base.DataList(modelDataList);
|
|
785
800
|
this.set({
|
|
786
801
|
[namesOfSlice.queryArgsOfModel]: queryArgs,
|
|
787
802
|
[namesOfSlice.modelList]: modelList,
|
|
@@ -807,7 +822,7 @@ const makeActions = (gql) => {
|
|
|
807
822
|
sort,
|
|
808
823
|
options
|
|
809
824
|
);
|
|
810
|
-
const modelList = new DataList(modelDataList);
|
|
825
|
+
const modelList = new import_base.DataList(modelDataList);
|
|
811
826
|
this.set({
|
|
812
827
|
[namesOfSlice.modelList]: modelList,
|
|
813
828
|
[namesOfSlice.sortOfModel]: sort,
|
|
@@ -854,7 +869,7 @@ const scalarStateOf = (refName, state) => {
|
|
|
854
869
|
return StateStore;
|
|
855
870
|
};
|
|
856
871
|
const Store = (returnsOrObj) => {
|
|
857
|
-
const refName = typeof returnsOrObj === "object" ? returnsOrObj.name : lowerlize(getClassMeta(returnsOrObj()).refName);
|
|
872
|
+
const refName = typeof returnsOrObj === "object" ? returnsOrObj.name : (0, import_common.lowerlize)((0, import_constant.getClassMeta)(returnsOrObj()).refName);
|
|
858
873
|
const storeMeta = getStoreMeta(refName);
|
|
859
874
|
return function(target) {
|
|
860
875
|
const customDoKeys = Object.getOwnPropertyNames(target.prototype).filter((key) => key !== "constructor");
|
|
@@ -875,8 +890,8 @@ const createSelectors = (_store, store = {}) => {
|
|
|
875
890
|
const state = store.get();
|
|
876
891
|
store.sub = _store.subscribe;
|
|
877
892
|
const useReference = (selectFn) => {
|
|
878
|
-
const ref = useRef(selectFn(store.get()));
|
|
879
|
-
useEffect(() => {
|
|
893
|
+
const ref = (0, import_react.useRef)(selectFn(store.get()));
|
|
894
|
+
(0, import_react.useEffect)(() => {
|
|
880
895
|
return store.sub(selectFn, (val) => ref.current = val);
|
|
881
896
|
}, []);
|
|
882
897
|
return ref;
|
|
@@ -894,7 +909,7 @@ const createSelectors = (_store, store = {}) => {
|
|
|
894
909
|
for (const k of Object.keys(state)) {
|
|
895
910
|
if (typeof state[k] !== "function") {
|
|
896
911
|
store.use[k] = () => store.sel((s) => s[k]);
|
|
897
|
-
const setKey = `set${capitalize(k)}`;
|
|
912
|
+
const setKey = `set${(0, import_common.capitalize)(k)}`;
|
|
898
913
|
if (!state[setKey])
|
|
899
914
|
store.do[setKey] = (value) => {
|
|
900
915
|
store.set({ [k]: value });
|
|
@@ -902,14 +917,14 @@ const createSelectors = (_store, store = {}) => {
|
|
|
902
917
|
} else {
|
|
903
918
|
store.do[k] = async (...args) => {
|
|
904
919
|
try {
|
|
905
|
-
Logger.verbose(`${k} action loading...`);
|
|
920
|
+
import_common.Logger.verbose(`${k} action loading...`);
|
|
906
921
|
const start = Date.now();
|
|
907
922
|
await state[k](...args);
|
|
908
923
|
const end = Date.now();
|
|
909
|
-
Logger.verbose(`=> ${k} action dispatched (${end - start}ms)`);
|
|
924
|
+
import_common.Logger.verbose(`=> ${k} action dispatched (${end - start}ms)`);
|
|
910
925
|
} catch (e) {
|
|
911
926
|
const errKey = typeof e === "string" ? e : e.message;
|
|
912
|
-
msg.error(errKey, { key: k });
|
|
927
|
+
import_dictionary.msg.error(errKey, { key: k });
|
|
913
928
|
throw e;
|
|
914
929
|
}
|
|
915
930
|
};
|
|
@@ -917,7 +932,7 @@ const createSelectors = (_store, store = {}) => {
|
|
|
917
932
|
}
|
|
918
933
|
const storeNames = getStoreNames();
|
|
919
934
|
for (const storeName of storeNames) {
|
|
920
|
-
const [fieldName, className] = [lowerlize(storeName), capitalize(storeName)];
|
|
935
|
+
const [fieldName, className] = [(0, import_common.lowerlize)(storeName), (0, import_common.capitalize)(storeName)];
|
|
921
936
|
const names = {
|
|
922
937
|
model: fieldName,
|
|
923
938
|
Model: className,
|
|
@@ -944,7 +959,7 @@ const createSelectors = (_store, store = {}) => {
|
|
|
944
959
|
};
|
|
945
960
|
const storeMeta = getStoreMeta(storeName);
|
|
946
961
|
storeMeta.slices.forEach(({ sliceName, argLength, refName }) => {
|
|
947
|
-
const SliceName = capitalize(sliceName);
|
|
962
|
+
const SliceName = (0, import_common.capitalize)(sliceName);
|
|
948
963
|
const namesOfSliceState = {
|
|
949
964
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
950
965
|
modelInitList: SliceName.replace(names.Model, names.modelInitList),
|
|
@@ -976,7 +991,7 @@ const createSelectors = (_store, store = {}) => {
|
|
|
976
991
|
});
|
|
977
992
|
Object.keys(namesOfSliceState).map((key) => {
|
|
978
993
|
targetSlice.use[names[key]] = store.use[namesOfSliceState[key]];
|
|
979
|
-
targetSlice.do[`set${capitalize(names[key])}`] = store.do[`set${capitalize(namesOfSliceState[key])}`];
|
|
994
|
+
targetSlice.do[`set${(0, import_common.capitalize)(names[key])}`] = store.do[`set${(0, import_common.capitalize)(namesOfSliceState[key])}`];
|
|
980
995
|
});
|
|
981
996
|
targetSlice.sliceName = sliceName;
|
|
982
997
|
targetSlice.refName = refName;
|
|
@@ -1003,10 +1018,10 @@ const makePicker = (set, get) => (...fields) => {
|
|
|
1003
1018
|
const makeStore = (st2, storeRef, { library } = {}) => {
|
|
1004
1019
|
if (library)
|
|
1005
1020
|
return st2;
|
|
1006
|
-
const zustandStore = create(
|
|
1007
|
-
devtools(
|
|
1008
|
-
subscribeWithSelector(
|
|
1009
|
-
immer((set, get) => {
|
|
1021
|
+
const zustandStore = (0, import_zustand.create)(
|
|
1022
|
+
(0, import_middleware.devtools)(
|
|
1023
|
+
(0, import_middleware.subscribeWithSelector)(
|
|
1024
|
+
(0, import_immer.immer)((set, get) => {
|
|
1010
1025
|
const store = {};
|
|
1011
1026
|
const pick = makePicker(set, get);
|
|
1012
1027
|
Object.getOwnPropertyNames(storeRef.prototype).forEach((key) => {
|
|
@@ -1058,7 +1073,7 @@ const MixStore = (s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s
|
|
|
1058
1073
|
].filter((s) => !!s);
|
|
1059
1074
|
class Mix {
|
|
1060
1075
|
}
|
|
1061
|
-
applyMixins(Mix, stores);
|
|
1076
|
+
(0, import_common.applyMixins)(Mix, stores);
|
|
1062
1077
|
return Mix;
|
|
1063
1078
|
};
|
|
1064
1079
|
const rootStoreOf = (store) => {
|
|
@@ -1069,27 +1084,15 @@ const Toast = ({ root, duration = 3 } = {}) => {
|
|
|
1069
1084
|
const originMethod = descriptor.value;
|
|
1070
1085
|
descriptor.value = async function(...args) {
|
|
1071
1086
|
try {
|
|
1072
|
-
msg.loading(`${root ? `${root}.` : ""}${key}-loading`, { key, duration });
|
|
1087
|
+
import_dictionary.msg.loading(`${root ? `${root}.` : ""}${key}-loading`, { key, duration });
|
|
1073
1088
|
const result = await originMethod.apply(this, args);
|
|
1074
|
-
msg.success(`${root ? `${root}.` : ""}${key}-success`, { key, duration });
|
|
1089
|
+
import_dictionary.msg.success(`${root ? `${root}.` : ""}${key}-success`, { key, duration });
|
|
1075
1090
|
return result;
|
|
1076
1091
|
} catch (err) {
|
|
1077
1092
|
const errKey = typeof err === "string" ? err : err.message;
|
|
1078
|
-
msg.error(errKey, { key, duration });
|
|
1079
|
-
Logger.error(`${key} action error return: ${err}`);
|
|
1093
|
+
import_dictionary.msg.error(errKey, { key, duration });
|
|
1094
|
+
import_common.Logger.error(`${key} action error return: ${err}`);
|
|
1080
1095
|
}
|
|
1081
1096
|
};
|
|
1082
1097
|
};
|
|
1083
1098
|
};
|
|
1084
|
-
export {
|
|
1085
|
-
MixStore,
|
|
1086
|
-
Store,
|
|
1087
|
-
Toast,
|
|
1088
|
-
createActions,
|
|
1089
|
-
createState,
|
|
1090
|
-
makeStore,
|
|
1091
|
-
rootStoreOf,
|
|
1092
|
-
scalarStateOf,
|
|
1093
|
-
st,
|
|
1094
|
-
stateOf
|
|
1095
|
-
};
|
package/src/storeDecorators.js
CHANGED
|
@@ -1,44 +1,29 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
rootStoreOf: () => rootStoreOf,
|
|
28
|
-
scalarStateOf: () => scalarStateOf,
|
|
29
|
-
st: () => st,
|
|
30
|
-
stateOf: () => stateOf
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(storeDecorators_exports);
|
|
33
|
-
var import_base = require("@akanjs/base");
|
|
34
|
-
var import_common = require("@akanjs/common");
|
|
35
|
-
var import_constant = require("@akanjs/constant");
|
|
36
|
-
var import_dictionary = require("@akanjs/dictionary");
|
|
37
|
-
var import_signal = require("@akanjs/signal");
|
|
38
|
-
var import_react = require("react");
|
|
39
|
-
var import_zustand = require("zustand");
|
|
40
|
-
var import_middleware = require("zustand/middleware");
|
|
41
|
-
var import_immer = require("zustand/middleware/immer");
|
|
2
|
+
import { DataList } from "@akanjs/base";
|
|
3
|
+
import {
|
|
4
|
+
applyMixins,
|
|
5
|
+
capitalize,
|
|
6
|
+
deepObjectify,
|
|
7
|
+
isQueryEqual,
|
|
8
|
+
Logger,
|
|
9
|
+
lowerlize,
|
|
10
|
+
pathSet
|
|
11
|
+
} from "@akanjs/common";
|
|
12
|
+
import {
|
|
13
|
+
getClassMeta,
|
|
14
|
+
getFieldMetas,
|
|
15
|
+
getFullModelRef,
|
|
16
|
+
getLightModelRef
|
|
17
|
+
} from "@akanjs/constant";
|
|
18
|
+
import { msg } from "@akanjs/dictionary";
|
|
19
|
+
import {
|
|
20
|
+
getGqlOnStorage,
|
|
21
|
+
immerify
|
|
22
|
+
} from "@akanjs/signal";
|
|
23
|
+
import { useEffect, useRef } from "react";
|
|
24
|
+
import { create } from "zustand";
|
|
25
|
+
import { devtools, subscribeWithSelector } from "zustand/middleware";
|
|
26
|
+
import { immer } from "zustand/middleware/immer";
|
|
42
27
|
const st = {};
|
|
43
28
|
class StoreStorage {
|
|
44
29
|
}
|
|
@@ -58,7 +43,7 @@ const getStoreNames = () => {
|
|
|
58
43
|
return storeNames;
|
|
59
44
|
};
|
|
60
45
|
const createState = (gql) => {
|
|
61
|
-
const [fieldName, className] = [
|
|
46
|
+
const [fieldName, className] = [lowerlize(gql.refName), capitalize(gql.refName)];
|
|
62
47
|
const names = {
|
|
63
48
|
model: fieldName,
|
|
64
49
|
Model: className,
|
|
@@ -94,7 +79,7 @@ const createState = (gql) => {
|
|
|
94
79
|
[names.modelOperation]: "sleep"
|
|
95
80
|
};
|
|
96
81
|
const sliceState = gql.slices.reduce((acc, { sliceName, defaultArgs }) => {
|
|
97
|
-
const SliceName =
|
|
82
|
+
const SliceName = capitalize(sliceName);
|
|
98
83
|
const namesOfSlice = {
|
|
99
84
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
100
85
|
//clusterInSelf Cluster
|
|
@@ -112,11 +97,11 @@ const createState = (gql) => {
|
|
|
112
97
|
};
|
|
113
98
|
const singleSliceState = {
|
|
114
99
|
[namesOfSlice.defaultModel]: { ...gql[names.defaultModel] },
|
|
115
|
-
[namesOfSlice.modelList]: new
|
|
100
|
+
[namesOfSlice.modelList]: new DataList(),
|
|
116
101
|
[namesOfSlice.modelListLoading]: true,
|
|
117
|
-
[namesOfSlice.modelInitList]: new
|
|
102
|
+
[namesOfSlice.modelInitList]: new DataList(),
|
|
118
103
|
[namesOfSlice.modelInitAt]: /* @__PURE__ */ new Date(0),
|
|
119
|
-
[namesOfSlice.modelSelection]: new
|
|
104
|
+
[namesOfSlice.modelSelection]: new DataList(),
|
|
120
105
|
[namesOfSlice.modelInsight]: gql[names.defaultModelInsight],
|
|
121
106
|
[namesOfSlice.lastPageOfModel]: 1,
|
|
122
107
|
[namesOfSlice.pageOfModel]: 1,
|
|
@@ -134,10 +119,10 @@ const createActions = (gql) => {
|
|
|
134
119
|
return { ...formSetterActions, ...baseActions };
|
|
135
120
|
};
|
|
136
121
|
const makeFormSetter = (gql) => {
|
|
137
|
-
const fileGql =
|
|
138
|
-
const [fieldName, className] = [
|
|
139
|
-
const modelRef =
|
|
140
|
-
const fieldMetas =
|
|
122
|
+
const fileGql = getGqlOnStorage("file");
|
|
123
|
+
const [fieldName, className] = [lowerlize(gql.refName), capitalize(gql.refName)];
|
|
124
|
+
const modelRef = getFullModelRef(gql.refName);
|
|
125
|
+
const fieldMetas = getFieldMetas(modelRef);
|
|
141
126
|
const names = {
|
|
142
127
|
model: fieldName,
|
|
143
128
|
Model: className,
|
|
@@ -148,12 +133,12 @@ const makeFormSetter = (gql) => {
|
|
|
148
133
|
const baseSetAction = {
|
|
149
134
|
[names.writeOnModel]: function(path, value) {
|
|
150
135
|
this.set((state) => {
|
|
151
|
-
|
|
136
|
+
pathSet(state[names.modelForm], path, value);
|
|
152
137
|
});
|
|
153
138
|
}
|
|
154
139
|
};
|
|
155
140
|
const fieldSetAction = fieldMetas.reduce((acc, fieldMeta) => {
|
|
156
|
-
const [fieldKeyName, classKeyName] = [
|
|
141
|
+
const [fieldKeyName, classKeyName] = [lowerlize(fieldMeta.key), capitalize(fieldMeta.key)];
|
|
157
142
|
const namesOfField = {
|
|
158
143
|
field: fieldKeyName,
|
|
159
144
|
Field: classKeyName,
|
|
@@ -166,7 +151,7 @@ const makeFormSetter = (gql) => {
|
|
|
166
151
|
const singleFieldSetAction = {
|
|
167
152
|
[namesOfField.setFieldOnModel]: function(value) {
|
|
168
153
|
this.set((state) => {
|
|
169
|
-
const setValue = fieldMeta.isClass ?
|
|
154
|
+
const setValue = fieldMeta.isClass ? immerify(fieldMeta.modelRef, value) : value;
|
|
170
155
|
state[names.modelForm][namesOfField.field] = setValue;
|
|
171
156
|
});
|
|
172
157
|
},
|
|
@@ -177,7 +162,7 @@ const makeFormSetter = (gql) => {
|
|
|
177
162
|
if (options.limit && options.limit <= length)
|
|
178
163
|
return;
|
|
179
164
|
const idx = options.idx ?? length;
|
|
180
|
-
const setValue = fieldMeta.isClass ?
|
|
165
|
+
const setValue = fieldMeta.isClass ? immerify(fieldMeta.modelRef, value) : value;
|
|
181
166
|
this.set((state) => {
|
|
182
167
|
state[names.modelForm][namesOfField.field] = [
|
|
183
168
|
...form[namesOfField.field].slice(0, idx),
|
|
@@ -251,9 +236,9 @@ const makeFormSetter = (gql) => {
|
|
|
251
236
|
return Object.assign(fieldSetAction, baseSetAction);
|
|
252
237
|
};
|
|
253
238
|
const makeActions = (gql) => {
|
|
254
|
-
const [fieldName, className] = [
|
|
255
|
-
const modelRef =
|
|
256
|
-
const lightModelRef =
|
|
239
|
+
const [fieldName, className] = [lowerlize(gql.refName), capitalize(gql.refName)];
|
|
240
|
+
const modelRef = getFullModelRef(className);
|
|
241
|
+
const lightModelRef = getLightModelRef(modelRef);
|
|
257
242
|
const names = {
|
|
258
243
|
model: fieldName,
|
|
259
244
|
_model: `_${fieldName}`,
|
|
@@ -305,7 +290,7 @@ const makeActions = (gql) => {
|
|
|
305
290
|
};
|
|
306
291
|
const baseAction = {
|
|
307
292
|
[names.createModelInForm]: async function({ idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
|
|
308
|
-
const SliceName =
|
|
293
|
+
const SliceName = capitalize(sliceName);
|
|
309
294
|
const namesOfSlice = {
|
|
310
295
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
311
296
|
modelList: sliceName.replace(names.model, names.modelList),
|
|
@@ -323,13 +308,13 @@ const makeActions = (gql) => {
|
|
|
323
308
|
return;
|
|
324
309
|
this.set({ [names.modelLoading]: true });
|
|
325
310
|
const model = await gql[names.createModel](modelInput, { onError });
|
|
326
|
-
const newModelList = modelListLoading ? modelList : new
|
|
311
|
+
const newModelList = modelListLoading ? modelList : new DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
|
|
327
312
|
const newModelInsight = gql[names.crystalizeInsight]({
|
|
328
313
|
...modelInsight,
|
|
329
314
|
count: modelInsight.count + 1
|
|
330
315
|
});
|
|
331
316
|
this.set({
|
|
332
|
-
[names.modelForm]:
|
|
317
|
+
[names.modelForm]: immerify(modelRef, defaultModel),
|
|
333
318
|
[names.model]: model,
|
|
334
319
|
[names.modelLoading]: false,
|
|
335
320
|
[namesOfSlice.modelList]: newModelList,
|
|
@@ -341,7 +326,7 @@ const makeActions = (gql) => {
|
|
|
341
326
|
await onSuccess?.(model);
|
|
342
327
|
},
|
|
343
328
|
[names.updateModelInForm]: async function({ path, modal, sliceName = names.model, onError, onSuccess } = {}) {
|
|
344
|
-
const SliceName =
|
|
329
|
+
const SliceName = capitalize(sliceName);
|
|
345
330
|
const namesOfSlice = {
|
|
346
331
|
defaultModel: SliceName.replace(names.Model, names.defaultModel)
|
|
347
332
|
};
|
|
@@ -359,7 +344,7 @@ const makeActions = (gql) => {
|
|
|
359
344
|
});
|
|
360
345
|
this.set({
|
|
361
346
|
...model?.id === updatedModel.id ? { [names.model]: updatedModel, [names.modelLoading]: false, [names.modelViewAt]: /* @__PURE__ */ new Date() } : {},
|
|
362
|
-
[names.modelForm]:
|
|
347
|
+
[names.modelForm]: immerify(modelRef, defaultModel),
|
|
363
348
|
[names.modelModal]: modal ?? null,
|
|
364
349
|
...typeof path === "string" && path ? { [path]: updatedModel } : {}
|
|
365
350
|
});
|
|
@@ -374,13 +359,13 @@ const makeActions = (gql) => {
|
|
|
374
359
|
const modelListLoading = currentState2[namesOfSlice2.modelListLoading];
|
|
375
360
|
if (modelListLoading || !modelList.has(updatedModel.id))
|
|
376
361
|
return;
|
|
377
|
-
const newModelList = new
|
|
362
|
+
const newModelList = new DataList(modelList).set(updatedLightModel);
|
|
378
363
|
this.set({ [namesOfSlice2.modelList]: newModelList });
|
|
379
364
|
});
|
|
380
365
|
await onSuccess?.(updatedModel);
|
|
381
366
|
},
|
|
382
367
|
[names.createModel]: async function(data, { idx, path, modal, sliceName = names.model, onError, onSuccess } = {}) {
|
|
383
|
-
const SliceName =
|
|
368
|
+
const SliceName = capitalize(sliceName);
|
|
384
369
|
const namesOfSlice = {
|
|
385
370
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
386
371
|
modelList: sliceName.replace(names.model, names.modelList),
|
|
@@ -396,7 +381,7 @@ const makeActions = (gql) => {
|
|
|
396
381
|
return;
|
|
397
382
|
this.set({ [names.modelLoading]: true });
|
|
398
383
|
const model = await gql[names.createModel](modelInput, { onError });
|
|
399
|
-
const newModelList = modelListLoading ? modelList : new
|
|
384
|
+
const newModelList = modelListLoading ? modelList : new DataList([...modelList.slice(0, idx ?? 0), model, ...modelList.slice(idx ?? 0)]);
|
|
400
385
|
const newModelInsight = gql[names.crystalizeInsight]({
|
|
401
386
|
...modelInsight,
|
|
402
387
|
count: modelInsight.count + 1
|
|
@@ -437,7 +422,7 @@ const makeActions = (gql) => {
|
|
|
437
422
|
const modelListLoading = currentState2[namesOfSlice.modelListLoading];
|
|
438
423
|
if (modelListLoading || !modelList.has(updatedModel.id))
|
|
439
424
|
return;
|
|
440
|
-
const newModelList = new
|
|
425
|
+
const newModelList = new DataList(modelList).set(updatedLightModel);
|
|
441
426
|
this.set({ [namesOfSlice.modelList]: newModelList });
|
|
442
427
|
});
|
|
443
428
|
await onSuccess?.(updatedModel);
|
|
@@ -463,14 +448,14 @@ const makeActions = (gql) => {
|
|
|
463
448
|
const modelInsight = currentState[namesOfSlice.modelInsight];
|
|
464
449
|
if (modelListLoading || !modelList.has(model.id))
|
|
465
450
|
return;
|
|
466
|
-
const newModelList = new
|
|
451
|
+
const newModelList = new DataList(modelList);
|
|
467
452
|
if (model.removedAt) {
|
|
468
453
|
newModelList.delete(id);
|
|
469
454
|
const newModelInsight = gql[names.crystalizeInsight]({
|
|
470
455
|
...modelInsight,
|
|
471
456
|
count: modelInsight.count - 1
|
|
472
457
|
});
|
|
473
|
-
const newModelSelection = new
|
|
458
|
+
const newModelSelection = new DataList(modelSelection);
|
|
474
459
|
newModelSelection.delete(id);
|
|
475
460
|
this.set({
|
|
476
461
|
[namesOfSlice.modelList]: newModelList,
|
|
@@ -506,15 +491,15 @@ const makeActions = (gql) => {
|
|
|
506
491
|
this.set({ [names.modelSubmit]: { ...modelSubmit, loading: false, times: modelSubmit.times + 1 } });
|
|
507
492
|
},
|
|
508
493
|
[names.newModel]: function(partial = {}, { modal, setDefault, sliceName = names.model } = {}) {
|
|
509
|
-
const SliceName =
|
|
494
|
+
const SliceName = capitalize(sliceName);
|
|
510
495
|
const namesOfSlice = {
|
|
511
496
|
defaultModel: SliceName.replace(names.Model, names.defaultModel)
|
|
512
497
|
};
|
|
513
498
|
const currentState = this.get();
|
|
514
499
|
const defaultModel = currentState[namesOfSlice.defaultModel];
|
|
515
500
|
this.set({
|
|
516
|
-
[names.modelForm]:
|
|
517
|
-
[namesOfSlice.defaultModel]: setDefault ?
|
|
501
|
+
[names.modelForm]: immerify(modelRef, { ...defaultModel, ...partial }),
|
|
502
|
+
[namesOfSlice.defaultModel]: setDefault ? immerify(modelRef, { ...defaultModel, ...partial }) : defaultModel,
|
|
518
503
|
[names.model]: null,
|
|
519
504
|
[names.modelModal]: modal ?? "edit",
|
|
520
505
|
[names.modelFormLoading]: false
|
|
@@ -527,7 +512,7 @@ const makeActions = (gql) => {
|
|
|
527
512
|
state[names.modelForm].id = id;
|
|
528
513
|
});
|
|
529
514
|
const model = await gql[names.model](id, { onError });
|
|
530
|
-
const modelForm =
|
|
515
|
+
const modelForm = deepObjectify(model);
|
|
531
516
|
this.set({
|
|
532
517
|
[names.model]: model,
|
|
533
518
|
[names.modelFormLoading]: false,
|
|
@@ -557,7 +542,7 @@ const makeActions = (gql) => {
|
|
|
557
542
|
const modelListLoading = currentState2[namesOfSlice.modelListLoading];
|
|
558
543
|
if (modelListLoading || !modelList.has(updatedModel.id))
|
|
559
544
|
return;
|
|
560
|
-
const newModelList = new
|
|
545
|
+
const newModelList = new DataList(modelList).set(updatedLightModel);
|
|
561
546
|
this.set({ [namesOfSlice.modelList]: newModelList });
|
|
562
547
|
});
|
|
563
548
|
},
|
|
@@ -597,14 +582,14 @@ const makeActions = (gql) => {
|
|
|
597
582
|
this.set({
|
|
598
583
|
[names.model]: model ?? null,
|
|
599
584
|
[names.modelViewAt]: /* @__PURE__ */ new Date(0),
|
|
600
|
-
[names.modelForm]:
|
|
585
|
+
[names.modelForm]: immerify(modelRef, defaultModel),
|
|
601
586
|
[names.modelModal]: null
|
|
602
587
|
});
|
|
603
588
|
return model ?? null;
|
|
604
589
|
}
|
|
605
590
|
};
|
|
606
591
|
const sliceAction = gql.slices.reduce((acc, { sliceName, argLength }) => {
|
|
607
|
-
const SliceName =
|
|
592
|
+
const SliceName = capitalize(sliceName);
|
|
608
593
|
const namesOfSlice = {
|
|
609
594
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
610
595
|
modelInsight: sliceName.replace(names.model, names.modelInsight),
|
|
@@ -632,7 +617,7 @@ const makeActions = (gql) => {
|
|
|
632
617
|
const initArgLength = Math.min(args.length, argLength);
|
|
633
618
|
const initForm = { invalidate: false, ...args[argLength] ?? {} };
|
|
634
619
|
const queryArgs = new Array(initArgLength).fill(null).map((_, i) => args[i]);
|
|
635
|
-
const defaultModel =
|
|
620
|
+
const defaultModel = immerify(modelRef, { ...gql[names.defaultModel], ...initForm.default ?? {} });
|
|
636
621
|
this.set({ [names.defaultModel]: defaultModel });
|
|
637
622
|
await this[namesOfSlice.refreshModel](
|
|
638
623
|
...initArgLength === argLength ? [...queryArgs, initForm] : queryArgs
|
|
@@ -658,7 +643,7 @@ const makeActions = (gql) => {
|
|
|
658
643
|
const pageOfModel = currentState[namesOfSlice.pageOfModel];
|
|
659
644
|
const limitOfModel = currentState[namesOfSlice.limitOfModel];
|
|
660
645
|
const sortOfModel = currentState[namesOfSlice.sortOfModel];
|
|
661
|
-
if (!invalidate && !["sleep", "reset"].includes(modelOperation) &&
|
|
646
|
+
if (!invalidate && !["sleep", "reset"].includes(modelOperation) && isQueryEqual(queryArgs, queryArgsOfModel) && page === pageOfModel && limit === limitOfModel && isQueryEqual(sort, sortOfModel))
|
|
662
647
|
return;
|
|
663
648
|
else
|
|
664
649
|
this.set({ [namesOfSlice.modelListLoading]: true });
|
|
@@ -674,7 +659,7 @@ const makeActions = (gql) => {
|
|
|
674
659
|
onError: initForm.onError
|
|
675
660
|
})
|
|
676
661
|
]);
|
|
677
|
-
const modelList = new
|
|
662
|
+
const modelList = new DataList(modelDataList);
|
|
678
663
|
this.set({
|
|
679
664
|
[namesOfSlice.modelList]: modelList,
|
|
680
665
|
[namesOfSlice.modelListLoading]: false,
|
|
@@ -694,13 +679,13 @@ const makeActions = (gql) => {
|
|
|
694
679
|
const currentState = this.get();
|
|
695
680
|
const modelSelection = currentState[namesOfSlice.modelSelection];
|
|
696
681
|
if (refresh)
|
|
697
|
-
this.set({ [namesOfSlice.modelSelection]: new
|
|
682
|
+
this.set({ [namesOfSlice.modelSelection]: new DataList(models) });
|
|
698
683
|
else if (remove) {
|
|
699
|
-
const newModelSelection = new
|
|
684
|
+
const newModelSelection = new DataList(modelSelection);
|
|
700
685
|
models.map((model2) => newModelSelection.delete(model2.id));
|
|
701
686
|
this.set({ [namesOfSlice.modelSelection]: newModelSelection });
|
|
702
687
|
} else {
|
|
703
|
-
this.set({ [namesOfSlice.modelSelection]: new
|
|
688
|
+
this.set({ [namesOfSlice.modelSelection]: new DataList([...modelSelection.values, ...models]) });
|
|
704
689
|
}
|
|
705
690
|
},
|
|
706
691
|
[namesOfSlice.setPageOfModel]: async function(page, options) {
|
|
@@ -719,7 +704,7 @@ const makeActions = (gql) => {
|
|
|
719
704
|
sortOfModel,
|
|
720
705
|
options
|
|
721
706
|
);
|
|
722
|
-
const modelList = new
|
|
707
|
+
const modelList = new DataList(modelDataList);
|
|
723
708
|
this.set({
|
|
724
709
|
[namesOfSlice.modelList]: modelList,
|
|
725
710
|
[namesOfSlice.pageOfModel]: page,
|
|
@@ -743,7 +728,7 @@ const makeActions = (gql) => {
|
|
|
743
728
|
sortOfModel,
|
|
744
729
|
options
|
|
745
730
|
);
|
|
746
|
-
const newModelList = new
|
|
731
|
+
const newModelList = new DataList(
|
|
747
732
|
addFront ? [...modelDataList, ...modelList] : [...modelList, ...modelDataList]
|
|
748
733
|
);
|
|
749
734
|
this.set({ [namesOfSlice.modelList]: newModelList, [namesOfSlice.pageOfModel]: page });
|
|
@@ -766,7 +751,7 @@ const makeActions = (gql) => {
|
|
|
766
751
|
sortOfModel,
|
|
767
752
|
options
|
|
768
753
|
);
|
|
769
|
-
const modelList = new
|
|
754
|
+
const modelList = new DataList(modelDataList);
|
|
770
755
|
this.set({
|
|
771
756
|
[namesOfSlice.modelList]: modelList,
|
|
772
757
|
[namesOfSlice.lastPageOfModel]: Math.max(Math.floor((modelInsight.count - 1) / limit) + 1, 1),
|
|
@@ -781,8 +766,8 @@ const makeActions = (gql) => {
|
|
|
781
766
|
const queryArgsOfModel = currentState[namesOfSlice.queryArgsOfModel];
|
|
782
767
|
const limitOfModel = currentState[namesOfSlice.limitOfModel];
|
|
783
768
|
const sortOfModel = currentState[namesOfSlice.sortOfModel];
|
|
784
|
-
if (
|
|
785
|
-
|
|
769
|
+
if (isQueryEqual(queryArgsOfModel, queryArgs)) {
|
|
770
|
+
Logger.trace(`${namesOfSlice.queryArgsOfModel} store-level cache hit`);
|
|
786
771
|
return;
|
|
787
772
|
}
|
|
788
773
|
this.set({ [namesOfSlice.modelListLoading]: true });
|
|
@@ -796,7 +781,7 @@ const makeActions = (gql) => {
|
|
|
796
781
|
),
|
|
797
782
|
gql[namesOfSlice.modelInsight](...queryArgs, options)
|
|
798
783
|
]);
|
|
799
|
-
const modelList = new
|
|
784
|
+
const modelList = new DataList(modelDataList);
|
|
800
785
|
this.set({
|
|
801
786
|
[namesOfSlice.queryArgsOfModel]: queryArgs,
|
|
802
787
|
[namesOfSlice.modelList]: modelList,
|
|
@@ -822,7 +807,7 @@ const makeActions = (gql) => {
|
|
|
822
807
|
sort,
|
|
823
808
|
options
|
|
824
809
|
);
|
|
825
|
-
const modelList = new
|
|
810
|
+
const modelList = new DataList(modelDataList);
|
|
826
811
|
this.set({
|
|
827
812
|
[namesOfSlice.modelList]: modelList,
|
|
828
813
|
[namesOfSlice.sortOfModel]: sort,
|
|
@@ -869,7 +854,7 @@ const scalarStateOf = (refName, state) => {
|
|
|
869
854
|
return StateStore;
|
|
870
855
|
};
|
|
871
856
|
const Store = (returnsOrObj) => {
|
|
872
|
-
const refName = typeof returnsOrObj === "object" ? returnsOrObj.name :
|
|
857
|
+
const refName = typeof returnsOrObj === "object" ? returnsOrObj.name : lowerlize(getClassMeta(returnsOrObj()).refName);
|
|
873
858
|
const storeMeta = getStoreMeta(refName);
|
|
874
859
|
return function(target) {
|
|
875
860
|
const customDoKeys = Object.getOwnPropertyNames(target.prototype).filter((key) => key !== "constructor");
|
|
@@ -890,8 +875,8 @@ const createSelectors = (_store, store = {}) => {
|
|
|
890
875
|
const state = store.get();
|
|
891
876
|
store.sub = _store.subscribe;
|
|
892
877
|
const useReference = (selectFn) => {
|
|
893
|
-
const ref =
|
|
894
|
-
|
|
878
|
+
const ref = useRef(selectFn(store.get()));
|
|
879
|
+
useEffect(() => {
|
|
895
880
|
return store.sub(selectFn, (val) => ref.current = val);
|
|
896
881
|
}, []);
|
|
897
882
|
return ref;
|
|
@@ -909,7 +894,7 @@ const createSelectors = (_store, store = {}) => {
|
|
|
909
894
|
for (const k of Object.keys(state)) {
|
|
910
895
|
if (typeof state[k] !== "function") {
|
|
911
896
|
store.use[k] = () => store.sel((s) => s[k]);
|
|
912
|
-
const setKey = `set${
|
|
897
|
+
const setKey = `set${capitalize(k)}`;
|
|
913
898
|
if (!state[setKey])
|
|
914
899
|
store.do[setKey] = (value) => {
|
|
915
900
|
store.set({ [k]: value });
|
|
@@ -917,14 +902,14 @@ const createSelectors = (_store, store = {}) => {
|
|
|
917
902
|
} else {
|
|
918
903
|
store.do[k] = async (...args) => {
|
|
919
904
|
try {
|
|
920
|
-
|
|
905
|
+
Logger.verbose(`${k} action loading...`);
|
|
921
906
|
const start = Date.now();
|
|
922
907
|
await state[k](...args);
|
|
923
908
|
const end = Date.now();
|
|
924
|
-
|
|
909
|
+
Logger.verbose(`=> ${k} action dispatched (${end - start}ms)`);
|
|
925
910
|
} catch (e) {
|
|
926
911
|
const errKey = typeof e === "string" ? e : e.message;
|
|
927
|
-
|
|
912
|
+
msg.error(errKey, { key: k });
|
|
928
913
|
throw e;
|
|
929
914
|
}
|
|
930
915
|
};
|
|
@@ -932,7 +917,7 @@ const createSelectors = (_store, store = {}) => {
|
|
|
932
917
|
}
|
|
933
918
|
const storeNames = getStoreNames();
|
|
934
919
|
for (const storeName of storeNames) {
|
|
935
|
-
const [fieldName, className] = [
|
|
920
|
+
const [fieldName, className] = [lowerlize(storeName), capitalize(storeName)];
|
|
936
921
|
const names = {
|
|
937
922
|
model: fieldName,
|
|
938
923
|
Model: className,
|
|
@@ -959,7 +944,7 @@ const createSelectors = (_store, store = {}) => {
|
|
|
959
944
|
};
|
|
960
945
|
const storeMeta = getStoreMeta(storeName);
|
|
961
946
|
storeMeta.slices.forEach(({ sliceName, argLength, refName }) => {
|
|
962
|
-
const SliceName =
|
|
947
|
+
const SliceName = capitalize(sliceName);
|
|
963
948
|
const namesOfSliceState = {
|
|
964
949
|
defaultModel: SliceName.replace(names.Model, names.defaultModel),
|
|
965
950
|
modelInitList: SliceName.replace(names.Model, names.modelInitList),
|
|
@@ -991,7 +976,7 @@ const createSelectors = (_store, store = {}) => {
|
|
|
991
976
|
});
|
|
992
977
|
Object.keys(namesOfSliceState).map((key) => {
|
|
993
978
|
targetSlice.use[names[key]] = store.use[namesOfSliceState[key]];
|
|
994
|
-
targetSlice.do[`set${
|
|
979
|
+
targetSlice.do[`set${capitalize(names[key])}`] = store.do[`set${capitalize(namesOfSliceState[key])}`];
|
|
995
980
|
});
|
|
996
981
|
targetSlice.sliceName = sliceName;
|
|
997
982
|
targetSlice.refName = refName;
|
|
@@ -1018,10 +1003,10 @@ const makePicker = (set, get) => (...fields) => {
|
|
|
1018
1003
|
const makeStore = (st2, storeRef, { library } = {}) => {
|
|
1019
1004
|
if (library)
|
|
1020
1005
|
return st2;
|
|
1021
|
-
const zustandStore =
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1006
|
+
const zustandStore = create(
|
|
1007
|
+
devtools(
|
|
1008
|
+
subscribeWithSelector(
|
|
1009
|
+
immer((set, get) => {
|
|
1025
1010
|
const store = {};
|
|
1026
1011
|
const pick = makePicker(set, get);
|
|
1027
1012
|
Object.getOwnPropertyNames(storeRef.prototype).forEach((key) => {
|
|
@@ -1073,7 +1058,7 @@ const MixStore = (s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s
|
|
|
1073
1058
|
].filter((s) => !!s);
|
|
1074
1059
|
class Mix {
|
|
1075
1060
|
}
|
|
1076
|
-
|
|
1061
|
+
applyMixins(Mix, stores);
|
|
1077
1062
|
return Mix;
|
|
1078
1063
|
};
|
|
1079
1064
|
const rootStoreOf = (store) => {
|
|
@@ -1084,15 +1069,27 @@ const Toast = ({ root, duration = 3 } = {}) => {
|
|
|
1084
1069
|
const originMethod = descriptor.value;
|
|
1085
1070
|
descriptor.value = async function(...args) {
|
|
1086
1071
|
try {
|
|
1087
|
-
|
|
1072
|
+
msg.loading(`${root ? `${root}.` : ""}${key}-loading`, { key, duration });
|
|
1088
1073
|
const result = await originMethod.apply(this, args);
|
|
1089
|
-
|
|
1074
|
+
msg.success(`${root ? `${root}.` : ""}${key}-success`, { key, duration });
|
|
1090
1075
|
return result;
|
|
1091
1076
|
} catch (err) {
|
|
1092
1077
|
const errKey = typeof err === "string" ? err : err.message;
|
|
1093
|
-
|
|
1094
|
-
|
|
1078
|
+
msg.error(errKey, { key, duration });
|
|
1079
|
+
Logger.error(`${key} action error return: ${err}`);
|
|
1095
1080
|
}
|
|
1096
1081
|
};
|
|
1097
1082
|
};
|
|
1098
1083
|
};
|
|
1084
|
+
export {
|
|
1085
|
+
MixStore,
|
|
1086
|
+
Store,
|
|
1087
|
+
Toast,
|
|
1088
|
+
createActions,
|
|
1089
|
+
createState,
|
|
1090
|
+
makeStore,
|
|
1091
|
+
rootStoreOf,
|
|
1092
|
+
scalarStateOf,
|
|
1093
|
+
st,
|
|
1094
|
+
stateOf
|
|
1095
|
+
};
|
package/src/types.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
package/src/types.js
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var types_exports = {};
|
|
15
|
-
module.exports = __toCommonJS(types_exports);
|
package/index.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src";
|
package/src/index.mjs
DELETED
package/src/types.mjs
DELETED
|
File without changes
|