as-model 0.0.1
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.md +21 -0
- package/README.md +413 -0
- package/dist/index.js +1025 -0
- package/esm/index.js +49 -0
- package/esm/key/index.js +73 -0
- package/esm/key/type.js +0 -0
- package/esm/model/index.js +28 -0
- package/esm/model/type.js +0 -0
- package/esm/store/index.js +153 -0
- package/esm/store/instance.js +197 -0
- package/esm/store/type.js +0 -0
- package/esm/tools.js +78 -0
- package/esm/updater/index.js +129 -0
- package/esm/updater/notifier.js +121 -0
- package/esm/updater/tunnel.js +138 -0
- package/esm/updater/type.js +0 -0
- package/esm/validation/index.js +25 -0
- package/index.d.ts +163 -0
- package/package.json +69 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1025 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// node_modules/@swc/helpers/esm/_define_property.js
|
|
4
|
+
function _define_property(obj, key, value) {
|
|
5
|
+
if (key in obj) {
|
|
6
|
+
Object.defineProperty(obj, key, {
|
|
7
|
+
value,
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true
|
|
11
|
+
});
|
|
12
|
+
} else obj[key] = value;
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// node_modules/@swc/helpers/esm/_object_spread.js
|
|
17
|
+
function _object_spread(target) {
|
|
18
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
19
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
20
|
+
var ownKeys2 = Object.keys(source);
|
|
21
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
22
|
+
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
23
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
ownKeys2.forEach(function(key) {
|
|
27
|
+
_define_property(target, key, source[key]);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// node_modules/@swc/helpers/esm/_object_spread_props.js
|
|
34
|
+
function ownKeys(object, enumerableOnly) {
|
|
35
|
+
var keys = Object.keys(object);
|
|
36
|
+
if (Object.getOwnPropertySymbols) {
|
|
37
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
38
|
+
if (enumerableOnly) {
|
|
39
|
+
symbols = symbols.filter(function(sym) {
|
|
40
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
keys.push.apply(keys, symbols);
|
|
44
|
+
}
|
|
45
|
+
return keys;
|
|
46
|
+
}
|
|
47
|
+
function _object_spread_props(target, source) {
|
|
48
|
+
source = source != null ? source : {};
|
|
49
|
+
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
50
|
+
else {
|
|
51
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
52
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return target;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// node_modules/@swc/helpers/esm/_type_of.js
|
|
59
|
+
function _type_of(obj) {
|
|
60
|
+
"@swc/helpers - typeof";
|
|
61
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/validation/index.ts
|
|
65
|
+
var noStateAModelKey = "no-state-a-model-key";
|
|
66
|
+
function createNoStateModel() {
|
|
67
|
+
return function noStateModel(state) {
|
|
68
|
+
return _define_property({}, noStateAModelKey, true);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function isInstanceFromNoStateModel(instance) {
|
|
72
|
+
if (instance == null) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object") {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
var ins = instance;
|
|
79
|
+
return !!ins[noStateAModelKey];
|
|
80
|
+
}
|
|
81
|
+
var validations = {
|
|
82
|
+
isInstanceFromNoStateModel
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// node_modules/@swc/helpers/esm/_array_like_to_array.js
|
|
86
|
+
function _array_like_to_array(arr, len) {
|
|
87
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
88
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
89
|
+
return arr2;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// node_modules/@swc/helpers/esm/_array_without_holes.js
|
|
93
|
+
function _array_without_holes(arr) {
|
|
94
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// node_modules/@swc/helpers/esm/_iterable_to_array.js
|
|
98
|
+
function _iterable_to_array(iter) {
|
|
99
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
|
|
100
|
+
return Array.from(iter);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// node_modules/@swc/helpers/esm/_non_iterable_spread.js
|
|
105
|
+
function _non_iterable_spread() {
|
|
106
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// node_modules/@swc/helpers/esm/_unsupported_iterable_to_array.js
|
|
110
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
111
|
+
if (!o) return;
|
|
112
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
113
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
114
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
115
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
116
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// node_modules/@swc/helpers/esm/_to_consumable_array.js
|
|
120
|
+
function _to_consumable_array(arr) {
|
|
121
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/updater/notifier.ts
|
|
125
|
+
function defaultNotifyImplement(dispatches, action) {
|
|
126
|
+
dispatches.forEach(function(callback) {
|
|
127
|
+
callback(action);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function generateNotifier(updater) {
|
|
131
|
+
function pendAction(value) {
|
|
132
|
+
updater.mutate(function(u) {
|
|
133
|
+
var dispatching = u.dispatching;
|
|
134
|
+
if (!dispatching) {
|
|
135
|
+
var wrap = {
|
|
136
|
+
value
|
|
137
|
+
};
|
|
138
|
+
wrap.tail = wrap;
|
|
139
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
140
|
+
dispatching: wrap
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
var tail = dispatching.tail;
|
|
144
|
+
if (!tail) {
|
|
145
|
+
return u;
|
|
146
|
+
}
|
|
147
|
+
var current = {
|
|
148
|
+
prev: tail,
|
|
149
|
+
value
|
|
150
|
+
};
|
|
151
|
+
tail.next = current;
|
|
152
|
+
dispatching.tail = current;
|
|
153
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
154
|
+
dispatching
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function unshiftAction() {
|
|
159
|
+
return updater.mutate(function(u) {
|
|
160
|
+
var dispatching = updater.dispatching;
|
|
161
|
+
if (!dispatching) {
|
|
162
|
+
return u;
|
|
163
|
+
}
|
|
164
|
+
var next = dispatching.next, tail = dispatching.tail;
|
|
165
|
+
if (tail === dispatching || !next) {
|
|
166
|
+
dispatching.tail = void 0;
|
|
167
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
168
|
+
dispatching: void 0
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
next.prev = void 0;
|
|
172
|
+
var newFirst = next;
|
|
173
|
+
newFirst.tail = tail;
|
|
174
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
175
|
+
dispatching: newFirst
|
|
176
|
+
});
|
|
177
|
+
}).dispatching;
|
|
178
|
+
}
|
|
179
|
+
function consumeTemporaries() {
|
|
180
|
+
var temporaryDispatches = updater.temporaryDispatches;
|
|
181
|
+
updater.mutate(function(u) {
|
|
182
|
+
return u.temporaryDispatches.length ? _object_spread_props(_object_spread({}, u), {
|
|
183
|
+
dispatches: _to_consumable_array(u.dispatches).concat(_to_consumable_array(u.temporaryDispatches)),
|
|
184
|
+
temporaryDispatches: []
|
|
185
|
+
}) : u;
|
|
186
|
+
});
|
|
187
|
+
var initializedAction = {
|
|
188
|
+
state: updater.state,
|
|
189
|
+
prevState: updater.state,
|
|
190
|
+
instance: updater.instance,
|
|
191
|
+
prevInstance: updater.instance,
|
|
192
|
+
type: null,
|
|
193
|
+
method: null
|
|
194
|
+
};
|
|
195
|
+
temporaryDispatches.forEach(function(call) {
|
|
196
|
+
call(initializedAction);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
var config2 = updater.config;
|
|
200
|
+
return function notify(action) {
|
|
201
|
+
if (action == null) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
var dispatching = updater.dispatching;
|
|
205
|
+
pendAction(action);
|
|
206
|
+
if (dispatching) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
while (updater.dispatching) {
|
|
210
|
+
var wrap = updater.dispatching;
|
|
211
|
+
if (wrap) {
|
|
212
|
+
var dispatches = updater.dispatches;
|
|
213
|
+
var dispatchCallbacks = _to_consumable_array(dispatches);
|
|
214
|
+
try {
|
|
215
|
+
if (typeof config2.batchNotify === "function" && dispatchCallbacks.length) {
|
|
216
|
+
config2.batchNotify(dispatchCallbacks, wrap.value);
|
|
217
|
+
} else {
|
|
218
|
+
defaultNotifyImplement(dispatchCallbacks, wrap.value);
|
|
219
|
+
}
|
|
220
|
+
} catch (e) {
|
|
221
|
+
updater.mutate(function(u) {
|
|
222
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
223
|
+
dispatching: void 0
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
throw e;
|
|
227
|
+
}
|
|
228
|
+
unshiftAction();
|
|
229
|
+
} else {
|
|
230
|
+
updater.mutate(function(u) {
|
|
231
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
232
|
+
dispatching: void 0
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
consumeTemporaries();
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/tools.ts
|
|
242
|
+
function getDescriptors(target, receiver, ownOrPrototype, handler) {
|
|
243
|
+
var it = Object.keys(ownOrPrototype);
|
|
244
|
+
var result = {};
|
|
245
|
+
it.forEach(function(key) {
|
|
246
|
+
result[key] = {
|
|
247
|
+
get: function() {
|
|
248
|
+
if (!handler.get) {
|
|
249
|
+
return target[key];
|
|
250
|
+
}
|
|
251
|
+
return handler.get(target, key, receiver);
|
|
252
|
+
},
|
|
253
|
+
set: function(v) {
|
|
254
|
+
if (!handler.set) {
|
|
255
|
+
target[key] = v;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
var valid = handler.set(target, key, v, receiver);
|
|
259
|
+
if (!valid) {
|
|
260
|
+
throw new Error("".concat(key, " in proxy target is not mutable"));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
var createSimpleProxy = function(target, handler) {
|
|
268
|
+
var proxy = {};
|
|
269
|
+
var own = getDescriptors(target, proxy, target, handler);
|
|
270
|
+
var prototype = getDescriptors(target, proxy, Object.getPrototypeOf(target), handler);
|
|
271
|
+
Object.defineProperties(proxy, _object_spread({}, prototype, own));
|
|
272
|
+
return proxy;
|
|
273
|
+
};
|
|
274
|
+
var createProxy = function(target, handler) {
|
|
275
|
+
if (typeof Proxy !== "function") {
|
|
276
|
+
return createSimpleProxy(target, handler);
|
|
277
|
+
}
|
|
278
|
+
return new Proxy(target, handler);
|
|
279
|
+
};
|
|
280
|
+
function isObject(data) {
|
|
281
|
+
return data && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object";
|
|
282
|
+
}
|
|
283
|
+
function shallowEqual(prev, current) {
|
|
284
|
+
if (Object.is(prev, current)) {
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
if (!isObject(prev) || !isObject(current)) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
var prevKeys = Object.keys(prev);
|
|
291
|
+
var currentKeys = Object.keys(current);
|
|
292
|
+
if (prevKeys.length !== currentKeys.length) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
var pre = prev;
|
|
296
|
+
var curr = current;
|
|
297
|
+
var hasDiffKey = prevKeys.some(function(key) {
|
|
298
|
+
return !Object.prototype.hasOwnProperty.call(curr, key);
|
|
299
|
+
});
|
|
300
|
+
if (hasDiffKey) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
var hasDiffValue = currentKeys.some(function(key) {
|
|
304
|
+
var currentValue = curr[key];
|
|
305
|
+
var prevValue = pre[key];
|
|
306
|
+
return !Object.is(currentValue, prevValue);
|
|
307
|
+
});
|
|
308
|
+
return !hasDiffValue;
|
|
309
|
+
}
|
|
310
|
+
function noop() {
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/updater/tunnel.ts
|
|
314
|
+
function createUnInitializedUpdater() {
|
|
315
|
+
return {
|
|
316
|
+
notify: function(a) {
|
|
317
|
+
},
|
|
318
|
+
createTunnel: function(dispatcher) {
|
|
319
|
+
return {
|
|
320
|
+
connect: noop,
|
|
321
|
+
disconnect: noop
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
function destroy(updater) {
|
|
327
|
+
function destroyDispatching() {
|
|
328
|
+
updater.mutate(function(u) {
|
|
329
|
+
var dispatching = u.dispatching;
|
|
330
|
+
if (!dispatching) {
|
|
331
|
+
return u;
|
|
332
|
+
}
|
|
333
|
+
var wrapper = dispatching;
|
|
334
|
+
while (wrapper) {
|
|
335
|
+
var next = wrapper.next;
|
|
336
|
+
wrapper.next = void 0;
|
|
337
|
+
wrapper.prev = void 0;
|
|
338
|
+
if (next) {
|
|
339
|
+
next.prev = void 0;
|
|
340
|
+
}
|
|
341
|
+
wrapper = next;
|
|
342
|
+
}
|
|
343
|
+
dispatching.tail = void 0;
|
|
344
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
345
|
+
dispatching: void 0,
|
|
346
|
+
initialized: false
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
updater.mutate(function(u, effect) {
|
|
351
|
+
var destroyed = createUnInitializedUpdater();
|
|
352
|
+
effect(function() {
|
|
353
|
+
destroyDispatching();
|
|
354
|
+
});
|
|
355
|
+
return _object_spread_props(_object_spread({}, u, destroyed), {
|
|
356
|
+
sidePayload: void 0,
|
|
357
|
+
isDestroyed: true
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
function generateTunnelCreator(updater) {
|
|
362
|
+
function subscribe(dispatchFn) {
|
|
363
|
+
var dispatches = updater.dispatches, temporaryDispatches = updater.temporaryDispatches, isControlled = updater.controlled;
|
|
364
|
+
var copied = _to_consumable_array(dispatches).concat(_to_consumable_array(temporaryDispatches));
|
|
365
|
+
var exist = copied.indexOf(dispatchFn) >= 0;
|
|
366
|
+
if (exist) {
|
|
367
|
+
return updater.mutate(function(u) {
|
|
368
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
369
|
+
isDestroyed: false
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (isControlled) {
|
|
374
|
+
return updater.mutate(function(u) {
|
|
375
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
376
|
+
dispatches: [
|
|
377
|
+
dispatchFn
|
|
378
|
+
],
|
|
379
|
+
isDestroyed: false
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return updater.mutate(function(u, effect) {
|
|
384
|
+
var tds = u.temporaryDispatches, ds = u.dispatches;
|
|
385
|
+
var nextTds = _to_consumable_array(tds).concat([
|
|
386
|
+
dispatchFn
|
|
387
|
+
]);
|
|
388
|
+
if (u.dispatching) {
|
|
389
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
390
|
+
temporaryDispatches: nextTds,
|
|
391
|
+
isDestroyed: false
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
effect(function(up) {
|
|
395
|
+
var initializedAction = {
|
|
396
|
+
state: up.state,
|
|
397
|
+
prevState: up.state,
|
|
398
|
+
instance: up.instance,
|
|
399
|
+
prevInstance: up.instance,
|
|
400
|
+
type: null,
|
|
401
|
+
method: null
|
|
402
|
+
};
|
|
403
|
+
nextTds.forEach(function(td) {
|
|
404
|
+
td(initializedAction);
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
408
|
+
temporaryDispatches: [],
|
|
409
|
+
dispatches: _to_consumable_array(ds).concat(_to_consumable_array(nextTds)),
|
|
410
|
+
isDestroyed: false
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
return function tunnel(dispatcher) {
|
|
415
|
+
function disconnect() {
|
|
416
|
+
updater.mutate(function(u) {
|
|
417
|
+
var ds = u.dispatches, tds = u.temporaryDispatches;
|
|
418
|
+
var nextDs = ds.filter(function(d) {
|
|
419
|
+
return d !== dispatcher;
|
|
420
|
+
});
|
|
421
|
+
var nextTds = tds.filter(function(d) {
|
|
422
|
+
return d !== dispatcher;
|
|
423
|
+
});
|
|
424
|
+
if (ds.length === nextDs.length && tds.length === nextTds.length) {
|
|
425
|
+
return u;
|
|
426
|
+
}
|
|
427
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
428
|
+
dispatches: nextDs,
|
|
429
|
+
temporaryDispatches: nextTds
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
connect: function connect() {
|
|
435
|
+
subscribe(dispatcher);
|
|
436
|
+
},
|
|
437
|
+
disconnect: function disconnect1() {
|
|
438
|
+
disconnect();
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// src/updater/index.ts
|
|
445
|
+
function createInitializedUpdater(updater) {
|
|
446
|
+
var createTunnel = generateTunnelCreator(updater);
|
|
447
|
+
return {
|
|
448
|
+
notify: generateNotifier(updater),
|
|
449
|
+
createTunnel
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
function createUpdateFn(updater) {
|
|
453
|
+
return function update() {
|
|
454
|
+
var args = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
455
|
+
updater.mutate(function(u, effect) {
|
|
456
|
+
var _args_model;
|
|
457
|
+
var model2 = (_args_model = args.model) !== null && _args_model !== void 0 ? _args_model : u.model;
|
|
458
|
+
var initialState = "initialState" in args ? args.initialState : u.state;
|
|
459
|
+
var state = "state" in args ? args.state : u.state;
|
|
460
|
+
if (u.controlled) {
|
|
461
|
+
var instance = model2(state);
|
|
462
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
463
|
+
state,
|
|
464
|
+
instance,
|
|
465
|
+
model: model2
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
if (u.isDestroyed) {
|
|
469
|
+
return u;
|
|
470
|
+
}
|
|
471
|
+
if (!u.initialized && !("initialState" in args)) {
|
|
472
|
+
throw new Error("Should update initialState first.");
|
|
473
|
+
}
|
|
474
|
+
if (!u.initialized) {
|
|
475
|
+
var instance1 = model2(initialState);
|
|
476
|
+
var initializedUpdater = createInitializedUpdater(u);
|
|
477
|
+
return _object_spread(_object_spread_props(_object_spread({}, u), {
|
|
478
|
+
model: model2,
|
|
479
|
+
state: initialState,
|
|
480
|
+
instance: instance1,
|
|
481
|
+
initialized: true
|
|
482
|
+
}), initializedUpdater);
|
|
483
|
+
}
|
|
484
|
+
if (Object.is(u.model, model2) && Object.is(u.state, state)) {
|
|
485
|
+
return u;
|
|
486
|
+
}
|
|
487
|
+
var instance2 = model2(state);
|
|
488
|
+
effect(function(up) {
|
|
489
|
+
up.notify({
|
|
490
|
+
type: null,
|
|
491
|
+
method: null,
|
|
492
|
+
prevInstance: u.instance,
|
|
493
|
+
instance: instance2,
|
|
494
|
+
prevState: u.state,
|
|
495
|
+
state
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
return _object_spread_props(_object_spread({}, u), {
|
|
499
|
+
state,
|
|
500
|
+
model: model2,
|
|
501
|
+
instance: instance2,
|
|
502
|
+
initialized: true
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
var lazyModel = createNoStateModel();
|
|
508
|
+
function createUpdater(model2) {
|
|
509
|
+
var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
510
|
+
var hasDefaultState = "state" in config2;
|
|
511
|
+
var controlled = config2.controlled, defaultState = config2.state;
|
|
512
|
+
var defaultInstance = hasDefaultState ? model2(defaultState) : lazyModel(void 0);
|
|
513
|
+
var unInitializedUpdater = createUnInitializedUpdater();
|
|
514
|
+
var updater = _object_spread({
|
|
515
|
+
sidePayload: void 0,
|
|
516
|
+
version: 0,
|
|
517
|
+
isDestroyed: false,
|
|
518
|
+
model: model2,
|
|
519
|
+
instance: defaultInstance,
|
|
520
|
+
dispatch: null,
|
|
521
|
+
dispatches: [],
|
|
522
|
+
temporaryDispatches: [],
|
|
523
|
+
cacheMethods: {},
|
|
524
|
+
cacheFields: {},
|
|
525
|
+
state: defaultState,
|
|
526
|
+
initialized: hasDefaultState,
|
|
527
|
+
controlled: !!controlled,
|
|
528
|
+
isSubscribing: false,
|
|
529
|
+
config: config2,
|
|
530
|
+
payload: function payload(setter) {
|
|
531
|
+
if (typeof setter === "function") {
|
|
532
|
+
updater.sidePayload = setter(updater.sidePayload);
|
|
533
|
+
}
|
|
534
|
+
return updater.sidePayload;
|
|
535
|
+
},
|
|
536
|
+
mutate: function mutate(callback) {
|
|
537
|
+
var effects = [];
|
|
538
|
+
var runEffects = function runEffects2(u) {
|
|
539
|
+
effects.forEach(function(e) {
|
|
540
|
+
return e(u);
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
var result = callback(updater, function(effectFn) {
|
|
544
|
+
return effects.push(effectFn);
|
|
545
|
+
});
|
|
546
|
+
if (updater === result) {
|
|
547
|
+
runEffects(result);
|
|
548
|
+
return updater;
|
|
549
|
+
}
|
|
550
|
+
Object.assign(updater, result);
|
|
551
|
+
runEffects(updater);
|
|
552
|
+
return updater;
|
|
553
|
+
},
|
|
554
|
+
update: function(args) {
|
|
555
|
+
},
|
|
556
|
+
destroy: function destroy1() {
|
|
557
|
+
destroy(updater);
|
|
558
|
+
}
|
|
559
|
+
}, unInitializedUpdater);
|
|
560
|
+
var initialized = createInitializedUpdater(updater);
|
|
561
|
+
Object.assign(updater, initialized, {
|
|
562
|
+
update: createUpdateFn(updater)
|
|
563
|
+
});
|
|
564
|
+
return updater;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/store/instance.ts
|
|
568
|
+
var cacheIdentify = {
|
|
569
|
+
field: function field(d) {
|
|
570
|
+
if (!d) {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
var f = d;
|
|
574
|
+
return f.identifier === cacheIdentify.field;
|
|
575
|
+
},
|
|
576
|
+
method: function method(d) {
|
|
577
|
+
if (typeof d !== "function") {
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
var m = d;
|
|
581
|
+
return m.identifier === cacheIdentify.method;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
function createField(callback, deps) {
|
|
585
|
+
var currentDeps = function computeDeps() {
|
|
586
|
+
if (deps == null) {
|
|
587
|
+
return deps;
|
|
588
|
+
}
|
|
589
|
+
if (deps.some(function(d) {
|
|
590
|
+
return cacheIdentify.field(d) && d.deps == null;
|
|
591
|
+
})) {
|
|
592
|
+
return void 0;
|
|
593
|
+
}
|
|
594
|
+
return deps.flatMap(function(d) {
|
|
595
|
+
if (cacheIdentify.field(d)) {
|
|
596
|
+
return d.deps;
|
|
597
|
+
}
|
|
598
|
+
return d;
|
|
599
|
+
});
|
|
600
|
+
}();
|
|
601
|
+
var value = callback();
|
|
602
|
+
return {
|
|
603
|
+
callback,
|
|
604
|
+
deps: currentDeps,
|
|
605
|
+
identifier: cacheIdentify.field,
|
|
606
|
+
value,
|
|
607
|
+
get: function get() {
|
|
608
|
+
return value;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function createMethod(method2) {
|
|
613
|
+
var replace = function replace2() {
|
|
614
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
615
|
+
args[_key] = arguments[_key];
|
|
616
|
+
}
|
|
617
|
+
return method2.apply(void 0, _to_consumable_array(args));
|
|
618
|
+
};
|
|
619
|
+
Object.assign(replace, method2());
|
|
620
|
+
replace.identifier = cacheIdentify.method;
|
|
621
|
+
return replace;
|
|
622
|
+
}
|
|
623
|
+
function wrapToActionMethod(updater, methodName) {
|
|
624
|
+
var cacheMethods = updater.cacheMethods;
|
|
625
|
+
var cachedMethod = cacheMethods[methodName];
|
|
626
|
+
if (typeof cachedMethod === "function") {
|
|
627
|
+
return cachedMethod;
|
|
628
|
+
}
|
|
629
|
+
var actionMethod = function actionMethod2() {
|
|
630
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
631
|
+
args[_key] = arguments[_key];
|
|
632
|
+
}
|
|
633
|
+
var instance = updater.instance, isDestroyed = updater.isDestroyed, controlled = updater.controlled, model2 = updater.model;
|
|
634
|
+
var method2 = instance[methodName];
|
|
635
|
+
if (typeof method2 !== "function") {
|
|
636
|
+
throw new Error("Can not change methods in runtime.");
|
|
637
|
+
}
|
|
638
|
+
if (cacheIdentify.method(method2)) {
|
|
639
|
+
return method2.apply(void 0, _to_consumable_array(args));
|
|
640
|
+
}
|
|
641
|
+
var state = method2.apply(void 0, _to_consumable_array(args));
|
|
642
|
+
if (isDestroyed) {
|
|
643
|
+
return state;
|
|
644
|
+
}
|
|
645
|
+
var action = {
|
|
646
|
+
type: methodName,
|
|
647
|
+
state,
|
|
648
|
+
prevState: updater.state,
|
|
649
|
+
instance: updater.instance,
|
|
650
|
+
prevInstance: updater.instance,
|
|
651
|
+
method: actionMethod2
|
|
652
|
+
};
|
|
653
|
+
if (controlled) {
|
|
654
|
+
updater.notify(action);
|
|
655
|
+
return state;
|
|
656
|
+
}
|
|
657
|
+
var prevState = updater.state;
|
|
658
|
+
var prevInstance = updater.instance;
|
|
659
|
+
var newestInstance = model2(state);
|
|
660
|
+
updater.mutate(function(up, effect) {
|
|
661
|
+
effect(function(u) {
|
|
662
|
+
u.notify({
|
|
663
|
+
type: methodName,
|
|
664
|
+
state,
|
|
665
|
+
prevState,
|
|
666
|
+
instance: newestInstance,
|
|
667
|
+
prevInstance,
|
|
668
|
+
method: actionMethod2
|
|
669
|
+
});
|
|
670
|
+
});
|
|
671
|
+
return _object_spread_props(_object_spread({}, up), {
|
|
672
|
+
instance: newestInstance,
|
|
673
|
+
state,
|
|
674
|
+
version: up.version + 1
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
return state;
|
|
678
|
+
};
|
|
679
|
+
cacheMethods[methodName] = actionMethod;
|
|
680
|
+
return actionMethod;
|
|
681
|
+
}
|
|
682
|
+
function wrapToField(updater, propertyName, value, onGot) {
|
|
683
|
+
var cacheFields = updater.cacheFields;
|
|
684
|
+
if (!cacheIdentify.field(value)) {
|
|
685
|
+
if (onGot) {
|
|
686
|
+
onGot(propertyName, value);
|
|
687
|
+
}
|
|
688
|
+
return value;
|
|
689
|
+
}
|
|
690
|
+
var field2 = value;
|
|
691
|
+
var cachedField = cacheFields[propertyName];
|
|
692
|
+
if (cachedField) {
|
|
693
|
+
return cachedField.getter;
|
|
694
|
+
}
|
|
695
|
+
var getter = {
|
|
696
|
+
get: function get() {
|
|
697
|
+
var currentField = updater.instance[propertyName];
|
|
698
|
+
if (!cacheIdentify.field(currentField)) {
|
|
699
|
+
throw new Error("Field should always be field.");
|
|
700
|
+
}
|
|
701
|
+
var current = currentField.get();
|
|
702
|
+
var fieldInCache = updater.cacheFields[propertyName];
|
|
703
|
+
if (!currentField.deps || fieldInCache == null) {
|
|
704
|
+
cacheFields[propertyName] = {
|
|
705
|
+
getter,
|
|
706
|
+
value: current,
|
|
707
|
+
deps: currentField.deps
|
|
708
|
+
};
|
|
709
|
+
return current;
|
|
710
|
+
}
|
|
711
|
+
if (shallowEqual(currentField.deps, fieldInCache.deps)) {
|
|
712
|
+
return fieldInCache.value;
|
|
713
|
+
}
|
|
714
|
+
cacheFields[propertyName] = {
|
|
715
|
+
getter,
|
|
716
|
+
value: current,
|
|
717
|
+
deps: currentField.deps
|
|
718
|
+
};
|
|
719
|
+
return current;
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
cacheFields[propertyName] = {
|
|
723
|
+
getter,
|
|
724
|
+
value: field2.value,
|
|
725
|
+
deps: field2.deps
|
|
726
|
+
};
|
|
727
|
+
return getter;
|
|
728
|
+
}
|
|
729
|
+
function extractInstance(updater, onGet) {
|
|
730
|
+
var instance = updater.instance;
|
|
731
|
+
if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object" || !instance) {
|
|
732
|
+
throw new Error("The instance should be an object or array.");
|
|
733
|
+
}
|
|
734
|
+
var properties = Object.getOwnPropertyNames(instance);
|
|
735
|
+
var handleGetter = function handleGetter2(key, value) {
|
|
736
|
+
if (!onGet) {
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
onGet(key, value);
|
|
740
|
+
};
|
|
741
|
+
return createProxy(instance, {
|
|
742
|
+
get: function get(target, p, receiver) {
|
|
743
|
+
var value = target[p];
|
|
744
|
+
if (typeof value === "function" && properties.indexOf(p) >= 0) {
|
|
745
|
+
var actionMethod = wrapToActionMethod(updater, p);
|
|
746
|
+
Object.assign(actionMethod, value);
|
|
747
|
+
handleGetter(p, actionMethod);
|
|
748
|
+
return actionMethod;
|
|
749
|
+
}
|
|
750
|
+
return wrapToField(updater, p, value, handleGetter);
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// src/store/index.ts
|
|
756
|
+
function modelKeyIdentifier() {
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
function isModelKey(data) {
|
|
760
|
+
if (!data) {
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
return data.modelKeyIdentifier === modelKeyIdentifier;
|
|
764
|
+
}
|
|
765
|
+
function createPrimaryKey(modelFn, defaultState) {
|
|
766
|
+
var model2 = isModelKey(modelFn) ? modelFn.source : modelFn;
|
|
767
|
+
var wrapModel = function wrapModel2(state) {
|
|
768
|
+
return model2(state);
|
|
769
|
+
};
|
|
770
|
+
wrapModel.source = model2;
|
|
771
|
+
wrapModel.modelKeyIdentifier = modelKeyIdentifier;
|
|
772
|
+
if (arguments.length > 1) {
|
|
773
|
+
wrapModel.defaultState = defaultState;
|
|
774
|
+
}
|
|
775
|
+
return wrapModel;
|
|
776
|
+
}
|
|
777
|
+
function createStore(modelLike) {
|
|
778
|
+
var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
779
|
+
var model2 = isModelKey(modelLike) ? modelLike.source : modelLike;
|
|
780
|
+
var modelKey = isModelKey(modelLike) ? modelLike : void 0;
|
|
781
|
+
var conf = function computeConfig() {
|
|
782
|
+
var hasConfigState = "state" in config2;
|
|
783
|
+
var hasKeyState = !!modelKey && "defaultState" in modelKey;
|
|
784
|
+
if (hasConfigState) {
|
|
785
|
+
return config2;
|
|
786
|
+
}
|
|
787
|
+
if (hasKeyState) {
|
|
788
|
+
return _object_spread_props(_object_spread({}, config2), {
|
|
789
|
+
state: modelKey === null || modelKey === void 0 ? void 0 : modelKey.defaultState
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
return config2;
|
|
793
|
+
}();
|
|
794
|
+
var updater = createUpdater(model2, conf);
|
|
795
|
+
var store = {
|
|
796
|
+
key: modelKey !== null && modelKey !== void 0 ? modelKey : "state" in config2 ? createPrimaryKey(model2, config2.state) : createPrimaryKey(model2),
|
|
797
|
+
subscribe: function subscribe(dispatcher) {
|
|
798
|
+
var _updater_createTunnel = updater.createTunnel(dispatcher), connect = _updater_createTunnel.connect, disconnect = _updater_createTunnel.disconnect;
|
|
799
|
+
connect();
|
|
800
|
+
return disconnect;
|
|
801
|
+
},
|
|
802
|
+
getInstance: function getInstance() {
|
|
803
|
+
return extractInstance(updater);
|
|
804
|
+
},
|
|
805
|
+
update: function update(args) {
|
|
806
|
+
updater.update(args);
|
|
807
|
+
},
|
|
808
|
+
destroy: function destroy2() {
|
|
809
|
+
updater.destroy();
|
|
810
|
+
},
|
|
811
|
+
payload: function payload(callback) {
|
|
812
|
+
return updater.payload(callback);
|
|
813
|
+
},
|
|
814
|
+
isDestroyed: function isDestroyed() {
|
|
815
|
+
return updater.isDestroyed;
|
|
816
|
+
},
|
|
817
|
+
updater
|
|
818
|
+
};
|
|
819
|
+
return store;
|
|
820
|
+
}
|
|
821
|
+
function createSignal(store) {
|
|
822
|
+
var signalStore = {
|
|
823
|
+
collection: null,
|
|
824
|
+
started: false,
|
|
825
|
+
enabled: false
|
|
826
|
+
};
|
|
827
|
+
var middleWare = function(dispatcher) {
|
|
828
|
+
return function(action) {
|
|
829
|
+
if (!signalStore.enabled) {
|
|
830
|
+
dispatcher(action);
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
var collection = signalStore.collection;
|
|
834
|
+
if (collection == null) {
|
|
835
|
+
dispatcher(action);
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
var current = extractInstance(store.updater);
|
|
839
|
+
var keys = Object.keys(collection);
|
|
840
|
+
var currentCollectionEntries = keys.map(function(key) {
|
|
841
|
+
var field2 = current[key];
|
|
842
|
+
if (cacheIdentify.field(field2)) {
|
|
843
|
+
return [
|
|
844
|
+
key,
|
|
845
|
+
field2.get()
|
|
846
|
+
];
|
|
847
|
+
}
|
|
848
|
+
return [
|
|
849
|
+
key,
|
|
850
|
+
field2
|
|
851
|
+
];
|
|
852
|
+
});
|
|
853
|
+
var currentCollection = Object.fromEntries(currentCollectionEntries);
|
|
854
|
+
if (!shallowEqual(collection, currentCollection)) {
|
|
855
|
+
dispatcher(action);
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
};
|
|
859
|
+
return {
|
|
860
|
+
key: store.key,
|
|
861
|
+
subscribe: function subscribe(dispatcher) {
|
|
862
|
+
return store.subscribe(middleWare(dispatcher));
|
|
863
|
+
},
|
|
864
|
+
getSignal: function getSignal() {
|
|
865
|
+
var collectUsedFields = function collectUsedFields2(key, val) {
|
|
866
|
+
if (!signalStore.started) {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
signalStore.collection = signalStore.collection || {};
|
|
870
|
+
signalStore.collection[key] = val;
|
|
871
|
+
};
|
|
872
|
+
var signal = function signal2() {
|
|
873
|
+
return extractInstance(store.updater, collectUsedFields);
|
|
874
|
+
};
|
|
875
|
+
signal.startStatistics = function startStatistics() {
|
|
876
|
+
signalStore.started = true;
|
|
877
|
+
};
|
|
878
|
+
signal.stopStatistics = function stopStatistics() {
|
|
879
|
+
signalStore.started = false;
|
|
880
|
+
};
|
|
881
|
+
signal.subscribe = function subscribe(dispatchCallback) {
|
|
882
|
+
return store.subscribe(dispatchCallback);
|
|
883
|
+
};
|
|
884
|
+
signal.payload = function payload(callback) {
|
|
885
|
+
return store.payload(callback);
|
|
886
|
+
};
|
|
887
|
+
signalStore.enabled = true;
|
|
888
|
+
signalStore.started = true;
|
|
889
|
+
return signal;
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
var createField2 = createField;
|
|
894
|
+
var createMethod2 = createMethod;
|
|
895
|
+
|
|
896
|
+
// src/key/index.ts
|
|
897
|
+
function createKey(model2) {
|
|
898
|
+
var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
899
|
+
var hasDefaultState = "state" in config2;
|
|
900
|
+
var wrapModel = hasDefaultState ? createPrimaryKey(model2, config2.state) : createPrimaryKey(model2);
|
|
901
|
+
wrapModel.createStore = function createKeyStore() {
|
|
902
|
+
var storeConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
903
|
+
return createStore(wrapModel, _object_spread({}, config2, storeConfig));
|
|
904
|
+
};
|
|
905
|
+
return wrapModel;
|
|
906
|
+
}
|
|
907
|
+
createKey.isModelKey = isModelKey;
|
|
908
|
+
function createStores(modelKeys) {
|
|
909
|
+
var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
910
|
+
var state = {
|
|
911
|
+
destroyed: false
|
|
912
|
+
};
|
|
913
|
+
var storeUnits = modelKeys.map(function(modelKey) {
|
|
914
|
+
if (typeof modelKey === "function") {
|
|
915
|
+
return modelKey.createStore();
|
|
916
|
+
}
|
|
917
|
+
var k = modelKey.key;
|
|
918
|
+
return createStore(k, "defaultState" in k ? _object_spread_props(_object_spread({}, config2), {
|
|
919
|
+
state: k.defaultState
|
|
920
|
+
}) : config2);
|
|
921
|
+
});
|
|
922
|
+
return {
|
|
923
|
+
find: function find(key) {
|
|
924
|
+
var found = storeUnits.find(function(c) {
|
|
925
|
+
if (typeof key === "function") {
|
|
926
|
+
return c.key === key;
|
|
927
|
+
}
|
|
928
|
+
return c.key === key.key;
|
|
929
|
+
});
|
|
930
|
+
if (!found) {
|
|
931
|
+
return null;
|
|
932
|
+
}
|
|
933
|
+
return found;
|
|
934
|
+
},
|
|
935
|
+
update: function update() {
|
|
936
|
+
for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
937
|
+
keys[_key] = arguments[_key];
|
|
938
|
+
}
|
|
939
|
+
if (state.destroyed) {
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
storeUnits.forEach(function(un, i) {
|
|
943
|
+
var key = keys[i];
|
|
944
|
+
if (!key) {
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
Object.assign(un, {
|
|
948
|
+
key
|
|
949
|
+
});
|
|
950
|
+
un.update({
|
|
951
|
+
model: typeof key === "function" ? key.source : key.key.source
|
|
952
|
+
});
|
|
953
|
+
});
|
|
954
|
+
},
|
|
955
|
+
destroy: function destroy2() {
|
|
956
|
+
storeUnits.forEach(function(unit) {
|
|
957
|
+
unit.destroy();
|
|
958
|
+
});
|
|
959
|
+
state.destroyed = true;
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// src/model/index.ts
|
|
965
|
+
function configModel(config2) {
|
|
966
|
+
var model2 = function model3(modelFn) {
|
|
967
|
+
var modelWrapper = function modelWrapper2(state) {
|
|
968
|
+
return modelFn(state);
|
|
969
|
+
};
|
|
970
|
+
modelWrapper.createKey = function createModelKey(state) {
|
|
971
|
+
return createKey(modelWrapper, arguments.length ? _object_spread_props(_object_spread({}, config2), {
|
|
972
|
+
state
|
|
973
|
+
}) : config2);
|
|
974
|
+
};
|
|
975
|
+
modelWrapper.createStore = function createModelStore(state) {
|
|
976
|
+
return createStore(modelWrapper, arguments.length ? _object_spread_props(_object_spread({}, config2), {
|
|
977
|
+
state
|
|
978
|
+
}) : config2);
|
|
979
|
+
};
|
|
980
|
+
return modelWrapper;
|
|
981
|
+
};
|
|
982
|
+
model2.createField = createField2;
|
|
983
|
+
model2.createMethod = createMethod2;
|
|
984
|
+
return model2;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// src/index.ts
|
|
988
|
+
function config() {
|
|
989
|
+
var configuration = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
990
|
+
var createStore3 = function createStore4(modelLike, state) {
|
|
991
|
+
return createStore(modelLike, arguments.length > 1 ? _object_spread_props(_object_spread({}, configuration), {
|
|
992
|
+
state
|
|
993
|
+
}) : configuration);
|
|
994
|
+
};
|
|
995
|
+
var createKey3 = function createKey4(model3, state) {
|
|
996
|
+
var isKeySetState = arguments.length > 1;
|
|
997
|
+
var key = createKey(model3, isKeySetState ? _object_spread_props(_object_spread({}, configuration), {
|
|
998
|
+
state
|
|
999
|
+
}) : configuration);
|
|
1000
|
+
key.createStore = function createKeyStore(s) {
|
|
1001
|
+
return arguments.length > 0 ? createStore3(key, s) : createStore3(key);
|
|
1002
|
+
};
|
|
1003
|
+
return key;
|
|
1004
|
+
};
|
|
1005
|
+
createKey3.isModelKey = createKey.isModelKey;
|
|
1006
|
+
var createStores3 = function createStores4() {
|
|
1007
|
+
for (var _len = arguments.length, modelKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1008
|
+
modelKeys[_key] = arguments[_key];
|
|
1009
|
+
}
|
|
1010
|
+
return createStores(modelKeys, configuration);
|
|
1011
|
+
};
|
|
1012
|
+
var model2 = configModel(configuration);
|
|
1013
|
+
return {
|
|
1014
|
+
createStore: createStore3,
|
|
1015
|
+
createKey: createKey3,
|
|
1016
|
+
createStores: createStores3,
|
|
1017
|
+
model: model2
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
var _config = config();
|
|
1021
|
+
var createStore2 = _config.createStore;
|
|
1022
|
+
var createKey2 = _config.createKey;
|
|
1023
|
+
var createStores2 = _config.createStores;
|
|
1024
|
+
var model = _config.model;
|
|
1025
|
+
})();
|