as-model 0.2.3 → 0.2.4

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.
Files changed (3) hide show
  1. package/dist/index.js +1313 -1282
  2. package/index.d.ts +325 -325
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,973 +1,823 @@
1
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;
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 });
14
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
19
 
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
- }
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ config: () => config,
24
+ createKey: () => createKey2,
25
+ createSelector: () => createSelector,
26
+ createSignal: () => createSignal,
27
+ createStore: () => createStore2,
28
+ createStores: () => createStores2,
29
+ model: () => model,
30
+ shallowEqual: () => shallowEqual,
31
+ validations: () => validations
32
+ });
33
+ module.exports = __toCommonJS(index_exports);
32
34
 
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);
35
+ // node_modules/@swc/helpers/esm/_define_property.js
36
+ function _define_property(obj, key, value) {
37
+ if (key in obj) {
38
+ Object.defineProperty(obj, key, {
39
+ value,
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true
43
+ });
44
+ } else obj[key] = value;
45
+ return obj;
46
+ }
47
+
48
+ // node_modules/@swc/helpers/esm/_object_spread.js
49
+ function _object_spread(target) {
50
+ for (var i = 1; i < arguments.length; i++) {
51
+ var source = arguments[i] != null ? arguments[i] : {};
52
+ var ownKeys2 = Object.keys(source);
53
+ if (typeof Object.getOwnPropertySymbols === "function") {
54
+ ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
55
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
56
+ }));
44
57
  }
45
- return keys;
58
+ ownKeys2.forEach(function(key) {
59
+ _define_property(target, key, source[key]);
60
+ });
46
61
  }
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));
62
+ return target;
63
+ }
64
+
65
+ // node_modules/@swc/helpers/esm/_object_spread_props.js
66
+ function ownKeys(object, enumerableOnly) {
67
+ var keys = Object.keys(object);
68
+ if (Object.getOwnPropertySymbols) {
69
+ var symbols = Object.getOwnPropertySymbols(object);
70
+ if (enumerableOnly) {
71
+ symbols = symbols.filter(function(sym) {
72
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
53
73
  });
54
74
  }
55
- return target;
75
+ keys.push.apply(keys, symbols);
76
+ }
77
+ return keys;
78
+ }
79
+ function _object_spread_props(target, source) {
80
+ source = source != null ? source : {};
81
+ if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
82
+ else {
83
+ ownKeys(Object(source)).forEach(function(key) {
84
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
85
+ });
56
86
  }
87
+ return target;
88
+ }
57
89
 
