@cclr/model 0.1.6
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/LICENSE +19 -0
- package/README.md +17 -0
- package/lib/cjs/index.js +372 -0
- package/lib/esm/index.js +363 -0
- package/lib/type/index.d.ts +121 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# `model`
|
|
2
|
+
|
|
3
|
+
> TODO: description
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
const front = require('front');
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 功能
|
|
13
|
+
|
|
14
|
+
1. 正常的发布订阅
|
|
15
|
+
2. 在新建model实例之前,可以管理全局预设的中间件
|
|
16
|
+
3. 可以在model实例中,动态添加中间件,只能向洋葱模型的最外层添加(无法管理中间件顺序,除非是新建的配置里面)
|
|
17
|
+
4. 可以单独新建一个model,也可以同时新建多个model,每个model都是独立的
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var immer = require('immer');
|
|
4
|
+
var lang = require('@cclr/lang');
|
|
5
|
+
|
|
6
|
+
var State = {};
|
|
7
|
+
var Actions = {};
|
|
8
|
+
var Subscribes = {
|
|
9
|
+
/*******
|
|
10
|
+
[modelName]: [
|
|
11
|
+
() => { }
|
|
12
|
+
]
|
|
13
|
+
********/
|
|
14
|
+
};
|
|
15
|
+
var GlobalModel = {
|
|
16
|
+
__MId: 1,
|
|
17
|
+
State: State,
|
|
18
|
+
Actions: Actions,
|
|
19
|
+
Subscribes: Subscribes
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
var getCtx = function getCtx(modelName) {
|
|
23
|
+
return {
|
|
24
|
+
state: GlobalModel.State[modelName],
|
|
25
|
+
actions: GlobalModel.Actions[modelName],
|
|
26
|
+
subscribes: GlobalModel.Subscribes[modelName]
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var getState = function getState(modelName) {
|
|
30
|
+
return GlobalModel.State[modelName];
|
|
31
|
+
};
|
|
32
|
+
var getActions = function getActions(modelName) {
|
|
33
|
+
return GlobalModel.Actions[modelName];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var applyMiddleware = function applyMiddleware() {};
|
|
37
|
+
|
|
38
|
+
function _arrayLikeToArray(r, a) {
|
|
39
|
+
(null == a || a > r.length) && (a = r.length);
|
|
40
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
41
|
+
return n;
|
|
42
|
+
}
|
|
43
|
+
function _arrayWithHoles(r) {
|
|
44
|
+
if (Array.isArray(r)) return r;
|
|
45
|
+
}
|
|
46
|
+
function _arrayWithoutHoles(r) {
|
|
47
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
48
|
+
}
|
|
49
|
+
function _defineProperty(e, r, t) {
|
|
50
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
51
|
+
value: t,
|
|
52
|
+
enumerable: !0,
|
|
53
|
+
configurable: !0,
|
|
54
|
+
writable: !0
|
|
55
|
+
}) : e[r] = t, e;
|
|
56
|
+
}
|
|
57
|
+
function _iterableToArray(r) {
|
|
58
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
59
|
+
}
|
|
60
|
+
function _iterableToArrayLimit(r, l) {
|
|
61
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
62
|
+
if (null != t) {
|
|
63
|
+
var e,
|
|
64
|
+
n,
|
|
65
|
+
i,
|
|
66
|
+
u,
|
|
67
|
+
a = [],
|
|
68
|
+
f = !0,
|
|
69
|
+
o = !1;
|
|
70
|
+
try {
|
|
71
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
72
|
+
} catch (r) {
|
|
73
|
+
o = !0, n = r;
|
|
74
|
+
} finally {
|
|
75
|
+
try {
|
|
76
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
77
|
+
} finally {
|
|
78
|
+
if (o) throw n;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return a;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function _nonIterableRest() {
|
|
85
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
86
|
+
}
|
|
87
|
+
function _nonIterableSpread() {
|
|
88
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
89
|
+
}
|
|
90
|
+
function ownKeys(e, r) {
|
|
91
|
+
var t = Object.keys(e);
|
|
92
|
+
if (Object.getOwnPropertySymbols) {
|
|
93
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
94
|
+
r && (o = o.filter(function (r) {
|
|
95
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
96
|
+
})), t.push.apply(t, o);
|
|
97
|
+
}
|
|
98
|
+
return t;
|
|
99
|
+
}
|
|
100
|
+
function _objectSpread2(e) {
|
|
101
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
102
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
103
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
104
|
+
_defineProperty(e, r, t[r]);
|
|
105
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
106
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return e;
|
|
110
|
+
}
|
|
111
|
+
function _slicedToArray(r, e) {
|
|
112
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
113
|
+
}
|
|
114
|
+
function _toConsumableArray(r) {
|
|
115
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
116
|
+
}
|
|
117
|
+
function _toPrimitive(t, r) {
|
|
118
|
+
if ("object" != typeof t || !t) return t;
|
|
119
|
+
var e = t[Symbol.toPrimitive];
|
|
120
|
+
if (void 0 !== e) {
|
|
121
|
+
var i = e.call(t, r || "default");
|
|
122
|
+
if ("object" != typeof i) return i;
|
|
123
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
124
|
+
}
|
|
125
|
+
return ("string" === r ? String : Number)(t);
|
|
126
|
+
}
|
|
127
|
+
function _toPropertyKey(t) {
|
|
128
|
+
var i = _toPrimitive(t, "string");
|
|
129
|
+
return "symbol" == typeof i ? i : i + "";
|
|
130
|
+
}
|
|
131
|
+
function _unsupportedIterableToArray(r, a) {
|
|
132
|
+
if (r) {
|
|
133
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
134
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
135
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
var gatter = function gatter(ctx) {
|
|
140
|
+
return function (next) {
|
|
141
|
+
return function (params) {
|
|
142
|
+
return new Promise(function ($return, $error) {
|
|
143
|
+
var action, payload, state, actions;
|
|
144
|
+
action = ctx.action, payload = ctx.payload, state = ctx.state, actions = ctx.actions;
|
|
145
|
+
return Promise.resolve(action(payload, {
|
|
146
|
+
state: state,
|
|
147
|
+
actions: actions
|
|
148
|
+
})).then(function ($await_1) {
|
|
149
|
+
try {
|
|
150
|
+
ctx.newState = $await_1;
|
|
151
|
+
return $return(next(params));
|
|
152
|
+
} catch ($boundEx) {
|
|
153
|
+
return $error($boundEx);
|
|
154
|
+
}
|
|
155
|
+
}, $error);
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
var logger = function logger(ctx) {
|
|
162
|
+
return function (next) {
|
|
163
|
+
return function (params) {
|
|
164
|
+
return new Promise(function ($return, $error) {
|
|
165
|
+
var r;
|
|
166
|
+
console.log(ctx.modelName, '- action -start: ', ctx.action.name);
|
|
167
|
+
return Promise.resolve(next(params)).then(function ($await_1) {
|
|
168
|
+
try {
|
|
169
|
+
r = $await_1;
|
|
170
|
+
console.log(ctx.modelName, '- action -end: ', ctx.action.name);
|
|
171
|
+
return $return(r);
|
|
172
|
+
} catch ($boundEx) {
|
|
173
|
+
return $error($boundEx);
|
|
174
|
+
}
|
|
175
|
+
}, $error);
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 发布函数
|
|
183
|
+
* @param ctx
|
|
184
|
+
* @returns
|
|
185
|
+
*/
|
|
186
|
+
var publish = function publish(ctx) {
|
|
187
|
+
return function (next) {
|
|
188
|
+
return function (params) {
|
|
189
|
+
var subscribes = ctx.subscribes;
|
|
190
|
+
subscribes === null || subscribes === void 0 || subscribes.forEach(function (callback) {
|
|
191
|
+
callback();
|
|
192
|
+
});
|
|
193
|
+
return next(params);
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* action返回
|
|
200
|
+
* @param ctx
|
|
201
|
+
* @returns
|
|
202
|
+
*/
|
|
203
|
+
var returnState = function returnState(ctx) {
|
|
204
|
+
return function (_next) {
|
|
205
|
+
return function (_params) {
|
|
206
|
+
return getState(ctx.modelName);
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
var produceState = function produceState(base, recipe) {
|
|
212
|
+
return immer.produce(base, recipe);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
var setter = function setter(ctx) {
|
|
216
|
+
return function (next) {
|
|
217
|
+
return function (params) {
|
|
218
|
+
return new Promise(function ($return, $error) {
|
|
219
|
+
var modelName = ctx.modelName;
|
|
220
|
+
var newState = ctx.newState;
|
|
221
|
+
if (!newState) {
|
|
222
|
+
return $return(getState(modelName));
|
|
223
|
+
}
|
|
224
|
+
if (lang.isFunction(newState)) {
|
|
225
|
+
newState = produceState(getState(modelName), newState);
|
|
226
|
+
}
|
|
227
|
+
GlobalModel.State = immer.produce(GlobalModel.State, function (draft) {
|
|
228
|
+
draft[modelName] = newState;
|
|
229
|
+
});
|
|
230
|
+
return $return(next(params));
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
var tryCatch = function tryCatch() {
|
|
237
|
+
return function (next) {
|
|
238
|
+
return function (params) {
|
|
239
|
+
return new Promise(function ($return, $error) {
|
|
240
|
+
var _next;
|
|
241
|
+
return Promise.resolve((_next = next(params)) === null || _next === void 0 ? void 0 : _next.catch(function (e) {
|
|
242
|
+
return console.log(e);
|
|
243
|
+
})).then($return, $error);
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
var presetMiddleware = [tryCatch, logger, gatter, setter, publish, returnState];
|
|
250
|
+
|
|
251
|
+
function compose() {
|
|
252
|
+
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
253
|
+
funcs[_key] = arguments[_key];
|
|
254
|
+
}
|
|
255
|
+
if (funcs.length === 0) {
|
|
256
|
+
return function (arg) {
|
|
257
|
+
return arg;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
if (funcs.length === 1) {
|
|
261
|
+
return funcs[0];
|
|
262
|
+
}
|
|
263
|
+
return funcs.reduce(function (a, b) {
|
|
264
|
+
return function () {
|
|
265
|
+
return a(b.apply(void 0, arguments));
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
var rebuildActions = function rebuildActions(actions, modelName) {
|
|
271
|
+
var updateActions = {};
|
|
272
|
+
Object.entries(actions).forEach(function (_ref) {
|
|
273
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
274
|
+
key = _ref2[0],
|
|
275
|
+
action = _ref2[1];
|
|
276
|
+
updateActions[key] = resetAction(action, modelName);
|
|
277
|
+
});
|
|
278
|
+
return updateActions;
|
|
279
|
+
};
|
|
280
|
+
var resetAction = function resetAction(action, modelName) {
|
|
281
|
+
return function (payload) {
|
|
282
|
+
var _getCtx = getCtx(modelName),
|
|
283
|
+
state = _getCtx.state,
|
|
284
|
+
actions = _getCtx.actions,
|
|
285
|
+
subscribes = _getCtx.subscribes;
|
|
286
|
+
var ctx = {
|
|
287
|
+
payload: payload,
|
|
288
|
+
state: state,
|
|
289
|
+
actions: actions,
|
|
290
|
+
action: action,
|
|
291
|
+
subscribes: subscribes,
|
|
292
|
+
modelName: modelName,
|
|
293
|
+
newState: null,
|
|
294
|
+
setterFun: undefined
|
|
295
|
+
};
|
|
296
|
+
var middlewares = presetMiddleware.map(function (middleware) {
|
|
297
|
+
return middleware(ctx);
|
|
298
|
+
});
|
|
299
|
+
var composeFun = compose.apply(void 0, _toConsumableArray(middlewares));
|
|
300
|
+
return composeFun(function () {
|
|
301
|
+
return getState(modelName);
|
|
302
|
+
})();
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
var initModel = function initModel(models) {
|
|
307
|
+
Object.entries(models).forEach(function (_ref) {
|
|
308
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
309
|
+
modelName = _ref2[0],
|
|
310
|
+
model = _ref2[1];
|
|
311
|
+
GlobalModel.__MId++;
|
|
312
|
+
GlobalModel.State = produceState(GlobalModel.State, function (draft) {
|
|
313
|
+
draft[modelName] = model.state;
|
|
314
|
+
});
|
|
315
|
+
GlobalModel.Actions[modelName] = _objectSpread2({}, rebuildActions(model.actions, modelName));
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 取消订阅 model 的 state 变化
|
|
321
|
+
* @param modelName
|
|
322
|
+
* @param callback
|
|
323
|
+
* @returns
|
|
324
|
+
*/
|
|
325
|
+
var unsubscribe = function unsubscribe(modelName, callback) {
|
|
326
|
+
if (!GlobalModel.Subscribes[modelName]) {
|
|
327
|
+
GlobalModel.Subscribes[modelName] = [];
|
|
328
|
+
}
|
|
329
|
+
GlobalModel.Subscribes[modelName] = GlobalModel.Subscribes[modelName].filter(function (item) {
|
|
330
|
+
return item !== callback;
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* 订阅 model 的 state 变化
|
|
336
|
+
* @param modelName
|
|
337
|
+
* @param callback
|
|
338
|
+
* @returns
|
|
339
|
+
*/
|
|
340
|
+
var subscribe = function subscribe(modelName, callback) {
|
|
341
|
+
if (!GlobalModel.Subscribes[modelName]) {
|
|
342
|
+
GlobalModel.Subscribes[modelName] = [];
|
|
343
|
+
}
|
|
344
|
+
GlobalModel.Subscribes[modelName].push(callback);
|
|
345
|
+
return function () {
|
|
346
|
+
return unsubscribe(modelName, callback);
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Model 类
|
|
352
|
+
*/
|
|
353
|
+
var Model = function Model(models) {
|
|
354
|
+
/** 初始化 */
|
|
355
|
+
initModel(models);
|
|
356
|
+
return {
|
|
357
|
+
getState: getState,
|
|
358
|
+
getActions: getActions,
|
|
359
|
+
subscribe: subscribe,
|
|
360
|
+
unsubscribe: unsubscribe,
|
|
361
|
+
applyMiddleware: applyMiddleware
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
exports.Model = Model;
|
|
366
|
+
exports.gatter = gatter;
|
|
367
|
+
exports.logger = logger;
|
|
368
|
+
exports.presetMiddleware = presetMiddleware;
|
|
369
|
+
exports.publish = publish;
|
|
370
|
+
exports.returnState = returnState;
|
|
371
|
+
exports.setter = setter;
|
|
372
|
+
exports.tryCatch = tryCatch;
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { produce } from 'immer';
|
|
2
|
+
import { isFunction } from '@cclr/lang';
|
|
3
|
+
|
|
4
|
+
var State = {};
|
|
5
|
+
var Actions = {};
|
|
6
|
+
var Subscribes = {
|
|
7
|
+
/*******
|
|
8
|
+
[modelName]: [
|
|
9
|
+
() => { }
|
|
10
|
+
]
|
|
11
|
+
********/
|
|
12
|
+
};
|
|
13
|
+
var GlobalModel = {
|
|
14
|
+
__MId: 1,
|
|
15
|
+
State: State,
|
|
16
|
+
Actions: Actions,
|
|
17
|
+
Subscribes: Subscribes
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
var getCtx = function getCtx(modelName) {
|
|
21
|
+
return {
|
|
22
|
+
state: GlobalModel.State[modelName],
|
|
23
|
+
actions: GlobalModel.Actions[modelName],
|
|
24
|
+
subscribes: GlobalModel.Subscribes[modelName]
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
var getState = function getState(modelName) {
|
|
28
|
+
return GlobalModel.State[modelName];
|
|
29
|
+
};
|
|
30
|
+
var getActions = function getActions(modelName) {
|
|
31
|
+
return GlobalModel.Actions[modelName];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var applyMiddleware = function applyMiddleware() {};
|
|
35
|
+
|
|
36
|
+
function _arrayLikeToArray(r, a) {
|
|
37
|
+
(null == a || a > r.length) && (a = r.length);
|
|
38
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
39
|
+
return n;
|
|
40
|
+
}
|
|
41
|
+
function _arrayWithHoles(r) {
|
|
42
|
+
if (Array.isArray(r)) return r;
|
|
43
|
+
}
|
|
44
|
+
function _arrayWithoutHoles(r) {
|
|
45
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
46
|
+
}
|
|
47
|
+
function _defineProperty(e, r, t) {
|
|
48
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
49
|
+
value: t,
|
|
50
|
+
enumerable: !0,
|
|
51
|
+
configurable: !0,
|
|
52
|
+
writable: !0
|
|
53
|
+
}) : e[r] = t, e;
|
|
54
|
+
}
|
|
55
|
+
function _iterableToArray(r) {
|
|
56
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
57
|
+
}
|
|
58
|
+
function _iterableToArrayLimit(r, l) {
|
|
59
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
60
|
+
if (null != t) {
|
|
61
|
+
var e,
|
|
62
|
+
n,
|
|
63
|
+
i,
|
|
64
|
+
u,
|
|
65
|
+
a = [],
|
|
66
|
+
f = !0,
|
|
67
|
+
o = !1;
|
|
68
|
+
try {
|
|
69
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
70
|
+
} catch (r) {
|
|
71
|
+
o = !0, n = r;
|
|
72
|
+
} finally {
|
|
73
|
+
try {
|
|
74
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
75
|
+
} finally {
|
|
76
|
+
if (o) throw n;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return a;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function _nonIterableRest() {
|
|
83
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
84
|
+
}
|
|
85
|
+
function _nonIterableSpread() {
|
|
86
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
87
|
+
}
|
|
88
|
+
function ownKeys(e, r) {
|
|
89
|
+
var t = Object.keys(e);
|
|
90
|
+
if (Object.getOwnPropertySymbols) {
|
|
91
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
92
|
+
r && (o = o.filter(function (r) {
|
|
93
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
94
|
+
})), t.push.apply(t, o);
|
|
95
|
+
}
|
|
96
|
+
return t;
|
|
97
|
+
}
|
|
98
|
+
function _objectSpread2(e) {
|
|
99
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
100
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
101
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
102
|
+
_defineProperty(e, r, t[r]);
|
|
103
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
104
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return e;
|
|
108
|
+
}
|
|
109
|
+
function _slicedToArray(r, e) {
|
|
110
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
111
|
+
}
|
|
112
|
+
function _toConsumableArray(r) {
|
|
113
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
114
|
+
}
|
|
115
|
+
function _toPrimitive(t, r) {
|
|
116
|
+
if ("object" != typeof t || !t) return t;
|
|
117
|
+
var e = t[Symbol.toPrimitive];
|
|
118
|
+
if (void 0 !== e) {
|
|
119
|
+
var i = e.call(t, r || "default");
|
|
120
|
+
if ("object" != typeof i) return i;
|
|
121
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
122
|
+
}
|
|
123
|
+
return ("string" === r ? String : Number)(t);
|
|
124
|
+
}
|
|
125
|
+
function _toPropertyKey(t) {
|
|
126
|
+
var i = _toPrimitive(t, "string");
|
|
127
|
+
return "symbol" == typeof i ? i : i + "";
|
|
128
|
+
}
|
|
129
|
+
function _unsupportedIterableToArray(r, a) {
|
|
130
|
+
if (r) {
|
|
131
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
132
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
133
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
var gatter = function gatter(ctx) {
|
|
138
|
+
return function (next) {
|
|
139
|
+
return function (params) {
|
|
140
|
+
return new Promise(function ($return, $error) {
|
|
141
|
+
var action, payload, state, actions;
|
|
142
|
+
action = ctx.action, payload = ctx.payload, state = ctx.state, actions = ctx.actions;
|
|
143
|
+
return Promise.resolve(action(payload, {
|
|
144
|
+
state: state,
|
|
145
|
+
actions: actions
|
|
146
|
+
})).then(function ($await_1) {
|
|
147
|
+
try {
|
|
148
|
+
ctx.newState = $await_1;
|
|
149
|
+
return $return(next(params));
|
|
150
|
+
} catch ($boundEx) {
|
|
151
|
+
return $error($boundEx);
|
|
152
|
+
}
|
|
153
|
+
}, $error);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
var logger = function logger(ctx) {
|
|
160
|
+
return function (next) {
|
|
161
|
+
return function (params) {
|
|
162
|
+
return new Promise(function ($return, $error) {
|
|
163
|
+
var r;
|
|
164
|
+
console.log(ctx.modelName, '- action -start: ', ctx.action.name);
|
|
165
|
+
return Promise.resolve(next(params)).then(function ($await_1) {
|
|
166
|
+
try {
|
|
167
|
+
r = $await_1;
|
|
168
|
+
console.log(ctx.modelName, '- action -end: ', ctx.action.name);
|
|
169
|
+
return $return(r);
|
|
170
|
+
} catch ($boundEx) {
|
|
171
|
+
return $error($boundEx);
|
|
172
|
+
}
|
|
173
|
+
}, $error);
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 发布函数
|
|
181
|
+
* @param ctx
|
|
182
|
+
* @returns
|
|
183
|
+
*/
|
|
184
|
+
var publish = function publish(ctx) {
|
|
185
|
+
return function (next) {
|
|
186
|
+
return function (params) {
|
|
187
|
+
var subscribes = ctx.subscribes;
|
|
188
|
+
subscribes === null || subscribes === void 0 || subscribes.forEach(function (callback) {
|
|
189
|
+
callback();
|
|
190
|
+
});
|
|
191
|
+
return next(params);
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* action返回
|
|
198
|
+
* @param ctx
|
|
199
|
+
* @returns
|
|
200
|
+
*/
|
|
201
|
+
var returnState = function returnState(ctx) {
|
|
202
|
+
return function (_next) {
|
|
203
|
+
return function (_params) {
|
|
204
|
+
return getState(ctx.modelName);
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
var produceState = function produceState(base, recipe) {
|
|
210
|
+
return produce(base, recipe);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
var setter = function setter(ctx) {
|
|
214
|
+
return function (next) {
|
|
215
|
+
return function (params) {
|
|
216
|
+
return new Promise(function ($return, $error) {
|
|
217
|
+
var modelName = ctx.modelName;
|
|
218
|
+
var newState = ctx.newState;
|
|
219
|
+
if (!newState) {
|
|
220
|
+
return $return(getState(modelName));
|
|
221
|
+
}
|
|
222
|
+
if (isFunction(newState)) {
|
|
223
|
+
newState = produceState(getState(modelName), newState);
|
|
224
|
+
}
|
|
225
|
+
GlobalModel.State = produce(GlobalModel.State, function (draft) {
|
|
226
|
+
draft[modelName] = newState;
|
|
227
|
+
});
|
|
228
|
+
return $return(next(params));
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
var tryCatch = function tryCatch() {
|
|
235
|
+
return function (next) {
|
|
236
|
+
return function (params) {
|
|
237
|
+
return new Promise(function ($return, $error) {
|
|
238
|
+
var _next;
|
|
239
|
+
return Promise.resolve((_next = next(params)) === null || _next === void 0 ? void 0 : _next.catch(function (e) {
|
|
240
|
+
return console.log(e);
|
|
241
|
+
})).then($return, $error);
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
var presetMiddleware = [tryCatch, logger, gatter, setter, publish, returnState];
|
|
248
|
+
|
|
249
|
+
function compose() {
|
|
250
|
+
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
251
|
+
funcs[_key] = arguments[_key];
|
|
252
|
+
}
|
|
253
|
+
if (funcs.length === 0) {
|
|
254
|
+
return function (arg) {
|
|
255
|
+
return arg;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (funcs.length === 1) {
|
|
259
|
+
return funcs[0];
|
|
260
|
+
}
|
|
261
|
+
return funcs.reduce(function (a, b) {
|
|
262
|
+
return function () {
|
|
263
|
+
return a(b.apply(void 0, arguments));
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
var rebuildActions = function rebuildActions(actions, modelName) {
|
|
269
|
+
var updateActions = {};
|
|
270
|
+
Object.entries(actions).forEach(function (_ref) {
|
|
271
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
272
|
+
key = _ref2[0],
|
|
273
|
+
action = _ref2[1];
|
|
274
|
+
updateActions[key] = resetAction(action, modelName);
|
|
275
|
+
});
|
|
276
|
+
return updateActions;
|
|
277
|
+
};
|
|
278
|
+
var resetAction = function resetAction(action, modelName) {
|
|
279
|
+
return function (payload) {
|
|
280
|
+
var _getCtx = getCtx(modelName),
|
|
281
|
+
state = _getCtx.state,
|
|
282
|
+
actions = _getCtx.actions,
|
|
283
|
+
subscribes = _getCtx.subscribes;
|
|
284
|
+
var ctx = {
|
|
285
|
+
payload: payload,
|
|
286
|
+
state: state,
|
|
287
|
+
actions: actions,
|
|
288
|
+
action: action,
|
|
289
|
+
subscribes: subscribes,
|
|
290
|
+
modelName: modelName,
|
|
291
|
+
newState: null,
|
|
292
|
+
setterFun: undefined
|
|
293
|
+
};
|
|
294
|
+
var middlewares = presetMiddleware.map(function (middleware) {
|
|
295
|
+
return middleware(ctx);
|
|
296
|
+
});
|
|
297
|
+
var composeFun = compose.apply(void 0, _toConsumableArray(middlewares));
|
|
298
|
+
return composeFun(function () {
|
|
299
|
+
return getState(modelName);
|
|
300
|
+
})();
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
var initModel = function initModel(models) {
|
|
305
|
+
Object.entries(models).forEach(function (_ref) {
|
|
306
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
307
|
+
modelName = _ref2[0],
|
|
308
|
+
model = _ref2[1];
|
|
309
|
+
GlobalModel.__MId++;
|
|
310
|
+
GlobalModel.State = produceState(GlobalModel.State, function (draft) {
|
|
311
|
+
draft[modelName] = model.state;
|
|
312
|
+
});
|
|
313
|
+
GlobalModel.Actions[modelName] = _objectSpread2({}, rebuildActions(model.actions, modelName));
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* 取消订阅 model 的 state 变化
|
|
319
|
+
* @param modelName
|
|
320
|
+
* @param callback
|
|
321
|
+
* @returns
|
|
322
|
+
*/
|
|
323
|
+
var unsubscribe = function unsubscribe(modelName, callback) {
|
|
324
|
+
if (!GlobalModel.Subscribes[modelName]) {
|
|
325
|
+
GlobalModel.Subscribes[modelName] = [];
|
|
326
|
+
}
|
|
327
|
+
GlobalModel.Subscribes[modelName] = GlobalModel.Subscribes[modelName].filter(function (item) {
|
|
328
|
+
return item !== callback;
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* 订阅 model 的 state 变化
|
|
334
|
+
* @param modelName
|
|
335
|
+
* @param callback
|
|
336
|
+
* @returns
|
|
337
|
+
*/
|
|
338
|
+
var subscribe = function subscribe(modelName, callback) {
|
|
339
|
+
if (!GlobalModel.Subscribes[modelName]) {
|
|
340
|
+
GlobalModel.Subscribes[modelName] = [];
|
|
341
|
+
}
|
|
342
|
+
GlobalModel.Subscribes[modelName].push(callback);
|
|
343
|
+
return function () {
|
|
344
|
+
return unsubscribe(modelName, callback);
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Model 类
|
|
350
|
+
*/
|
|
351
|
+
var Model = function Model(models) {
|
|
352
|
+
/** 初始化 */
|
|
353
|
+
initModel(models);
|
|
354
|
+
return {
|
|
355
|
+
getState: getState,
|
|
356
|
+
getActions: getActions,
|
|
357
|
+
subscribe: subscribe,
|
|
358
|
+
unsubscribe: unsubscribe,
|
|
359
|
+
applyMiddleware: applyMiddleware
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
export { Model, gatter, logger, presetMiddleware, publish, returnState, setter, tryCatch };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { TAny, TPlainObject } from '@cclr/lang';
|
|
2
|
+
|
|
3
|
+
type IsOptional<T> = Extract<T, undefined> extends never ? false : true;
|
|
4
|
+
type FirstArg<F> = F extends (arg1: infer A, ...args: any[]) => any ? A : never;
|
|
5
|
+
|
|
6
|
+
type TState<S = TAny> = S;
|
|
7
|
+
|
|
8
|
+
/** action 字典 */
|
|
9
|
+
type TActionMap<S extends TState = TState, PM extends TActionParamsMap = TActionParamsMap> = {
|
|
10
|
+
[ActionName in keyof PM]: TAction<PM[ActionName], S, PM>;
|
|
11
|
+
};
|
|
12
|
+
/** action */
|
|
13
|
+
type TAction<P extends TActionParams = TActionParams, S extends TState = TState, PM extends TActionParamsMap = TActionParamsMap> = (params: P, options: TActionOptions<S, PM>) => TOptionsActionReturn<S>;
|
|
14
|
+
/** actions 入参 */
|
|
15
|
+
type TActionParams = TAny;
|
|
16
|
+
/** actions 入参字典 */
|
|
17
|
+
type TActionParamsMap = TPlainObject;
|
|
18
|
+
/** actions 入参里 options.action 的返回值 */
|
|
19
|
+
type TOptionsActionReturn<S extends TState> = Promise<(p: S) => void> | ((p: S) => void) | Promise<S> | S | Promise<void> | void;
|
|
20
|
+
/** action 的 第二个入参,state 和所有的action */
|
|
21
|
+
type TActionOptions<S extends TState = TState, PM extends TActionParamsMap = TActionParamsMap> = {
|
|
22
|
+
state: S;
|
|
23
|
+
actions: GetConsumerActionsType<TActionMap<S, PM>>;
|
|
24
|
+
};
|
|
25
|
+
type GetConsumerActionsType<A extends TActionMap = TActionMap> = {
|
|
26
|
+
[P in keyof A]-?: IsOptional<Parameters<A[P]>[0]> extends true ? (payload?: Parameters<A[P]>[0], middlewareConfig?: any) => TOptionsActionReturn<ReturnType<A[P]>> : (payload: Parameters<A[P]>[0], middlewareConfig?: any) => TOptionsActionReturn<ReturnType<A[P]>>;
|
|
27
|
+
};
|
|
28
|
+
/************ action 的 api ***************/
|
|
29
|
+
/** 获取action的调用方法 */
|
|
30
|
+
type TActionMapApi<AM extends TActionMap, S extends TState> = {
|
|
31
|
+
[ActionName in keyof AM]: TActionApi<AM[ActionName], S>;
|
|
32
|
+
};
|
|
33
|
+
/** 只保留函数TAction第一个参数,其余全部去掉 */
|
|
34
|
+
type TActionApi<A extends (...args: any[]) => any, S extends TState> = (arg: FirstArg<A>) => Promise<S>;
|
|
35
|
+
|
|
36
|
+
type TSubscribesFun = () => any;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 获取model的api
|
|
40
|
+
*/
|
|
41
|
+
type ModelsApi<MS extends ModelsType> = {
|
|
42
|
+
/** 获取state的值 */
|
|
43
|
+
getState<K extends keyof MS>(params: K): MS[K]['state'];
|
|
44
|
+
/** 获取actions */
|
|
45
|
+
getActions<K extends keyof MS>(params: K): TActionMapApi<MS[K]['actions'], MS[K]['state']>;
|
|
46
|
+
/** 订阅模块更新 */
|
|
47
|
+
subscribe<K extends keyof MS>(params: K, callback: TSubscribesFun): () => void;
|
|
48
|
+
/** 取消订阅 */
|
|
49
|
+
unsubscribe<K extends keyof MS>(params: K, callback: TSubscribesFun): void;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* models的类型
|
|
53
|
+
*/
|
|
54
|
+
type ModelsType<S extends TState = TState, PM extends TPlainObject = TPlainObject> = {
|
|
55
|
+
[modelName: string]: ModelType<S, PM>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* 单个model的类型
|
|
59
|
+
*/
|
|
60
|
+
type ModelType<S extends TState = TState, PM extends TPlainObject = TPlainObject> = {
|
|
61
|
+
state: S;
|
|
62
|
+
actions: TActionMap<S, PM>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Model 类
|
|
67
|
+
*/
|
|
68
|
+
declare const Model: <MS extends ModelsType>(models: MS) => ModelsApi<MS>;
|
|
69
|
+
|
|
70
|
+
/** 中间件上下文 */
|
|
71
|
+
interface IActionCtx {
|
|
72
|
+
/** model的唯一索引 */
|
|
73
|
+
modelName: any;
|
|
74
|
+
/** 数据模型 */
|
|
75
|
+
state: TState;
|
|
76
|
+
/** 数据模型 */
|
|
77
|
+
newState?: ((state: TState) => TState) | TState | null | undefined;
|
|
78
|
+
/** 订阅函数 */
|
|
79
|
+
subscribes: TSubscribesFun[];
|
|
80
|
+
/** 当前action */
|
|
81
|
+
action: TAction;
|
|
82
|
+
/** action的函数 */
|
|
83
|
+
payload: any;
|
|
84
|
+
/** 设置数据模型的函数 */
|
|
85
|
+
setterFun?: (state: TState) => void;
|
|
86
|
+
/** action 字典 */
|
|
87
|
+
actions: {
|
|
88
|
+
[key: string]: TAction;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type TNextReturn<P extends TActionParams = TActionParams, S extends TState = TState> = (params: P) => S;
|
|
93
|
+
type TNextFun<P extends TActionParams = TActionParams, S extends TState = TState> = (next: TNextFun<P, S>) => TNextReturn<P, S>;
|
|
94
|
+
/** 中间件 */
|
|
95
|
+
type TMiddleware<P extends TActionParams = TActionParams, S extends TState = TState, C extends IActionCtx = IActionCtx> = (ctx: C) => TNextFun<P, S>;
|
|
96
|
+
|
|
97
|
+
declare const gatter: TMiddleware;
|
|
98
|
+
|
|
99
|
+
declare const logger: TMiddleware;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 发布函数
|
|
103
|
+
* @param ctx
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
declare const publish: TMiddleware;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* action返回
|
|
110
|
+
* @param ctx
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
declare const returnState: TMiddleware;
|
|
114
|
+
|
|
115
|
+
declare const setter: TMiddleware;
|
|
116
|
+
|
|
117
|
+
declare const tryCatch: () => (next: any) => (params: any) => Promise<any>;
|
|
118
|
+
|
|
119
|
+
declare const presetMiddleware: TMiddleware[];
|
|
120
|
+
|
|
121
|
+
export { Model, type ModelType, type ModelsApi, type ModelsType, type TAction, type TActionMapApi, type TMiddleware, type TSubscribesFun, gatter, logger, presetMiddleware, publish, returnState, setter, tryCatch };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cclr/model",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "前端开发状态管理",
|
|
5
|
+
"author": "cclr <18843152354@163.com>",
|
|
6
|
+
"homepage": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "lib/cjs/index.js",
|
|
9
|
+
"module": "lib/esm/index.js",
|
|
10
|
+
"types": "lib/type/index.d.ts",
|
|
11
|
+
"directories": {
|
|
12
|
+
"lib": "lib",
|
|
13
|
+
"test": "__tests__"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"registry": "https://registry.npmjs.org/"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "vitest",
|
|
25
|
+
"relese": "npm run test && npm publish",
|
|
26
|
+
"build": "ccf build",
|
|
27
|
+
"g:test": "vitest run",
|
|
28
|
+
"g:build": "ccf build"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "f7ad5275ae3c07cbf4597b6a38ba41362a27e4e1",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@cclr/lang": "workspace:*",
|
|
33
|
+
"@cclr/utils": "workspace:*",
|
|
34
|
+
"immer": "^10.1.1"
|
|
35
|
+
}
|
|
36
|
+
}
|