58
- // node_modules/@swc/helpers/esm/_object_without_properties_loose.js
59
- function _object_without_properties_loose(source, excluded) {
60
- if (source == null) return {};
61
- var target = {};
62
- var sourceKeys = Object.keys(source);
63
- var key, i;
64
- for (i = 0; i < sourceKeys.length; i++) {
65
- key = sourceKeys[i];
66
- if (excluded.indexOf(key) >= 0) continue;
67
- target[key] = source[key];
68
- }
69
- return target;
90
+ // node_modules/@swc/helpers/esm/_object_without_properties_loose.js
91
+ function _object_without_properties_loose(source, excluded) {
92
+ if (source == null) return {};
93
+ var target = {};
94
+ var sourceKeys = Object.keys(source);
95
+ var key, i;
96
+ for (i = 0; i < sourceKeys.length; i++) {
97
+ key = sourceKeys[i];
98
+ if (excluded.indexOf(key) >= 0) continue;
99
+ target[key] = source[key];
70
100
  }
101
+ return target;
102
+ }
71
103
 
72
- // node_modules/@swc/helpers/esm/_object_without_properties.js
73
- function _object_without_properties(source, excluded) {
74
- if (source == null) return {};
75
- var target = _object_without_properties_loose(source, excluded);
76
- var key, i;
77
- if (Object.getOwnPropertySymbols) {
78
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
79
- for (i = 0; i < sourceSymbolKeys.length; i++) {
80
- key = sourceSymbolKeys[i];
81
- if (excluded.indexOf(key) >= 0) continue;
82
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
83
- target[key] = source[key];
84
- }
104
+ // node_modules/@swc/helpers/esm/_object_without_properties.js
105
+ function _object_without_properties(source, excluded) {
106
+ if (source == null) return {};
107
+ var target = _object_without_properties_loose(source, excluded);
108
+ var key, i;
109
+ if (Object.getOwnPropertySymbols) {
110
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
111
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
112
+ key = sourceSymbolKeys[i];
113
+ if (excluded.indexOf(key) >= 0) continue;
114
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
115
+ target[key] = source[key];
85
116
  }
86
- return target;
87
117
  }
118
+ return target;
119
+ }
88
120
 
89
- // node_modules/@swc/helpers/esm/_array_like_to_array.js
90
- function _array_like_to_array(arr, len) {
91
- if (len == null || len > arr.length) len = arr.length;
92
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
93
- return arr2;
94
- }
121
+ // node_modules/@swc/helpers/esm/_array_like_to_array.js
122
+ function _array_like_to_array(arr, len) {
123
+ if (len == null || len > arr.length) len = arr.length;
124
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
125
+ return arr2;
126
+ }
95
127
 
96
- // node_modules/@swc/helpers/esm/_array_without_holes.js
97
- function _array_without_holes(arr) {
98
- if (Array.isArray(arr)) return _array_like_to_array(arr);
99
- }
128
+ // node_modules/@swc/helpers/esm/_array_without_holes.js
129
+ function _array_without_holes(arr) {
130
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
131
+ }
100
132
 
101
- // node_modules/@swc/helpers/esm/_iterable_to_array.js
102
- function _iterable_to_array(iter) {
103
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
104
- return Array.from(iter);
105
- }
133
+ // node_modules/@swc/helpers/esm/_iterable_to_array.js
134
+ function _iterable_to_array(iter) {
135
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
136
+ return Array.from(iter);
106
137
  }
138
+ }
107
139
 
108
- // node_modules/@swc/helpers/esm/_non_iterable_spread.js
109
- function _non_iterable_spread() {
110
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
111
- }
140
+ // node_modules/@swc/helpers/esm/_non_iterable_spread.js
141
+ function _non_iterable_spread() {
142
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
143
+ }
112
144
 
113
- // node_modules/@swc/helpers/esm/_unsupported_iterable_to_array.js
114
- function _unsupported_iterable_to_array(o, minLen) {
115
- if (!o) return;
116
- if (typeof o === "string") return _array_like_to_array(o, minLen);
117
- var n = Object.prototype.toString.call(o).slice(8, -1);
118
- if (n === "Object" && o.constructor) n = o.constructor.name;
119
- if (n === "Map" || n === "Set") return Array.from(n);
120
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
121
- }
145
+ // node_modules/@swc/helpers/esm/_unsupported_iterable_to_array.js
146
+ function _unsupported_iterable_to_array(o, minLen) {
147
+ if (!o) return;
148
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
149
+ var n = Object.prototype.toString.call(o).slice(8, -1);
150
+ if (n === "Object" && o.constructor) n = o.constructor.name;
151
+ if (n === "Map" || n === "Set") return Array.from(n);
152
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
153
+ }
122
154
 
123
- // node_modules/@swc/helpers/esm/_to_consumable_array.js
124
- function _to_consumable_array(arr) {
125
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
126
- }
155
+ // node_modules/@swc/helpers/esm/_to_consumable_array.js
156
+ function _to_consumable_array(arr) {
157
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
158
+ }
127
159
 
128
- // node_modules/@swc/helpers/esm/_type_of.js
129
- function _type_of(obj) {
130
- "@swc/helpers - typeof";
131
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
132
- }
160
+ // node_modules/@swc/helpers/esm/_type_of.js
161
+ function _type_of(obj) {
162
+ "@swc/helpers - typeof";
163
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
164
+ }
133
165
 
134
- // src/identifiers/index.ts
135
- function modelKeyIdentifier() {
136
- return true;
137
- }
138
- function modelUsageIdentifier() {
139
- return true;
140
- }
141
- function modelStoreIdentifier() {
142
- return true;
143
- }
144
- function tokenIdentifier() {
145
- return true;
146
- }
166
+ // src/identifiers/index.ts
167
+ function modelKeyIdentifier() {
168
+ return true;
169
+ }
170
+ function modelUsageIdentifier() {
171
+ return true;
172
+ }
173
+ function modelStoreIdentifier() {
174
+ return true;
175
+ }
176
+ function tokenIdentifier() {
177
+ return true;
178
+ }
147
179
 
148
- // src/validation/index.ts
149
- var noStateAModelKey = "no-state-a-model-key";
150
- function createNoStateModel() {
151
- return function noStateModel(state) {
152
- return _define_property({}, noStateAModelKey, true);
153
- };
180
+ // src/validation/index.ts
181
+ var noStateAModelKey = "no-state-a-model-key";
182
+ function createNoStateModel() {
183
+ return function noStateModel(state) {
184
+ return _define_property({}, noStateAModelKey, true);
185
+ };
186
+ }
187
+ function isInstanceFromNoStateModel(instance) {
188
+ if (instance == null) {
189
+ return false;
154
190
  }
155
- function isInstanceFromNoStateModel(instance) {
156
- if (instance == null) {
157
- return false;
158
- }
159
- if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object") {
160
- return false;
161
- }
162
- var ins = instance;
163
- return !!ins[noStateAModelKey];
191
+ if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object") {
192
+ return false;
164
193
  }
165
- function isModelKey(data) {
166
- if (!data) {
167
- return false;
168
- }
169
- return data.modelKeyIdentifier === modelKeyIdentifier && data.modelKeyIdentifier();
194
+ var ins = instance;
195
+ return !!ins[noStateAModelKey];
196
+ }
197
+ function isModelKey(data) {
198
+ if (!data) {
199
+ return false;
170
200
  }
171
- function isModelUsage(data) {
172
- if (!data) {
173
- return false;
174
- }
175
- return data.modelUsageIdentifier === modelUsageIdentifier && data.modelUsageIdentifier();
201
+ return data.modelKeyIdentifier === modelKeyIdentifier && data.modelKeyIdentifier();
202
+ }
203
+ function isModelUsage(data) {
204
+ if (!data) {
205
+ return false;
176
206
  }
177
- function isModelStore(data) {
178
- if (!data) {
179
- return false;
180
- }
181
- return data.modelStoreIdentifier === modelStoreIdentifier && data.modelStoreIdentifier();
207
+ return data.modelUsageIdentifier === modelUsageIdentifier && data.modelUsageIdentifier();
208
+ }
209
+ function isModelStore(data) {
210
+ if (!data) {
211
+ return false;
182
212
  }
183
- function isToken(data) {
184
- if (!data) {
185
- return false;
186
- }
187
- return data.tokenIdentifier === tokenIdentifier && data.tokenIdentifier();
213
+ return data.modelStoreIdentifier === modelStoreIdentifier && data.modelStoreIdentifier();
214
+ }
215
+ function isToken(data) {
216
+ if (!data) {
217
+ return false;
188
218
  }
189
- function isStoreIndex(data) {
190
- if (!data) {
191
- return false;
192
- }
193
- return !!data.key && isModelKey(data.key);
219
+ return data.tokenIdentifier === tokenIdentifier && data.tokenIdentifier();
220
+ }
221
+ function isStoreIndex(data) {
222
+ if (!data) {
223
+ return false;
194
224
  }
195
- var validations = {
196
- isInstanceFromNoStateModel,
197
- isModelKey,
198
- isModelStore,
199
- isModelUsage,
200
- isToken,
201
- isStoreIndex
202
- };
225
+ return !!data.key && isModelKey(data.key);
226
+ }
227
+ var validations = {
228
+ isInstanceFromNoStateModel,
229
+ isModelKey,
230
+ isModelStore,
231
+ isModelUsage,
232
+ isToken,
233
+ isStoreIndex
234
+ };
203
235
 
204
- // src/tools/proxy.ts
205
- function getDescriptors(target, receiver, ownOrPrototype, handler) {
206
- var it = Object.keys(ownOrPrototype);
207
- var result = {};
208
- it.forEach(function(key) {
209
- result[key] = {
210
- get: function() {
211
- if (!handler.get) {
212
- return target[key];
213
- }
214
- return handler.get(target, key, receiver);
215
- },
216
- set: function(v) {
217
- if (!handler.set) {
218
- target[key] = v;
219
- return;
220
- }
221
- var valid = handler.set(target, key, v, receiver);
222
- if (!valid) {
223
- throw new Error("".concat(key, " in proxy target is not mutable"));
224
- }
236
+ // src/tools/proxy.ts
237
+ function getDescriptors(target, receiver, ownOrPrototype, handler) {
238
+ var it = Object.keys(ownOrPrototype);
239
+ var result = {};
240
+ it.forEach(function(key) {
241
+ result[key] = {
242
+ get: function() {
243
+ if (!handler.get) {
244
+ return target[key];
225
245
  }
226
- };
227
- });
228
- return result;
246
+ return handler.get(target, key, receiver);
247
+ },
248
+ set: function(v) {
249
+ if (!handler.set) {
250
+ target[key] = v;
251
+ return;
252
+ }
253
+ var valid = handler.set(target, key, v, receiver);
254
+ if (!valid) {
255
+ throw new Error("".concat(key, " in proxy target is not mutable"));
256
+ }
257
+ }
258
+ };
259
+ });
260
+ return result;
261
+ }
262
+ var createSimpleProxy = function(target, handler) {
263
+ var proxy = {};
264
+ var own = getDescriptors(target, proxy, target, handler);
265
+ var prototype = getDescriptors(target, proxy, Object.getPrototypeOf(target), handler);
266
+ Object.defineProperties(proxy, _object_spread({}, prototype, own));
267
+ return proxy;
268
+ };
269
+ var createProxy = function(target, handler) {
270
+ if (typeof Proxy !== "function") {
271
+ return createSimpleProxy(target, handler);
229
272
  }
230
- var createSimpleProxy = function(target, handler) {
231
- var proxy = {};
232
- var own = getDescriptors(target, proxy, target, handler);
233
- var prototype = getDescriptors(target, proxy, Object.getPrototypeOf(target), handler);
234
- Object.defineProperties(proxy, _object_spread({}, prototype, own));
235
- return proxy;
236
- };
237
- var createProxy = function(target, handler) {
238
- if (typeof Proxy !== "function") {
239
- return createSimpleProxy(target, handler);
240
- }
241
- return new Proxy(target, handler);
242
- };
273
+ return new Proxy(target, handler);
274
+ };
243
275
 
244
- // src/tools/shallowEqual.ts
245
- function isObject(data) {
246
- return data && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object";
276
+ // src/tools/shallowEqual.ts
277
+ function isObject(data) {
278
+ return data && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object";
279
+ }
280
+ function shallowEqual(prev, current) {
281
+ if (Object.is(prev, current)) {
282
+ return true;
247
283
  }
248
- function shallowEqual(prev, current) {
249
- if (Object.is(prev, current)) {
250
- return true;
251
- }
252
- if (!isObject(prev) || !isObject(current)) {
253
- return false;
254
- }
255
- var prevKeys = Object.keys(prev);
256
- var currentKeys = Object.keys(current);
257
- if (prevKeys.length !== currentKeys.length) {
258
- return false;
259
- }
260
- var pre = prev;
261
- var curr = current;
262
- var hasDiffKey = prevKeys.some(function(key) {
263
- return !Object.prototype.hasOwnProperty.call(curr, key);
264
- });
265
- if (hasDiffKey) {
266
- return false;
267
- }
268
- var hasDiffValue = currentKeys.some(function(key) {
269
- var currentValue = curr[key];
270
- var prevValue = pre[key];
271
- return !Object.is(currentValue, prevValue);
272
- });
273
- return !hasDiffValue;
284
+ if (!isObject(prev) || !isObject(current)) {
285
+ return false;
274
286
  }
275
-
276
- // src/tools/index.ts
277
- function noop() {
287
+ var prevKeys = Object.keys(prev);
288
+ var currentKeys = Object.keys(current);
289
+ if (prevKeys.length !== currentKeys.length) {
290
+ return false;
278
291
  }
279
- function simpleErrorProcess(errors) {
280
- return function wrap(callback) {
281
- return function replaced() {
282
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
283
- args[_key] = arguments[_key];
284
- }
285
- try {
286
- return callback.apply(void 0, _to_consumable_array(args));
287
- } catch (e) {
288
- errors.push(e);
289
- }
290
- };
291
- };
292
+ var pre = prev;
293
+ var curr = current;
294
+ var hasDiffKey = prevKeys.some(function(key) {
295
+ return !Object.prototype.hasOwnProperty.call(curr, key);
296
+ });
297
+ if (hasDiffKey) {
298
+ return false;
292
299
  }
300
+ var hasDiffValue = currentKeys.some(function(key) {
301
+ var currentValue = curr[key];
302
+ var prevValue = pre[key];
303
+ return !Object.is(currentValue, prevValue);
304
+ });
305
+ return !hasDiffValue;
306
+ }
293
307
 
294
- // src/updater/token.ts
295
- function createToken() {
296
- var value = {};
297
- return {
298
- isDifferent: function isDifferent(token) {
299
- if (!isToken(token)) {
300
- return true;
301
- }
302
- return token.value !== value;
303
- },
304
- value
308
+ // src/tools/index.ts
309
+ function noop() {
310
+ }
311
+ function simpleErrorProcess(errors) {
312
+ return function wrap(callback) {
313
+ return function replaced() {
314
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
315
+ args[_key] = arguments[_key];
316
+ }
317
+ try {
318
+ return callback.apply(void 0, _to_consumable_array(args));
319
+ } catch (e) {
320
+ errors.push(e);
321
+ }
305
322
  };
306
- }
323
+ };
324
+ }
307
325
 
308
- // src/updater/notifier.ts
309
- function defaultNotifyImplement(dispatches, action) {
310
- dispatches.forEach(function(callback) {
311
- callback(action);
312
- });
313
- }
314
- function generateNotifier(updater, middleWare) {
315
- function pendAction(value) {
316
- updater.mutate(function(u) {
317
- var dispatching = u.dispatching;
318
- if (!dispatching) {
319
- var wrap = {
320
- value
321
- };
322
- wrap.tail = wrap;
323
- return _object_spread_props(_object_spread({}, u), {
324
- dispatching: wrap
325
- });
326
- }
327
- var tail = dispatching.tail;
328
- if (!tail) {
329
- return u;
330
- }
331
- var current = {
332
- prev: tail,
326
+ // src/updater/token.ts
327
+ function createToken() {
328
+ var value = {};
329
+ return {
330
+ isDifferent: function isDifferent(token) {
331
+ if (!isToken(token)) {
332
+ return true;
333
+ }
334
+ return token.value !== value;
335
+ },
336
+ value
337
+ };
338
+ }
339
+
340
+ // src/updater/notifier.ts
341
+ function defaultNotifyImplement(dispatches, action) {
342
+ dispatches.forEach(function(callback) {
343
+ callback(action);
344
+ });
345
+ }
346
+ function generateNotifier(updater, middleWare) {
347
+ function pendAction(value) {
348
+ updater.mutate(function(u) {
349
+ var dispatching = u.dispatching;
350
+ if (!dispatching) {
351
+ var wrap = {
333
352
  value
334
353
  };
335
- tail.next = current;
336
- dispatching.tail = current;
354
+ wrap.tail = wrap;
337
355
  return _object_spread_props(_object_spread({}, u), {
338
- dispatching
356
+ dispatching: wrap
339
357
  });
358
+ }
359
+ var tail = dispatching.tail;
360
+ if (!tail) {
361
+ return u;
362
+ }
363
+ var current = {
364
+ prev: tail,
365
+ value
366
+ };
367
+ tail.next = current;
368
+ dispatching.tail = current;
369
+ return _object_spread_props(_object_spread({}, u), {
370
+ dispatching
340
371
  });
341
- }
342
- function unshiftAction() {
343
- return updater.mutate(function(u) {
344
- var dispatching = updater.dispatching;
345
- if (!dispatching) {
346
- return u;
347
- }
348
- var next = dispatching.next, tail = dispatching.tail;
349
- if (tail === dispatching || !next) {
350
- dispatching.tail = void 0;
351
- return _object_spread_props(_object_spread({}, u), {
352
- dispatching: void 0
353
- });
354
- }
355
- next.prev = void 0;
356
- var newFirst = next;
357
- newFirst.tail = tail;
372
+ });
373
+ }
374
+ function unshiftAction() {
375
+ return updater.mutate(function(u) {
376
+ var dispatching = updater.dispatching;
377
+ if (!dispatching) {
378
+ return u;
379
+ }
380
+ var next = dispatching.next, tail = dispatching.tail;
381
+ if (tail === dispatching || !next) {
382
+ dispatching.tail = void 0;
358
383
  return _object_spread_props(_object_spread({}, u), {
359
- dispatching: newFirst
384
+ dispatching: void 0
360
385
  });
361
- }).dispatching;
362
- }
363
- function consumeTemporaries() {
364
- var temporaryDispatches = updater.temporaryDispatches;
365
- updater.mutate(function(u) {
366
- return u.temporaryDispatches.length ? _object_spread_props(_object_spread({}, u), {
367
- dispatches: _to_consumable_array(u.dispatches).concat(_to_consumable_array(u.temporaryDispatches)),
368
- temporaryDispatches: []
369
- }) : u;
386
+ }
387
+ next.prev = void 0;
388
+ var newFirst = next;
389
+ newFirst.tail = tail;
390
+ return _object_spread_props(_object_spread({}, u), {
391
+ dispatching: newFirst
370
392
  });
371
- var initializedAction = {
372
- state: updater.state,
373
- prevState: updater.state,
374
- instance: updater.instance,
375
- prevInstance: updater.instance,
376
- type: null,
377
- method: null
378
- };
379
- temporaryDispatches.forEach(function(d) {
380
- if (!d.accessible) {
381
- return;
382
- }
383
- d.dispatch(initializedAction);
393
+ }).dispatching;
394
+ }
395
+ function consumeTemporaries() {
396
+ var temporaryDispatches = updater.temporaryDispatches;
397
+ updater.mutate(function(u) {
398
+ return u.temporaryDispatches.length ? _object_spread_props(_object_spread({}, u), {
399
+ dispatches: _to_consumable_array(u.dispatches).concat(_to_consumable_array(u.temporaryDispatches)),
400
+ temporaryDispatches: []
401
+ }) : u;
402
+ });
403
+ var initializedAction = {
404
+ state: updater.state,
405
+ prevState: updater.state,
406
+ instance: updater.instance,
407
+ prevInstance: updater.instance,
408
+ type: null,
409
+ method: null
410
+ };
411
+ temporaryDispatches.forEach(function(d) {
412
+ if (!d.accessible) {
413
+ return;
414
+ }
415
+ d.dispatch(initializedAction);
416
+ });
417
+ }
418
+ var dispatch = function dispatch2(action) {
419
+ var dispatches = updater.dispatches, controlled = updater.controlled, model2 = updater.model, config2 = updater.config;
420
+ var state = action.state;
421
+ var nextInstance = model2(state);
422
+ var nextAction = _object_spread_props(_object_spread({}, action), {
423
+ instance: nextInstance
424
+ });
425
+ if (!controlled) {
426
+ updater.mutate(function(u) {
427
+ return _object_spread_props(_object_spread({}, u), {
428
+ state,
429
+ instance: nextInstance,
430
+ version: u.version + 1,
431
+ token: createToken()
432
+ });
384
433
  });
385
434
  }
386
- var dispatch = function dispatch2(action) {
387
- var dispatches = updater.dispatches, controlled = updater.controlled, model2 = updater.model, config2 = updater.config;
388
- var state = action.state;
389
- var nextInstance = model2(state);
390
- var nextAction = _object_spread_props(_object_spread({}, action), {
391
- instance: nextInstance
392
- });
393
- if (!controlled) {
394
- updater.mutate(function(u) {
395
- return _object_spread_props(_object_spread({}, u), {
396
- state,
397
- instance: nextInstance,
398
- version: u.version + 1,
399
- token: createToken()
400
- });
401
- });
402
- }
403
- var notifyAction = function notifyAction2(act) {
404
- var errors = [];
405
- var dispatchWrap = simpleErrorProcess(errors);
406
- var dispatchCallbacks = dispatches.map(function(d) {
407
- return dispatchWrap(function dispatchCallback(ac) {
408
- if (!d.accessible) {
409
- return;
410
- }
411
- d.dispatch(ac);
412
- });
435
+ var notifyAction = function notifyAction2(act) {
436
+ var errors = [];
437
+ var dispatchWrap = simpleErrorProcess(errors);
438
+ var dispatchCallbacks = dispatches.map(function(d) {
439
+ return dispatchWrap(function dispatchCallback(ac) {
440
+ if (!d.accessible) {
441
+ return;
442
+ }
443
+ d.dispatch(ac);
413
444
  });
414
- defaultNotifyImplement(dispatchCallbacks, act);
415
- if (!errors.length) {
416
- return {
417
- errors: void 0
418
- };
419
- }
445
+ });
446
+ defaultNotifyImplement(dispatchCallbacks, act);
447
+ if (!errors.length) {
420
448
  return {
421
- errors
449
+ errors: void 0
422
450
  };
451
+ }
452
+ return {
453
+ errors
423
454
  };
424
- var notifyActionWithErrorThrow = function notifyActionWithErrorThrow2(act) {
425
- var errors = notifyAction(act).errors;
426
- if (!errors || !errors.length) {
427
- return;
428
- }
429
- throw errors[0];
430
- };
431
- try {
432
- if (typeof config2.notify === "function") {
433
- config2.notify(notifyAction, nextAction);
434
- } else {
435
- notifyActionWithErrorThrow(nextAction);
436
- }
437
- } catch (e) {
455
+ };
456
+ var notifyActionWithErrorThrow = function notifyActionWithErrorThrow2(act) {
457
+ var errors = notifyAction(act).errors;
458
+ if (!errors || !errors.length) {
459
+ return;
460
+ }
461
+ throw errors[0];
462
+ };
463
+ try {
464
+ if (typeof config2.notify === "function") {
465
+ config2.notify(notifyAction, nextAction);
466
+ } else {
467
+ notifyActionWithErrorThrow(nextAction);
468
+ }
469
+ } catch (e) {
470
+ updater.mutate(function(u) {
471
+ return _object_spread_props(_object_spread({}, u), {
472
+ dispatching: void 0
473
+ });
474
+ });
475
+ throw e;
476
+ }
477
+ };
478
+ return function notify(action) {
479
+ if (action == null || updater.isDestroyed) {
480
+ return;
481
+ }
482
+ var dispatching = updater.dispatching;
483
+ pendAction(action);
484
+ if (dispatching) {
485
+ return;
486
+ }
487
+ while (updater.dispatching) {
488
+ var wrap = updater.dispatching;
489
+ if (wrap) {
490
+ middleWare({
491
+ getState: function getState() {
492
+ return {
493
+ state: updater.state,
494
+ instance: updater.instance
495
+ };
496
+ },
497
+ dispatch: notify
498
+ })(dispatch)(wrap.value);
499
+ unshiftAction();
500
+ } else {
438
501
  updater.mutate(function(u) {
439
502
  return _object_spread_props(_object_spread({}, u), {
440
503
  dispatching: void 0
441
504
  });
442
505
  });
443
- throw e;
444
506
  }
445
- };
446
- return function notify(action) {
447
- if (action == null || updater.isDestroyed) {
448
- return;
449
- }
450
- var dispatching = updater.dispatching;
451
- pendAction(action);
452
- if (dispatching) {
453
- return;
507
+ }
508
+ consumeTemporaries();
509
+ };
510
+ }
511
+
512
+ // src/updater/tunnel.ts
513
+ function createUnInitializedUpdater() {
514
+ return {
515
+ notify: function(a) {
516
+ },
517
+ createTunnel: function(dispatcher) {
518
+ return {
519
+ connect: noop,
520
+ disconnect: noop
521
+ };
522
+ }
523
+ };
524
+ }
525
+ function destroy(updater) {
526
+ function destroyDispatching() {
527
+ updater.mutate(function(u) {
528
+ var dispatching = u.dispatching;
529
+ if (!dispatching) {
530
+ return u;
454
531
  }
455
- while (updater.dispatching) {
456
- var wrap = updater.dispatching;
457
- if (wrap) {
458
- middleWare({
459
- getState: function getState() {
460
- return {
461
- state: updater.state,
462
- instance: updater.instance
463
- };
464
- },
465
- dispatch: notify
466
- })(dispatch)(wrap.value);
467
- unshiftAction();
468
- } else {
469
- updater.mutate(function(u) {
470
- return _object_spread_props(_object_spread({}, u), {
471
- dispatching: void 0
472
- });
473
- });
532
+ var wrapper = dispatching;
533
+ while (wrapper) {
534
+ var next = wrapper.next;
535
+ wrapper.next = void 0;
536
+ wrapper.prev = void 0;
537
+ if (next) {
538
+ next.prev = void 0;
474
539
  }
540
+ wrapper = next;
475
541
  }
476
- consumeTemporaries();
477
- };
542
+ dispatching.tail = void 0;
543
+ return _object_spread_props(_object_spread({}, u), {
544
+ dispatching: void 0,
545
+ initialized: false
546
+ });
547
+ });
478
548
  }
479
-
480
- // src/updater/tunnel.ts
481
- function createUnInitializedUpdater() {
482
- return {
483
- notify: function(a) {
484
- },
485
- createTunnel: function(dispatcher) {
486
- return {
487
- connect: noop,
488
- disconnect: noop
489
- };
490
- }
549
+ updater.mutate(function(u, effect) {
550
+ var destroyed = createUnInitializedUpdater();
551
+ effect(function() {
552
+ destroyDispatching();
553
+ });
554
+ return _object_spread_props(_object_spread({}, u, destroyed), {
555
+ sidePayload: void 0,
556
+ isDestroyed: true
557
+ });
558
+ });
559
+ }
560
+ function generateTunnelCreator(updater) {
561
+ function subscribe(dispatchFn) {
562
+ var dispatches = updater.dispatches, temporaryDispatches = updater.temporaryDispatches, isControlled = updater.controlled;
563
+ var copied = _to_consumable_array(dispatches).concat(_to_consumable_array(temporaryDispatches));
564
+ var exist = copied.some(function(d) {
565
+ return d.dispatch === dispatchFn;
566
+ });
567
+ if (exist) {
568
+ return updater.mutate(function(u) {
569
+ return _object_spread_props(_object_spread({}, u), {
570
+ isDestroyed: false
571
+ });
572
+ });
573
+ }
574
+ var dispatcher = {
575
+ dispatch: dispatchFn,
576
+ accessible: true
491
577
  };
492
- }
493
- function destroy(updater) {
494
- function destroyDispatching() {
495
- updater.mutate(function(u) {
496
- var dispatching = u.dispatching;
497
- if (!dispatching) {
498
- return u;
499
- }
500
- var wrapper = dispatching;
501
- while (wrapper) {
502
- var next = wrapper.next;
503
- wrapper.next = void 0;
504
- wrapper.prev = void 0;
505
- if (next) {
506
- next.prev = void 0;
507
- }
508
- wrapper = next;
509
- }
510
- dispatching.tail = void 0;
578
+ if (isControlled) {
579
+ return updater.mutate(function(u) {
511
580
  return _object_spread_props(_object_spread({}, u), {
512
- dispatching: void 0,
513
- initialized: false
581
+ dispatches: [
582
+ dispatcher
583
+ ],
584
+ isDestroyed: false
514
585
  });
515
586
  });
516
587
  }
517
- updater.mutate(function(u, effect) {
518
- var destroyed = createUnInitializedUpdater();
519
- effect(function() {
520
- destroyDispatching();
588
+ return updater.mutate(function(u, effect) {
589
+ var tds = u.temporaryDispatches, ds = u.dispatches;
590
+ var nextTds = _to_consumable_array(tds).concat([
591
+ dispatcher
592
+ ]);
593
+ if (u.dispatching) {
594
+ return _object_spread_props(_object_spread({}, u), {
595
+ temporaryDispatches: nextTds,
596
+ isDestroyed: false
597
+ });
598
+ }
599
+ effect(function(up) {
600
+ var initializedAction = {
601
+ state: up.state,
602
+ prevState: up.state,
603
+ instance: up.instance,
604
+ prevInstance: up.instance,
605
+ type: null,
606
+ method: null
607
+ };
608
+ nextTds.forEach(function(td) {
609
+ td.dispatch(initializedAction);
610
+ });
521
611
  });
522
- return _object_spread_props(_object_spread({}, u, destroyed), {
523
- sidePayload: void 0,
524
- isDestroyed: true
612
+ return _object_spread_props(_object_spread({}, u), {
613
+ temporaryDispatches: [],
614
+ dispatches: _to_consumable_array(ds).concat(_to_consumable_array(nextTds)),
615
+ isDestroyed: false
525
616
  });
526
617
  });
527
618
  }
528
- function generateTunnelCreator(updater) {
529
- function subscribe(dispatchFn) {
530
- var dispatches = updater.dispatches, temporaryDispatches = updater.temporaryDispatches, isControlled = updater.controlled;
531
- var copied = _to_consumable_array(dispatches).concat(_to_consumable_array(temporaryDispatches));
532
- var exist = copied.some(function(d) {
533
- return d.dispatch === dispatchFn;
534
- });
535
- if (exist) {
536
- return updater.mutate(function(u) {
537
- return _object_spread_props(_object_spread({}, u), {
538
- isDestroyed: false
539
- });
540
- });
541
- }
542
- var dispatcher = {
543
- dispatch: dispatchFn,
544
- accessible: true
545
- };
546
- if (isControlled) {
547
- return updater.mutate(function(u) {
548
- return _object_spread_props(_object_spread({}, u), {
549
- dispatches: [
550
- dispatcher
551
- ],
552
- isDestroyed: false
553
- });
619
+ return function tunnel(dispatchFn) {
620
+ function disconnect() {
621
+ updater.mutate(function(u) {
622
+ var ds = u.dispatches, tds = u.temporaryDispatches;
623
+ var found = _to_consumable_array(ds).concat(_to_consumable_array(tds)).find(function(d) {
624
+ return d.dispatch === dispatchFn;
554
625
  });
555
- }
556
- return updater.mutate(function(u, effect) {
557
- var tds = u.temporaryDispatches, ds = u.dispatches;
558
- var nextTds = _to_consumable_array(tds).concat([
559
- dispatcher
560
- ]);
561
- if (u.dispatching) {
562
- return _object_spread_props(_object_spread({}, u), {
563
- temporaryDispatches: nextTds,
564
- isDestroyed: false
565
- });
626
+ if (!found) {
627
+ return u;
566
628
  }
567
- effect(function(up) {
568
- var initializedAction = {
569
- state: up.state,
570
- prevState: up.state,
571
- instance: up.instance,
572
- prevInstance: up.instance,
573
- type: null,
574
- method: null
575
- };
576
- nextTds.forEach(function(td) {
577
- td.dispatch(initializedAction);
578
- });
629
+ found.accessible = false;
630
+ var nextDs = ds.filter(function(d) {
631
+ return d !== found;
632
+ });
633
+ var nextTds = tds.filter(function(d) {
634
+ return d !== found;
579
635
  });
580
636
  return _object_spread_props(_object_spread({}, u), {
581
- temporaryDispatches: [],
582
- dispatches: _to_consumable_array(ds).concat(_to_consumable_array(nextTds)),
583
- isDestroyed: false
637
+ dispatches: nextDs,
638
+ temporaryDispatches: nextTds
584
639
  });
585
640
  });
586
641
  }
587
- return function tunnel(dispatchFn) {
588
- function disconnect() {
589
- updater.mutate(function(u) {
590
- var ds = u.dispatches, tds = u.temporaryDispatches;
591
- var found = _to_consumable_array(ds).concat(_to_consumable_array(tds)).find(function(d) {
592
- return d.dispatch === dispatchFn;
593
- });
594
- if (!found) {
595
- return u;
596
- }
597
- found.accessible = false;
598
- var nextDs = ds.filter(function(d) {
599
- return d !== found;
600
- });
601
- var nextTds = tds.filter(function(d) {
602
- return d !== found;
603
- });
604
- return _object_spread_props(_object_spread({}, u), {
605
- dispatches: nextDs,
606
- temporaryDispatches: nextTds
607
- });
608
- });
642
+ return {
643
+ connect: function connect() {
644
+ subscribe(dispatchFn);
645
+ },
646
+ disconnect: function disconnect1() {
647
+ disconnect();
609
648
  }
610
- return {
611
- connect: function connect() {
612
- subscribe(dispatchFn);
613
- },
614
- disconnect: function disconnect1() {
615
- disconnect();
616
- }
617
- };
618
649
  };
619
- }
650
+ };
651
+ }
620
652
 
621
- // src/updater/index.ts
622
- function createInitializedUpdater(updater, middleWare) {
623
- var createTunnel = generateTunnelCreator(updater);
624
- return {
625
- notify: generateNotifier(updater, middleWare),
626
- createTunnel
627
- };
628
- }
629
- function createUpdateFn(updater, middleWare) {
630
- return function update() {
631
- var args = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
632
- updater.mutate(function(u, effect) {
633
- var _args_model;
634
- var model2 = (_args_model = args.model) !== null && _args_model !== void 0 ? _args_model : u.model;
635
- var hasState = Object.prototype.hasOwnProperty.call(args, "state");
636
- var hasInitialState = Object.prototype.hasOwnProperty.call(args, "initialState");
637
- var state = hasState ? args.state : u.state;
638
- var isInitialize = !u.initialized || hasInitialState;
639
- var token = createToken();
640
- if (u.controlled) {
641
- var controlledState = hasInitialState && !hasState ? args.initialState : state;
642
- var instance = model2(controlledState);
643
- return _object_spread_props(_object_spread({}, u), {
644
- state: controlledState,
645
- instance,
646
- model: model2
647
- });
648
- }
649
- if (u.isDestroyed) {
650
- return u;
651
- }
652
- if (!u.initialized && !hasState && !hasInitialState) {
653
- throw new Error("The updater has not been initialized, it should be updated with a state for initializing.");
654
- }
655
- if (isInitialize) {
656
- var initialState = hasInitialState ? args.initialState : state;
657
- var instance1 = model2(initialState);
658
- var initializedUpdater = createInitializedUpdater(u, middleWare);
659
- return _object_spread(_object_spread_props(_object_spread({}, u), {
660
- model: model2,
661
- state: initialState,
662
- instance: instance1,
663
- initialized: true,
664
- token
665
- }), initializedUpdater);
666
- }
667
- if (Object.is(u.model, model2) && Object.is(u.state, state)) {
668
- return u;
669
- }
670
- effect(function(up) {
671
- up.notify({
672
- type: null,
673
- method: null,
674
- prevInstance: u.instance,
675
- instance: u.instance,
676
- prevState: u.state,
677
- state
678
- });
679
- });
653
+ // src/updater/index.ts
654
+ function createInitializedUpdater(updater, middleWare) {
655
+ var createTunnel = generateTunnelCreator(updater);
656
+ return {
657
+ notify: generateNotifier(updater, middleWare),
658
+ createTunnel
659
+ };
660
+ }
661
+ function createUpdateFn(updater, middleWare) {
662
+ return function update() {
663
+ var args = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
664
+ updater.mutate(function(u, effect) {
665
+ var _args_model;
666
+ var model2 = (_args_model = args.model) !== null && _args_model !== void 0 ? _args_model : u.model;
667
+ var hasState = Object.prototype.hasOwnProperty.call(args, "state");
668
+ var hasInitialState = Object.prototype.hasOwnProperty.call(args, "initialState");
669
+ var state = hasState ? args.state : u.state;
670
+ var isInitialize = !u.initialized || hasInitialState;
671
+ var token = createToken();
672
+ if (u.controlled) {
673
+ var controlledState = hasInitialState && !hasState ? args.initialState : state;
674
+ var instance = model2(controlledState);
680
675
  return _object_spread_props(_object_spread({}, u), {
676
+ state: controlledState,
677
+ instance,
678
+ model: model2
679
+ });
680
+ }
681
+ if (u.isDestroyed) {
682
+ return u;
683
+ }
684
+ if (!u.initialized && !hasState && !hasInitialState) {
685
+ throw new Error("The updater has not been initialized, it should be updated with a state for initializing.");
686
+ }
687
+ if (isInitialize) {
688
+ var initialState = hasInitialState ? args.initialState : state;
689
+ var instance1 = model2(initialState);
690
+ var initializedUpdater = createInitializedUpdater(u, middleWare);
691
+ return _object_spread(_object_spread_props(_object_spread({}, u), {
681
692
  model: model2,
693
+ state: initialState,
694
+ instance: instance1,
682
695
  initialized: true,
683
- cacheFields: {},
684
- cacheMethods: {}
696
+ token
697
+ }), initializedUpdater);
698
+ }
699
+ if (Object.is(u.model, model2) && Object.is(u.state, state)) {
700
+ return u;
701
+ }
702
+ effect(function(up) {
703
+ up.notify({
704
+ type: null,
705
+ method: null,
706
+ prevInstance: u.instance,
707
+ instance: u.instance,
708
+ prevState: u.state,
709
+ state
685
710
  });
686
711
  });
687
- };
688
- }
689
- var lazyModel = createNoStateModel();
690
- function createUpdater(model2, middleWare) {
691
- var config2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
692
- var hasDefaultState = "state" in config2;
693
- var controlled = config2.controlled, defaultState = config2.state;
694
- var defaultInstance = hasDefaultState ? model2(defaultState) : lazyModel(void 0);
695
- var unInitializedUpdater = createUnInitializedUpdater();
696
- var updater = _object_spread({
697
- sidePayload: void 0,
698
- version: 0,
699
- token: createToken(),
700
- isDestroyed: false,
701
- model: model2,
702
- instance: defaultInstance,
703
- dispatch: null,
704
- dispatches: [],
705
- temporaryDispatches: [],
706
- cacheMethods: {},
707
- cacheFields: {},
708
- state: defaultState,
709
- initialized: hasDefaultState,
710
- controlled: !!controlled,
711
- isSubscribing: false,
712
- config: config2,
713
- payload: function payload(setter) {
714
- if (typeof setter === "function") {
715
- updater.sidePayload = setter(updater.sidePayload);
716
- }
717
- return updater.sidePayload;
718
- },
719
- mutate: function mutate(callback) {
720
- var effects = [];
721
- var runEffects = function runEffects2(u) {
722
- effects.forEach(function(e) {
723
- return e(u);
724
- });
725
- };
726
- var result = callback(updater, function(effectFn) {
727
- return effects.push(effectFn);
728
- });
729
- if (updater === result) {
730
- runEffects(result);
731
- return updater;
732
- }
733
- Object.assign(updater, result);
734
- runEffects(updater);
735
- return updater;
736
- },
737
- update: function(args) {
738
- },
739
- destroy: function destroy1() {
740
- destroy(updater);
741
- }
742
- }, unInitializedUpdater);
743
- var initialized = createInitializedUpdater(updater, middleWare);
744
- Object.assign(updater, initialized, {
745
- update: createUpdateFn(updater, middleWare)
712
+ return _object_spread_props(_object_spread({}, u), {
713
+ model: model2,
714
+ initialized: true,
715
+ cacheFields: {},
716
+ cacheMethods: {}
717
+ });
746
718
  });
747
- return updater;
748
- }
749
-
750
- // src/store/cache.ts
751
- var cacheIdentify = {
752
- field: function field(d) {
753
- if (!d) {
754
- return false;
719
+ };
720
+ }
721
+ var lazyModel = createNoStateModel();
722
+ function createUpdater(model2, middleWare) {
723
+ var config2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
724
+ var hasDefaultState = "state" in config2;
725
+ var controlled = config2.controlled, defaultState = config2.state;
726
+ var defaultInstance = hasDefaultState ? model2(defaultState) : lazyModel(void 0);
727
+ var unInitializedUpdater = createUnInitializedUpdater();
728
+ var updater = _object_spread({
729
+ sidePayload: void 0,
730
+ version: 0,
731
+ token: createToken(),
732
+ isDestroyed: false,
733
+ model: model2,
734
+ instance: defaultInstance,
735
+ dispatch: null,
736
+ dispatches: [],
737
+ temporaryDispatches: [],
738
+ cacheMethods: {},
739
+ cacheFields: {},
740
+ state: defaultState,
741
+ initialized: hasDefaultState,
742
+ controlled: !!controlled,
743
+ isSubscribing: false,
744
+ config: config2,
745
+ payload: function payload(setter) {
746
+ if (typeof setter === "function") {
747
+ updater.sidePayload = setter(updater.sidePayload);
755
748
  }
756
- var f = d;
757
- return f.identifier === cacheIdentify.field;
749
+ return updater.sidePayload;
758
750
  },
759
- method: function method(d) {
760
- if (typeof d !== "function") {
761
- return false;
751
+ mutate: function mutate(callback) {
752
+ var effects = [];
753
+ var runEffects = function runEffects2(u) {
754
+ effects.forEach(function(e) {
755
+ return e(u);
756
+ });
757
+ };
758
+ var result = callback(updater, function(effectFn) {
759
+ return effects.push(effectFn);
760
+ });
761
+ if (updater === result) {
762
+ runEffects(result);
763
+ return updater;
762
764
  }
763
- var m = d;
764
- return m.identifier === cacheIdentify.method;
765
+ Object.assign(updater, result);
766
+ runEffects(updater);
767
+ return updater;
768
+ },
769
+ update: function(args) {
770
+ },
771
+ destroy: function destroy1() {
772
+ destroy(updater);
765
773
  }
766
- };
767
- function wrapToField(cache, propertyName, value, onGot) {
768
- var cacheFields = cache.cacheFields;
769
- if (!cacheIdentify.field(value)) {
770
- if (onGot) {
771
- onGot(propertyName, value);
772
- }
773
- return value;
774
+ }, unInitializedUpdater);
775
+ var initialized = createInitializedUpdater(updater, middleWare);
776
+ Object.assign(updater, initialized, {
777
+ update: createUpdateFn(updater, middleWare)
778
+ });
779
+ return updater;
780
+ }
781
+
782
+ // src/store/cache.ts
783
+ var cacheIdentify = {
784
+ field: function field(d) {
785
+ if (!d) {
786
+ return false;
774
787
  }
775
- var field2 = value;
776
- var cachedField = cacheFields[propertyName];
777
- if (cachedField) {
778
- return cachedField.getter;
788
+ var f = d;
789
+ return f.identifier === cacheIdentify.field;
790
+ },
791
+ method: function method(d) {
792
+ if (typeof d !== "function") {
793
+ return false;
779
794
  }
780
- var getter = {
781
- get: function get() {
782
- var currentField = cache.target[propertyName];
783
- if (!cacheIdentify.field(currentField)) {
784
- throw new Error("Field should always be field.");
785
- }
786
- var current = currentField.get();
787
- var fieldInCache = cache.cacheFields[propertyName];
788
- if (!currentField.deps || fieldInCache == null) {
789
- cacheFields[propertyName] = {
790
- getter,
791
- value: current,
792
- deps: currentField.deps
793
- };
794
- return current;
795
- }
796
- if (shallowEqual(currentField.deps, fieldInCache.deps)) {
797
- return fieldInCache.value;
798
- }
799
- cacheFields[propertyName] = {
800
- getter,
801
- value: current,
802
- deps: currentField.deps
803
- };
804
- return current;
805
- }
806
- };
807
- cacheFields[propertyName] = {
808
- getter,
809
- value: field2.value,
810
- deps: field2.deps
811
- };
812
- return getter;
795
+ var m = d;
796
+ return m.identifier === cacheIdentify.method;
813
797
  }
814
- function wrapToActionMethod(cache, methodName) {
815
- var cacheMethods = cache.cacheMethods;
816
- var cachedMethod = cacheMethods[methodName];
817
- if (typeof cachedMethod === "function") {
818
- return cachedMethod;
798
+ };
799
+ function wrapToField(cache, propertyName, value, onGot) {
800
+ var cacheFields = cache.cacheFields;
801
+ if (!cacheIdentify.field(value)) {
802
+ if (onGot) {
803
+ onGot(propertyName, value);
819
804
  }
820
- var actionMethod = function actionMethod2() {
821
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
822
- args[_key] = arguments[_key];
823
- }
824
- var target = cache.target;
825
- var method2 = target[methodName];
826
- if (typeof method2 !== "function") {
827
- throw new Error("Can not change methods in runtime.");
828
- }
829
- return method2.apply(void 0, _to_consumable_array(args));
830
- };
831
- cacheMethods[methodName] = actionMethod;
832
- return actionMethod;
833
- }
834
- var cacheProperties = function(cache, onGet) {
835
- return function createCachePropertiesProxy() {
836
- var instance = cache.target;
837
- var properties = Object.getOwnPropertyNames(instance);
838
- var handleGetter = function handleGetter2(key, value) {
839
- if (!onGet) {
840
- return;
841
- }
842
- onGet(key, value);
843
- };
844
- return createProxy(instance, {
845
- get: function get(target, p) {
846
- var value = target[p];
847
- if (typeof value === "function" && properties.indexOf(p) >= 0) {
848
- var actionMethod = wrapToActionMethod(cache, p);
849
- Object.assign(actionMethod, value);
850
- handleGetter(p, actionMethod);
851
- return actionMethod;
852
- }
853
- return wrapToField(cache, p, value, handleGetter);
854
- },
855
- set: function set() {
856
- return false;
857
- }
858
- });
859
- };
860
- };
861
-
862
- // src/store/instance.ts
863
- function createField(callback, deps) {
864
- var currentDeps = function computeDeps() {
865
- if (deps == null) {
866
- return deps;
867
- }
868
- if (deps.some(function(d) {
869
- return cacheIdentify.field(d) && d.deps == null;
870
- })) {
871
- return void 0;
872
- }
873
- return deps.flatMap(function(d) {
874
- if (cacheIdentify.field(d)) {
875
- return d.deps;
876
- }
877
- return d;
878
- });
879
- }();
880
- var value = callback();
881
- return {
882
- callback,
883
- deps: currentDeps,
884
- identifier: cacheIdentify.field,
885
- value,
886
- get: function get() {
887
- return value;
888
- }
889
- };
890
- }
891
- function createMethod(method2) {
892
- var replace = function replace2() {
893
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
894
- args[_key] = arguments[_key];
895
- }
896
- return method2.apply(void 0, _to_consumable_array(args));
897
- };
898
- replace.identifier = cacheIdentify.method;
899
- return replace;
805
+ return value;
900
806
  }
901
- function wrapToActionMethod2(updater, methodName) {
902
- var cacheMethods = updater.cacheMethods;
903
- var cachedMethod = cacheMethods[methodName];
904
- if (typeof cachedMethod === "function") {
905
- return cachedMethod;
906
- }
907
- var actionMethod = function actionMethod2() {
908
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
909
- args[_key] = arguments[_key];
910
- }
911
- var instance = updater.instance;
912
- var method2 = instance[methodName];
913
- if (typeof method2 !== "function") {
914
- throw new Error("Can not change methods in runtime.");
915
- }
916
- if (cacheIdentify.method(method2)) {
917
- return method2.apply(void 0, _to_consumable_array(args));
918
- }
919
- var state = method2.apply(void 0, _to_consumable_array(args));
920
- var action = {
921
- type: methodName,
922
- state,
923
- prevState: updater.state,
924
- instance: updater.instance,
925
- prevInstance: updater.instance,
926
- method: actionMethod2
927
- };
928
- updater.notify(action);
929
- return state;
930
- };
931
- cacheMethods[methodName] = actionMethod;
932
- return actionMethod;
807
+ var field2 = value;
808
+ var cachedField = cacheFields[propertyName];
809
+ if (cachedField) {
810
+ return cachedField.getter;
933
811
  }
934
- function wrapToField2(updater, propertyName, value, onGot) {
935
- function collect(pName, v) {
936
- if (onGot) {
937
- onGot(pName, v);
812
+ var getter = {
813
+ get: function get() {
814
+ var currentField = cache.target[propertyName];
815
+ if (!cacheIdentify.field(currentField)) {
816
+ throw new Error("Field should always be field.");
938
817
  }
939
- }
940
- var cacheFields = updater.cacheFields;
941
- if (!cacheIdentify.field(value)) {
942
- collect(propertyName, value);
943
- return value;
944
- }
945
- var field2 = value;
946
- var cachedField = cacheFields[propertyName];
947
- if (cachedField && (field2.deps && shallowEqual(cachedField.deps, field2.deps) || !field2.deps && cachedField.value === field2.value)) {
948
- var cacheFieldGetter = cachedField.getter;
949
- collect(propertyName, cacheFieldGetter);
950
- return cacheFieldGetter;
951
- }
952
- var getter = {
953
- get: function get() {
954
- var currentField = updater.instance[propertyName];
955
- if (!cacheIdentify.field(currentField)) {
956
- throw new Error("Field should always be field.");
957
- }
958
- var current = currentField.get();
959
- var fieldInCache = updater.cacheFields[propertyName];
960
- if (!currentField.deps || fieldInCache == null) {
961
- cacheFields[propertyName] = {
962
- getter,
963
- value: current,
964
- deps: currentField.deps
965
- };
966
- return current;
967
- }
968
- if (shallowEqual(currentField.deps, fieldInCache.deps)) {
969
- return fieldInCache.value;
970
- }
818
+ var current = currentField.get();
819
+ var fieldInCache = cache.cacheFields[propertyName];
820
+ if (!currentField.deps || fieldInCache == null) {
971
821
  cacheFields[propertyName] = {
972
822
  getter,
973
823
  value: current,
@@ -975,471 +825,652 @@
975
825
  };
976
826
  return current;
977
827
  }
978
- };
979
- cacheFields[propertyName] = {
980
- getter,
981
- value: field2.value,
982
- deps: field2.deps
983
- };
984
- collect(propertyName, getter);
985
- return getter;
828
+ if (shallowEqual(currentField.deps, fieldInCache.deps)) {
829
+ return fieldInCache.value;
830
+ }
831
+ cacheFields[propertyName] = {
832
+ getter,
833
+ value: current,
834
+ deps: currentField.deps
835
+ };
836
+ return current;
837
+ }
838
+ };
839
+ cacheFields[propertyName] = {
840
+ getter,
841
+ value: field2.value,
842
+ deps: field2.deps
843
+ };
844
+ return getter;
845
+ }
846
+ function wrapToActionMethod(cache, methodName) {
847
+ var cacheMethods = cache.cacheMethods;
848
+ var cachedMethod = cacheMethods[methodName];
849
+ if (typeof cachedMethod === "function") {
850
+ return cachedMethod;
986
851
  }
987
- function extractInstance(updater, wrapper, cache, opts) {
988
- var onGet = (opts || {}).onGet;
852
+ var actionMethod = function actionMethod2() {
853
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
854
+ args[_key] = arguments[_key];
855
+ }
856
+ var target = cache.target;
857
+ var method2 = target[methodName];
858
+ if (typeof method2 !== "function") {
859
+ throw new Error("Can not change methods in runtime.");
860
+ }
861
+ return method2.apply(void 0, _to_consumable_array(args));
862
+ };
863
+ cacheMethods[methodName] = actionMethod;
864
+ return actionMethod;
865
+ }
866
+ var cacheProperties = function(cache, onGet) {
867
+ return function createCachePropertiesProxy() {
868
+ var instance = cache.target;
869
+ var properties = Object.getOwnPropertyNames(instance);
989
870
  var handleGetter = function handleGetter2(key, value) {
990
871
  if (!onGet) {
991
872
  return;
992
873
  }
993
874
  onGet(key, value);
994
875
  };
995
- var instance = updater.instance;
996
- if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object" || !instance) {
997
- throw new Error("The instance should be an object or array.");
998
- }
999
- var properties = Object.getOwnPropertyNames(instance);
1000
- var proxiedInstance = createProxy(instance, {
876
+ return createProxy(instance, {
1001
877
  get: function get(target, p) {
1002
878
  var value = target[p];
1003
879
  if (typeof value === "function" && properties.indexOf(p) >= 0) {
1004
- var actionMethod = wrapToActionMethod2(updater, p);
880
+ var actionMethod = wrapToActionMethod(cache, p);
1005
881
  Object.assign(actionMethod, value);
882
+ handleGetter(p, actionMethod);
1006
883
  return actionMethod;
1007
884
  }
1008
- return wrapToField2(updater, p, value);
885
+ return wrapToField(cache, p, value, handleGetter);
1009
886
  },
1010
887
  set: function set() {
1011
888
  return false;
1012
889
  }
1013
890
  });
1014
- function generateInstance() {
1015
- return proxiedInstance;
891
+ };
892
+ };
893
+
894
+ // src/store/instance.ts
895
+ function createField(callback, deps) {
896
+ var currentDeps = function computeDeps() {
897
+ if (deps == null) {
898
+ return deps;
1016
899
  }
1017
- if (wrapper == null) {
1018
- return proxiedInstance;
900
+ if (deps.some(function(d) {
901
+ return cacheIdentify.field(d) && d.deps == null;
902
+ })) {
903
+ return void 0;
1019
904
  }
1020
- var wrapped = wrapper(generateInstance);
1021
- if ((typeof wrapped === "undefined" ? "undefined" : _type_of(wrapped)) === "object" && wrapped != null) {
1022
- return cacheProperties(_object_spread_props(_object_spread({}, cache), {
1023
- target: wrapped
1024
- }), handleGetter)();
905
+ return deps.flatMap(function(d) {
906
+ if (cacheIdentify.field(d)) {
907
+ return d.deps;
908
+ }
909
+ return d;
910
+ });
911
+ }();
912
+ var value = callback();
913
+ return {
914
+ callback,
915
+ deps: currentDeps,
916
+ identifier: cacheIdentify.field,
917
+ value,
918
+ get: function get() {
919
+ return value;
920
+ }
921
+ };
922
+ }
923
+ function createMethod(method2) {
924
+ var replace = function replace2() {
925
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
926
+ args[_key] = arguments[_key];
1025
927
  }
1026
- return wrapped;
928
+ return method2.apply(void 0, _to_consumable_array(args));
929
+ };
930
+ replace.identifier = cacheIdentify.method;
931
+ return replace;
932
+ }
933
+ function wrapToActionMethod2(updater, methodName) {
934
+ var cacheMethods = updater.cacheMethods;
935
+ var cachedMethod = cacheMethods[methodName];
936
+ if (typeof cachedMethod === "function") {
937
+ return cachedMethod;
1027
938
  }
1028
-
1029
- // src/store/enhance/signal.ts
1030
- function createSignal(store) {
1031
- var signalStore = {
1032
- collection: {},
1033
- started: false,
1034
- enabled: false
1035
- };
1036
- var propertiesCache = {
1037
- target: store.getInstance(),
1038
- cacheFields: {},
1039
- cacheMethods: {}
1040
- };
1041
- var enhance = function(dispatcher) {
1042
- return function(action) {
1043
- if (!signalStore.enabled) {
1044
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher(action);
1045
- return;
1046
- }
1047
- var collection = signalStore.collection;
1048
- if (collection == null) {
1049
- return;
1050
- }
1051
- var storeInstance = extractInstance(store.updater, store.key.wrapper, propertiesCache);
1052
- var keys = Object.keys(collection);
1053
- if (!keys.length) {
1054
- return;
1055
- }
1056
- var hasChange = keys.some(function(key) {
1057
- var field2 = storeInstance[key];
1058
- var collectedField = collection[key];
1059
- if (cacheIdentify.field(field2) && cacheIdentify.field(collectedField)) {
1060
- return field2.get() !== collectedField.get();
1061
- }
1062
- return field2 !== collectedField;
1063
- });
1064
- if (hasChange) {
1065
- dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher(action);
1066
- }
1067
- };
939
+ var actionMethod = function actionMethod2() {
940
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
941
+ args[_key] = arguments[_key];
942
+ }
943
+ var instance = updater.instance;
944
+ var method2 = instance[methodName];
945
+ if (typeof method2 !== "function") {
946
+ throw new Error("Can not change methods in runtime.");
947
+ }
948
+ if (cacheIdentify.method(method2)) {
949
+ return method2.apply(void 0, _to_consumable_array(args));
950
+ }
951
+ var state = method2.apply(void 0, _to_consumable_array(args));
952
+ var action = {
953
+ type: methodName,
954
+ state,
955
+ prevState: updater.state,
956
+ instance: updater.instance,
957
+ prevInstance: updater.instance,
958
+ method: actionMethod2
1068
959
  };
1069
- var storeKey = store.key;
1070
- return {
1071
- key: storeKey,
1072
- getToken: function getToken() {
1073
- return store.getToken();
1074
- },
1075
- subscribe: function subscribe(dispatcher) {
1076
- return store.subscribe(enhance(dispatcher));
1077
- },
1078
- getSignal: function getSignal() {
1079
- var collectUsedFields = function collectUsedFields2(key, val) {
1080
- if (!signalStore.started) {
1081
- return;
1082
- }
1083
- signalStore.collection[key] = val;
1084
- };
1085
- var getInstance = function getInstance2(options) {
1086
- var cutOff = (options !== null && options !== void 0 ? options : {}).cutOff;
1087
- return extractInstance(store.updater, store.key.wrapper, propertiesCache, {
1088
- onGet: cutOff ? void 0 : collectUsedFields
1089
- });
1090
- };
1091
- var signal = function signal2(options) {
1092
- return getInstance(options);
1093
- };
1094
- signal.startStatistics = function startStatistics() {
1095
- signalStore.started = true;
1096
- signalStore.collection = {};
1097
- };
1098
- signal.stopStatistics = function stopStatistics() {
1099
- signalStore.started = false;
1100
- };
1101
- signal.subscribe = function subscribe(dispatchCallback) {
1102
- return store.subscribe(dispatchCallback);
960
+ updater.notify(action);
961
+ return state;
962
+ };
963
+ cacheMethods[methodName] = actionMethod;
964
+ return actionMethod;
965
+ }
966
+ function wrapToField2(updater, propertyName, value, onGot) {
967
+ function collect(pName, v) {
968
+ if (onGot) {
969
+ onGot(pName, v);
970
+ }
971
+ }
972
+ var cacheFields = updater.cacheFields;
973
+ if (!cacheIdentify.field(value)) {
974
+ collect(propertyName, value);
975
+ return value;
976
+ }
977
+ var field2 = value;
978
+ var cachedField = cacheFields[propertyName];
979
+ if (cachedField && (field2.deps && shallowEqual(cachedField.deps, field2.deps) || !field2.deps && cachedField.value === field2.value)) {
980
+ var cacheFieldGetter = cachedField.getter;
981
+ collect(propertyName, cacheFieldGetter);
982
+ return cacheFieldGetter;
983
+ }
984
+ var getter = {
985
+ get: function get() {
986
+ var currentField = updater.instance[propertyName];
987
+ if (!cacheIdentify.field(currentField)) {
988
+ throw new Error("Field should always be field.");
989
+ }
990
+ var current = currentField.get();
991
+ var fieldInCache = updater.cacheFields[propertyName];
992
+ if (!currentField.deps || fieldInCache == null) {
993
+ cacheFields[propertyName] = {
994
+ getter,
995
+ value: current,
996
+ deps: currentField.deps
1103
997
  };
1104
- signal.store = store;
1105
- signalStore.enabled = true;
1106
- signalStore.started = true;
1107
- return signal;
998
+ return current;
1108
999
  }
1109
- };
1000
+ if (shallowEqual(currentField.deps, fieldInCache.deps)) {
1001
+ return fieldInCache.value;
1002
+ }
1003
+ cacheFields[propertyName] = {
1004
+ getter,
1005
+ value: current,
1006
+ deps: currentField.deps
1007
+ };
1008
+ return current;
1009
+ }
1010
+ };
1011
+ cacheFields[propertyName] = {
1012
+ getter,
1013
+ value: field2.value,
1014
+ deps: field2.deps
1015
+ };
1016
+ collect(propertyName, getter);
1017
+ return getter;
1018
+ }
1019
+ function extractInstance(updater, wrapper, cache, opts) {
1020
+ var onGet = (opts || {}).onGet;
1021
+ var handleGetter = function handleGetter2(key, value) {
1022
+ if (!onGet) {
1023
+ return;
1024
+ }
1025
+ onGet(key, value);
1026
+ };
1027
+ var instance = updater.instance;
1028
+ if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object" || !instance) {
1029
+ throw new Error("The instance should be an object or array.");
1030
+ }
1031
+ var properties = Object.getOwnPropertyNames(instance);
1032
+ var proxiedInstance = createProxy(instance, {
1033
+ get: function get(target, p) {
1034
+ var value = target[p];
1035
+ if (typeof value === "function" && properties.indexOf(p) >= 0) {
1036
+ var actionMethod = wrapToActionMethod2(updater, p);
1037
+ Object.assign(actionMethod, value);
1038
+ return actionMethod;
1039
+ }
1040
+ return wrapToField2(updater, p, value);
1041
+ },
1042
+ set: function set() {
1043
+ return false;
1044
+ }
1045
+ });
1046
+ function generateInstance() {
1047
+ return proxiedInstance;
1048
+ }
1049
+ if (wrapper == null) {
1050
+ return proxiedInstance;
1051
+ }
1052
+ var wrapped = wrapper(generateInstance);
1053
+ if ((typeof wrapped === "undefined" ? "undefined" : _type_of(wrapped)) === "object" && wrapped != null) {
1054
+ return cacheProperties(_object_spread_props(_object_spread({}, cache), {
1055
+ target: wrapped
1056
+ }), handleGetter)();
1110
1057
  }
1058
+ return wrapped;
1059
+ }
1111
1060
 
1112
- // src/store/enhance/selector.ts
1113
- function createSelector(store, opts) {
1114
- var equality = (opts !== null && opts !== void 0 ? opts : {}).equality;
1115
- var selectStore = {
1116
- selectedInstance: store.getInstance()
1117
- };
1118
- var cache = {
1119
- equality,
1120
- setSelect: function setSelect(selector) {
1121
- cache.selector = selector;
1122
- if (!selector) {
1123
- return;
1124
- }
1125
- var currentSelectedInstance = selectStore.selectedInstance;
1126
- var nextSelectedInstance = selector(store.getInstance);
1127
- if (currentSelectedInstance === nextSelectedInstance || equality && equality(currentSelectedInstance, nextSelectedInstance)) {
1128
- return;
1129
- }
1130
- selectStore.selectedInstance = nextSelectedInstance;
1061
+ // src/store/enhance/signal.ts
1062
+ function createSignal(store) {
1063
+ var signalStore = {
1064
+ collection: {},
1065
+ started: false,
1066
+ enabled: false
1067
+ };
1068
+ var propertiesCache = {
1069
+ target: store.getInstance(),
1070
+ cacheFields: {},
1071
+ cacheMethods: {}
1072
+ };
1073
+ var enhance = function(dispatcher) {
1074
+ return function(action) {
1075
+ if (!signalStore.enabled) {
1076
+ dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher(action);
1077
+ return;
1131
1078
  }
1132
- };
1133
- var generateSelectedInstance = function generateSelectedInstance2(getInstance) {
1134
- if (cache.selector) {
1135
- return cache.selector(getInstance);
1079
+ var collection = signalStore.collection;
1080
+ if (collection == null) {
1081
+ return;
1136
1082
  }
1137
- return getInstance();
1138
- };
1139
- selectStore.selectedInstance = generateSelectedInstance(store.getInstance);
1140
- var enhance = function(dispatcher) {
1141
- return function(action) {
1142
- var currentSelectedInstance = selectStore.selectedInstance;
1143
- var nextSelectedInstance = generateSelectedInstance(store.getInstance);
1144
- if (currentSelectedInstance === nextSelectedInstance || cache.equality && cache.equality(currentSelectedInstance, nextSelectedInstance)) {
1145
- return;
1083
+ var storeInstance = extractInstance(store.updater, store.key.wrapper, propertiesCache);
1084
+ var keys = Object.keys(collection);
1085
+ if (!keys.length) {
1086
+ return;
1087
+ }
1088
+ var hasChange = keys.some(function(key) {
1089
+ var field2 = storeInstance[key];
1090
+ var collectedField = collection[key];
1091
+ if (cacheIdentify.field(field2) && cacheIdentify.field(collectedField)) {
1092
+ return field2.get() !== collectedField.get();
1146
1093
  }
1147
- selectStore.selectedInstance = nextSelectedInstance;
1148
- if (dispatcher == null) {
1094
+ return field2 !== collectedField;
1095
+ });
1096
+ if (hasChange) {
1097
+ dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher(action);
1098
+ }
1099
+ };
1100
+ };
1101
+ var storeKey = store.key;
1102
+ return {
1103
+ key: storeKey,
1104
+ getToken: function getToken() {
1105
+ return store.getToken();
1106
+ },
1107
+ subscribe: function subscribe(dispatcher) {
1108
+ return store.subscribe(enhance(dispatcher));
1109
+ },
1110
+ getSignal: function getSignal() {
1111
+ var collectUsedFields = function collectUsedFields2(key, val) {
1112
+ if (!signalStore.started) {
1149
1113
  return;
1150
1114
  }
1151
- dispatcher(action);
1115
+ signalStore.collection[key] = val;
1152
1116
  };
1153
- };
1154
- function select(selector) {
1155
- cache.setSelect(selector);
1156
- return selectStore.selectedInstance;
1117
+ var getInstance = function getInstance2(options) {
1118
+ var cutOff = (options !== null && options !== void 0 ? options : {}).cutOff;
1119
+ return extractInstance(store.updater, store.key.wrapper, propertiesCache, {
1120
+ onGet: cutOff ? void 0 : collectUsedFields
1121
+ });
1122
+ };
1123
+ var signal = function signal2(options) {
1124
+ return getInstance(options);
1125
+ };
1126
+ signal.startStatistics = function startStatistics() {
1127
+ signalStore.started = true;
1128
+ signalStore.collection = {};
1129
+ };
1130
+ signal.stopStatistics = function stopStatistics() {
1131
+ signalStore.started = false;
1132
+ };
1133
+ signal.subscribe = function subscribe(dispatchCallback) {
1134
+ return store.subscribe(dispatchCallback);
1135
+ };
1136
+ signal.store = store;
1137
+ signalStore.enabled = true;
1138
+ signalStore.started = true;
1139
+ return signal;
1157
1140
  }
1158
- return {
1159
- key: store.key,
1160
- getToken: function getToken() {
1161
- return store.getToken();
1162
- },
1163
- subscribe: function subscribe(dispatcher) {
1164
- return store.subscribe(enhance(dispatcher));
1165
- },
1166
- select
1167
- };
1168
- }
1141
+ };
1142
+ }
1169
1143
 
1170
- // src/store/index.ts
1171
- function createPrimaryKey(modelFn) {
1172
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1173
- var ifModelKey = isModelKey(modelFn);
1174
- var ifModelUsage = isModelUsage(modelFn);
1175
- var model2 = ifModelKey ? modelFn.source : modelFn;
1176
- var _config_wrapper;
1177
- var wrapper = (_config_wrapper = config2.wrapper) !== null && _config_wrapper !== void 0 ? _config_wrapper : ifModelKey || ifModelUsage ? modelFn.wrapper : function defaultSelector(i) {
1178
- return i();
1179
- };
1180
- var wrapModel = function wrapModel2(state) {
1181
- return model2(state);
1182
- };
1183
- wrapModel.source = model2;
1184
- wrapModel.wrapper = wrapper;
1185
- wrapModel.modelKeyIdentifier = modelKeyIdentifier;
1186
- if ("state" in config2) {
1187
- wrapModel.defaultState = config2.state;
1144
+ // src/store/enhance/selector.ts
1145
+ function createSelector(store, opts) {
1146
+ var equality = (opts !== null && opts !== void 0 ? opts : {}).equality;
1147
+ var selectStore = {
1148
+ selectedInstance: store.getInstance()
1149
+ };
1150
+ var cache = {
1151
+ equality,
1152
+ setSelect: function setSelect(selector) {
1153
+ cache.selector = selector;
1154
+ if (!selector) {
1155
+ return;
1156
+ }
1157
+ var currentSelectedInstance = selectStore.selectedInstance;
1158
+ var nextSelectedInstance = selector(store.getInstance);
1159
+ if (currentSelectedInstance === nextSelectedInstance || equality && equality(currentSelectedInstance, nextSelectedInstance)) {
1160
+ return;
1161
+ }
1162
+ selectStore.selectedInstance = nextSelectedInstance;
1188
1163
  }
1189
- return wrapModel;
1190
- }
1191
- function createStore(modelLike) {
1192
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1193
- var ifModelKey = isModelKey(modelLike);
1194
- var model2 = ifModelKey ? modelLike.source : modelLike;
1195
- var modelKey = ifModelKey ? modelLike : void 0;
1196
- var conf = function computeConfig() {
1197
- var hasConfigState = "state" in config2;
1198
- var hasKeyState = !!modelKey && "defaultState" in modelKey;
1199
- if (hasConfigState) {
1200
- return config2;
1164
+ };
1165
+ var generateSelectedInstance = function generateSelectedInstance2(getInstance) {
1166
+ if (cache.selector) {
1167
+ return cache.selector(getInstance);
1168
+ }
1169
+ return getInstance();
1170
+ };
1171
+ selectStore.selectedInstance = generateSelectedInstance(store.getInstance);
1172
+ var enhance = function(dispatcher) {
1173
+ return function(action) {
1174
+ var currentSelectedInstance = selectStore.selectedInstance;
1175
+ var nextSelectedInstance = generateSelectedInstance(store.getInstance);
1176
+ if (currentSelectedInstance === nextSelectedInstance || cache.equality && cache.equality(currentSelectedInstance, nextSelectedInstance)) {
1177
+ return;
1201
1178
  }
1202
- if (hasKeyState) {
1203
- return _object_spread_props(_object_spread({}, config2), {
1204
- state: modelKey === null || modelKey === void 0 ? void 0 : modelKey.defaultState
1205
- });
1179
+ selectStore.selectedInstance = nextSelectedInstance;
1180
+ if (dispatcher == null) {
1181
+ return;
1206
1182
  }
1207
- return config2;
1208
- }();
1209
- var combinedMiddleWare = function combinedMiddleWare2(s) {
1210
- return function updaterMiddleWare(next) {
1211
- var middleWares = conf.middleWares;
1212
- if (middleWares == null) {
1213
- return next;
1214
- }
1215
- var updateMiddleWares = _to_consumable_array(middleWares).reverse().map(function(middleWare) {
1216
- return middleWare(s);
1217
- });
1218
- return updateMiddleWares.reduce(function(finalDispatcher, um) {
1219
- return um(finalDispatcher);
1220
- }, next);
1221
- };
1222
- };
1223
- var updater = createUpdater(model2, combinedMiddleWare, conf);
1224
- var key = modelKey !== null && modelKey !== void 0 ? modelKey : createPrimaryKey(model2, config2);
1225
- var propertiesCache = {
1226
- target: updater.instance,
1227
- cacheFields: {},
1228
- cacheMethods: {}
1229
- };
1230
- var store = {
1231
- key,
1232
- getToken: function getToken() {
1233
- return updater.token;
1234
- },
1235
- subscribe: function subscribe(dispatcher) {
1236
- var _updater_createTunnel = updater.createTunnel(dispatcher || noop), connect = _updater_createTunnel.connect, disconnect = _updater_createTunnel.disconnect;
1237
- connect();
1238
- return disconnect;
1239
- },
1240
- getInstance: function getInstance() {
1241
- return extractInstance(updater, key.wrapper, propertiesCache);
1242
- },
1243
- getStoreInstance: function getStoreInstance() {
1244
- return extractInstance(updater, void 0, propertiesCache);
1245
- },
1246
- update: function update(args) {
1247
- var updateArgs = args !== null && args !== void 0 ? args : {};
1248
- if (updateArgs.key) {
1249
- var updatingKey = updateArgs.key, updatingModel = updateArgs.model, rest = _object_without_properties(updateArgs, [
1250
- "key",
1251
- "model"
1252
- ]);
1253
- updater.update(_object_spread_props(_object_spread({}, rest), {
1254
- model: updatingKey.source
1255
- }));
1256
- store.key = updatingKey;
1257
- return;
1258
- }
1259
- if (updateArgs.model) {
1260
- var updatingKey1 = updateArgs.key, updatingModel1 = updateArgs.model, rest1 = _object_without_properties(updateArgs, [
1261
- "key",
1262
- "model"
1263
- ]);
1264
- updater.update(_object_spread_props(_object_spread({}, rest1), {
1265
- model: updatingModel1
1266
- }));
1267
- store.key = createPrimaryKey(updatingModel1, config2);
1268
- return;
1269
- }
1270
- updater.update(args);
1271
- },
1272
- destroy: function destroy2() {
1273
- updater.destroy();
1274
- },
1275
- payload: function payload(callback) {
1276
- return updater.payload(callback);
1277
- },
1278
- isDestroyed: function isDestroyed() {
1279
- return updater.isDestroyed;
1280
- },
1281
- extends: function _extends(e) {
1282
- return Object.assign(store, e);
1283
- },
1284
- updater,
1285
- modelStoreIdentifier
1183
+ dispatcher(action);
1286
1184
  };
1287
- return store;
1185
+ };
1186
+ function select(selector) {
1187
+ cache.setSelect(selector);
1188
+ return selectStore.selectedInstance;
1288
1189
  }
1289
- var createField2 = createField;
1290
- var createMethod2 = createMethod;
1190
+ return {
1191
+ key: store.key,
1192
+ getToken: function getToken() {
1193
+ return store.getToken();
1194
+ },
1195
+ subscribe: function subscribe(dispatcher) {
1196
+ return store.subscribe(enhance(dispatcher));
1197
+ },
1198
+ select
1199
+ };
1200
+ }
1291
1201
 
1292
- // src/key/index.ts
1293
- function createKey(model2) {
1294
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1295
- var wrapModel = createPrimaryKey(model2, config2);
1296
- wrapModel.createStore = function createKeyStore() {
1297
- var storeConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1298
- return createStore(wrapModel, _object_spread({}, config2, storeConfig));
1299
- };
1300
- wrapModel.extends = function extendsKey(e) {
1301
- return Object.assign(wrapModel, e);
1302
- };
1303
- return wrapModel;
1202
+ // src/store/index.ts
1203
+ function createPrimaryKey(modelFn) {
1204
+ var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1205
+ var ifModelKey = isModelKey(modelFn);
1206
+ var ifModelUsage = isModelUsage(modelFn);
1207
+ var model2 = ifModelKey ? modelFn.source : modelFn;
1208
+ var _config_wrapper;
1209
+ var wrapper = (_config_wrapper = config2.wrapper) !== null && _config_wrapper !== void 0 ? _config_wrapper : ifModelKey || ifModelUsage ? modelFn.wrapper : function defaultSelector(i) {
1210
+ return i();
1211
+ };
1212
+ var wrapModel = function wrapModel2(state) {
1213
+ return model2(state);
1214
+ };
1215
+ wrapModel.source = model2;
1216
+ wrapModel.wrapper = wrapper;
1217
+ wrapModel.modelKeyIdentifier = modelKeyIdentifier;
1218
+ if ("state" in config2) {
1219
+ wrapModel.defaultState = config2.state;
1304
1220
  }
1305
- createKey.isModelKey = isModelKey;
1306
- function createStores(modelKeys) {
1307
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1308
- var state = {
1309
- destroyed: false
1221
+ return wrapModel;
1222
+ }
1223
+ function createStore(modelLike) {
1224
+ var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1225
+ var ifModelKey = isModelKey(modelLike);
1226
+ var model2 = ifModelKey ? modelLike.source : modelLike;
1227
+ var modelKey = ifModelKey ? modelLike : void 0;
1228
+ var conf = function computeConfig() {
1229
+ var hasConfigState = "state" in config2;
1230
+ var hasKeyState = !!modelKey && "defaultState" in modelKey;
1231
+ if (hasConfigState) {
1232
+ return config2;
1233
+ }
1234
+ if (hasKeyState) {
1235
+ return _object_spread_props(_object_spread({}, config2), {
1236
+ state: modelKey === null || modelKey === void 0 ? void 0 : modelKey.defaultState
1237
+ });
1238
+ }
1239
+ return config2;
1240
+ }();
1241
+ var combinedMiddleWare = function combinedMiddleWare2(s) {
1242
+ return function updaterMiddleWare(next) {
1243
+ var middleWares = conf.middleWares;
1244
+ if (middleWares == null) {
1245
+ return next;
1246
+ }
1247
+ var updateMiddleWares = _to_consumable_array(middleWares).reverse().map(function(middleWare) {
1248
+ return middleWare(s);
1249
+ });
1250
+ return updateMiddleWares.reduce(function(finalDispatcher, um) {
1251
+ return um(finalDispatcher);
1252
+ }, next);
1310
1253
  };
1311
- var storeUnits = modelKeys.map(function(modelKey) {
1312
- if (typeof modelKey === "function") {
1313
- return modelKey.createStore();
1254
+ };
1255
+ var updater = createUpdater(model2, combinedMiddleWare, conf);
1256
+ var key = modelKey !== null && modelKey !== void 0 ? modelKey : createPrimaryKey(model2, config2);
1257
+ var propertiesCache = {
1258
+ target: updater.instance,
1259
+ cacheFields: {},
1260
+ cacheMethods: {}
1261
+ };
1262
+ var store = {
1263
+ key,
1264
+ getToken: function getToken() {
1265
+ return updater.token;
1266
+ },
1267
+ subscribe: function subscribe(dispatcher) {
1268
+ var _updater_createTunnel = updater.createTunnel(dispatcher || noop), connect = _updater_createTunnel.connect, disconnect = _updater_createTunnel.disconnect;
1269
+ connect();
1270
+ return disconnect;
1271
+ },
1272
+ getInstance: function getInstance() {
1273
+ return extractInstance(updater, key.wrapper, propertiesCache);
1274
+ },
1275
+ getStoreInstance: function getStoreInstance() {
1276
+ return extractInstance(updater, void 0, propertiesCache);
1277
+ },
1278
+ update: function update(args) {
1279
+ var updateArgs = args !== null && args !== void 0 ? args : {};
1280
+ if (updateArgs.key) {
1281
+ var updatingKey = updateArgs.key, updatingModel = updateArgs.model, rest = _object_without_properties(updateArgs, [
1282
+ "key",
1283
+ "model"
1284
+ ]);
1285
+ updater.update(_object_spread_props(_object_spread({}, rest), {
1286
+ model: updatingKey.source
1287
+ }));
1288
+ store.key = updatingKey;
1289
+ return;
1314
1290
  }
1315
- var k = modelKey.key;
1316
- return createStore(k, "defaultState" in k ? _object_spread_props(_object_spread({}, config2), {
1317
- state: k.defaultState
1318
- }) : config2);
1319
- });
1320
- return {
1321
- find: function find(key) {
1322
- var found = storeUnits.find(function(c) {
1323
- if (typeof key === "function") {
1324
- return c.key === key;
1325
- }
1326
- return c.key === key.key;
1327
- });
1328
- if (!found) {
1329
- return null;
1330
- }
1331
- return found;
1332
- },
1333
- update: function update() {
1334
- for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
1335
- keys[_key] = arguments[_key];
1291
+ if (updateArgs.model) {
1292
+ var updatingKey1 = updateArgs.key, updatingModel1 = updateArgs.model, rest1 = _object_without_properties(updateArgs, [
1293
+ "key",
1294
+ "model"
1295
+ ]);
1296
+ updater.update(_object_spread_props(_object_spread({}, rest1), {
1297
+ model: updatingModel1
1298
+ }));
1299
+ store.key = createPrimaryKey(updatingModel1, config2);
1300
+ return;
1301
+ }
1302
+ updater.update(args);
1303
+ },
1304
+ destroy: function destroy2() {
1305
+ updater.destroy();
1306
+ },
1307
+ payload: function payload(callback) {
1308
+ return updater.payload(callback);
1309
+ },
1310
+ isDestroyed: function isDestroyed() {
1311
+ return updater.isDestroyed;
1312
+ },
1313
+ extends: function _extends(e) {
1314
+ return Object.assign(store, e);
1315
+ },
1316
+ updater,
1317
+ modelStoreIdentifier
1318
+ };
1319
+ return store;
1320
+ }
1321
+ var createField2 = createField;
1322
+ var createMethod2 = createMethod;
1323
+
1324
+ // src/key/index.ts
1325
+ function createKey(model2) {
1326
+ var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1327
+ var wrapModel = createPrimaryKey(model2, config2);
1328
+ wrapModel.createStore = function createKeyStore() {
1329
+ var storeConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1330
+ return createStore(wrapModel, _object_spread({}, config2, storeConfig));
1331
+ };
1332
+ wrapModel.extends = function extendsKey(e) {
1333
+ return Object.assign(wrapModel, e);
1334
+ };
1335
+ return wrapModel;
1336
+ }
1337
+ createKey.isModelKey = isModelKey;
1338
+ function createStores(modelKeys) {
1339
+ var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1340
+ var state = {
1341
+ destroyed: false
1342
+ };
1343
+ var storeUnits = modelKeys.map(function(modelKey) {
1344
+ if (typeof modelKey === "function") {
1345
+ return modelKey.createStore();
1346
+ }
1347
+ var k = modelKey.key;
1348
+ return createStore(k, "defaultState" in k ? _object_spread_props(_object_spread({}, config2), {
1349
+ state: k.defaultState
1350
+ }) : config2);
1351
+ });
1352
+ return {
1353
+ find: function find(key) {
1354
+ var found = storeUnits.find(function(c) {
1355
+ if (typeof key === "function") {
1356
+ return c.key === key;
1336
1357
  }
1337
- if (state.destroyed) {
1358
+ return c.key === key.key;
1359
+ });
1360
+ if (!found) {
1361
+ return null;
1362
+ }
1363
+ return found;
1364
+ },
1365
+ update: function update() {
1366
+ for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
1367
+ keys[_key] = arguments[_key];
1368
+ }
1369
+ if (state.destroyed) {
1370
+ return;
1371
+ }
1372
+ storeUnits.forEach(function(un, i) {
1373
+ var keyLike = keys[i];
1374
+ if (!keyLike) {
1338
1375
  return;
1339
1376
  }
1340
- storeUnits.forEach(function(un, i) {
1341
- var keyLike = keys[i];
1342
- if (!keyLike) {
1343
- return;
1344
- }
1345
- var ifIsModelKey = validations.isModelKey(keyLike);
1346
- var key = ifIsModelKey ? keyLike : keyLike.key;
1347
- un.update({
1348
- key
1349
- });
1350
- });
1351
- },
1352
- keys: function keys() {
1353
- return storeUnits.map(function(param) {
1354
- var key = param.key;
1355
- return key;
1377
+ var ifIsModelKey = validations.isModelKey(keyLike);
1378
+ var key = ifIsModelKey ? keyLike : keyLike.key;
1379
+ un.update({
1380
+ key
1356
1381
  });
1357
- },
1358
- destroy: function destroy2() {
1359
- storeUnits.forEach(function(unit) {
1360
- unit.destroy();
1361
- });
1362
- state.destroyed = true;
1363
- }
1364
- };
1365
- }
1382
+ });
1383
+ },
1384
+ keys: function keys() {
1385
+ return storeUnits.map(function(param) {
1386
+ var key = param.key;
1387
+ return key;
1388
+ });
1389
+ },
1390
+ destroy: function destroy2() {
1391
+ storeUnits.forEach(function(unit) {
1392
+ unit.destroy();
1393
+ });
1394
+ state.destroyed = true;
1395
+ }
1396
+ };
1397
+ }
1366
1398
 
1367
- // src/model/index.ts
1368
- function configModel(config2) {
1369
- var model2 = function model3(modelFn, wrapper) {
1370
- var currentSelector = wrapper !== null && wrapper !== void 0 ? wrapper : function defaultSelector(i) {
1371
- return i();
1372
- };
1373
- var modelWrapper = function modelWrapper2(state) {
1374
- return modelFn(state);
1375
- };
1376
- modelWrapper.produce = function produce(s) {
1377
- return model3(modelFn, s);
1378
- };
1379
- modelWrapper.createKey = function createModelKey(state) {
1380
- return createKey(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
1381
- state,
1382
- wrapper: currentSelector
1383
- }) : _object_spread_props(_object_spread({}, config2), {
1384
- wrapper: currentSelector
1385
- }));
1386
- };
1387
- modelWrapper.createStore = function createModelStore(state) {
1388
- return createStore(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
1389
- state,
1390
- wrapper: currentSelector
1391
- }) : _object_spread_props(_object_spread({}, config2), {
1392
- wrapper: currentSelector
1393
- }));
1394
- };
1395
- modelWrapper.extends = function extendsModelUsage(e) {
1396
- return Object.assign(modelWrapper, e);
1397
- };
1398
- modelWrapper.wrapper = currentSelector;
1399
- modelWrapper.modelUsageIdentifier = modelUsageIdentifier;
1400
- return modelWrapper;
1399
+ // src/model/index.ts
1400
+ function configModel(config2) {
1401
+ var model2 = function model3(modelFn, wrapper) {
1402
+ var currentSelector = wrapper !== null && wrapper !== void 0 ? wrapper : function defaultSelector(i) {
1403
+ return i();
1401
1404
  };
1402
- model2.createField = createField2;
1403
- model2.createMethod = createMethod2;
1404
- return model2;
1405
- }
1406
-
1407
- // src/index.ts
1408
- function config() {
1409
- var configuration = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1410
- var createStore3 = function createStore4(modelLike, state) {
1411
- return createStore(modelLike, arguments.length > 1 ? _object_spread_props(_object_spread({}, configuration), {
1412
- state
1413
- }) : configuration);
1405
+ var modelWrapper = function modelWrapper2(state) {
1406
+ return modelFn(state);
1414
1407
  };
1415
- var createKey3 = function createKey4(model3, state) {
1416
- var isKeySetState = arguments.length > 1;
1417
- var key = createKey(model3, isKeySetState ? _object_spread_props(_object_spread({}, configuration), {
1418
- state
1419
- }) : configuration);
1420
- key.createStore = function createKeyStore(s) {
1421
- return arguments.length > 0 ? createStore3(key, s) : createStore3(key);
1422
- };
1423
- return key;
1408
+ modelWrapper.produce = function produce(s) {
1409
+ return model3(modelFn, s);
1424
1410
  };
1425
- createKey3.isModelKey = createKey.isModelKey;
1426
- var createStores3 = function createStores4() {
1427
- for (var _len = arguments.length, modelKeys = new Array(_len), _key = 0; _key < _len; _key++) {
1428
- modelKeys[_key] = arguments[_key];
1429
- }
1430
- return createStores(modelKeys, configuration);
1411
+ modelWrapper.createKey = function createModelKey(state) {
1412
+ return createKey(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
1413
+ state,
1414
+ wrapper: currentSelector
1415
+ }) : _object_spread_props(_object_spread({}, config2), {
1416
+ wrapper: currentSelector
1417
+ }));
1431
1418
  };
1432
- var model2 = configModel(configuration);
1433
- return {
1434
- createStore: createStore3,
1435
- createKey: createKey3,
1436
- createStores: createStores3,
1437
- model: model2
1419
+ modelWrapper.createStore = function createModelStore(state) {
1420
+ return createStore(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
1421
+ state,
1422
+ wrapper: currentSelector
1423
+ }) : _object_spread_props(_object_spread({}, config2), {
1424
+ wrapper: currentSelector
1425
+ }));
1438
1426
  };
1439
- }
1440
- var _config = config();
1441
- var createStore2 = _config.createStore;
1442
- var createKey2 = _config.createKey;
1443
- var createStores2 = _config.createStores;
1444
- var model = _config.model;
1445
- })();
1427
+ modelWrapper.extends = function extendsModelUsage(e) {
1428
+ return Object.assign(modelWrapper, e);
1429
+ };
1430
+ modelWrapper.wrapper = currentSelector;
1431
+ modelWrapper.modelUsageIdentifier = modelUsageIdentifier;
1432
+ return modelWrapper;
1433
+ };
1434
+ model2.createField = createField2;
1435
+ model2.createMethod = createMethod2;
1436
+ return model2;
1437
+ }
1438
+
1439
+ // src/index.ts
1440
+ function config() {
1441
+ var configuration = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1442
+ var createStore3 = function createStore4(modelLike, state) {
1443
+ return createStore(modelLike, arguments.length > 1 ? _object_spread_props(_object_spread({}, configuration), {
1444
+ state
1445
+ }) : configuration);
1446
+ };
1447
+ var createKey3 = function createKey4(model3, state) {
1448
+ var isKeySetState = arguments.length > 1;
1449
+ var key = createKey(model3, isKeySetState ? _object_spread_props(_object_spread({}, configuration), {
1450
+ state
1451
+ }) : configuration);
1452
+ key.createStore = function createKeyStore(s) {
1453
+ return arguments.length > 0 ? createStore3(key, s) : createStore3(key);
1454
+ };
1455
+ return key;
1456
+ };
1457
+ createKey3.isModelKey = createKey.isModelKey;
1458
+ var createStores3 = function createStores4() {
1459
+ for (var _len = arguments.length, modelKeys = new Array(_len), _key = 0; _key < _len; _key++) {
1460
+ modelKeys[_key] = arguments[_key];
1461
+ }
1462
+ return createStores(modelKeys, configuration);
1463
+ };
1464
+ var model2 = configModel(configuration);
1465
+ return {
1466
+ createStore: createStore3,
1467
+ createKey: createKey3,
1468
+ createStores: createStores3,
1469
+ model: model2
1470
+ };
1471
+ }
1472
+ var _config = config();
1473
+ var createStore2 = _config.createStore;
1474
+ var createKey2 = _config.createKey;
1475
+ var createStores2 = _config.createStores;
1476
+ var model = _config.model;