as-model 0.3.4 → 0.4.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/README.md CHANGED
@@ -43,7 +43,9 @@ Create store:
43
43
  ```js
44
44
  // store.js
45
45
  import {counting} from './model';
46
- import {createStore} from 'as-model';
46
+ import {config} from 'as-model';
47
+
48
+ const {createStore} = config();
47
49
 
48
50
  // Create and initialize a model store.
49
51
  const store = createStore(counting, 0);
@@ -59,7 +61,9 @@ Create multiple stores:
59
61
 
60
62
  ```js
61
63
  import {counting} from './model';
62
- import {createKey, createStores} from 'as-model';
64
+ import {config} from 'as-model';
65
+
66
+ const {createKey, createStores} = config();
63
67
 
64
68
  // Create model key with initial state.
65
69
  const countingKey0 = createKey(counting, 0);
@@ -79,7 +83,9 @@ Use **model** API to create store or key.
79
83
 
80
84
  ```js
81
85
  import {counting} from './model';
82
- import {model} from 'as-model';
86
+ import {config} from 'as-model';
87
+
88
+ const {model} = config();
83
89
 
84
90
  const store = model(counting).createStore(0);
85
91
  const key = model(counting).createKey(0);
@@ -90,7 +96,9 @@ In typescript develop environment, `model` API can do a type check for making su
90
96
 
91
97
  ```js
92
98
  // ts
93
- import {model} from 'as-model';
99
+ import {config} from 'as-model';
100
+
101
+ const {model} = config();
94
102
 
95
103
  // The model api ensures every action method returns a same type value with model state.
96
104
  const counting = model((state: number)=>{
@@ -115,7 +123,9 @@ Subscribe store
115
123
 
116
124
  ```js
117
125
  import {counting} from './model';
118
- import {model} from 'as-model';
126
+ import {config} from 'as-model';
127
+
128
+ const {model} = config();
119
129
 
120
130
  const store = model(counting).createStore(0);
121
131
  const {getInstance} = store;
@@ -132,7 +142,9 @@ Want to use async operations?
132
142
 
133
143
  ```js
134
144
  import {counting} from './model';
135
- import {model, createSelector} from 'as-model';
145
+ import {config, createSelector} from 'as-model';
146
+
147
+ const {model} = config();
136
148
 
137
149
  const store = model(counting).select((getInstance)=>{
138
150
  const instance = getInstance();
@@ -163,7 +175,7 @@ select().count // 1
163
175
  Subscribe store in react hooks:
164
176
 
165
177
  ```js
166
- import {model, createStores} from 'as-model';
178
+ import {config} from 'as-model';
167
179
  import {
168
180
  createContext,
169
181
  useRef,
@@ -172,6 +184,8 @@ import {
172
184
  useContext
173
185
  } from 'react';
174
186
 
187
+ const {model, createStores} = config();
188
+
175
189
  // Local state management
176
190
  function useModel(modelFn, defaultState){
177
191
  // Use ref to persist the store object.
@@ -283,7 +297,33 @@ npm install as-model
283
297
 
284
298
  ## Simplify API
285
299
 
286
- ### createStore
300
+ ### config
301
+
302
+ ```js
303
+ function config(options):configAPI
304
+ ```
305
+
306
+ #### parameters
307
+
308
+ ##### options - (Optional) an object with the following properties:
309
+ * notify - (Optional) a callback function for noticing an action to every subscriber, it accepts a notifier function and an action as parameters.
310
+ * controlled - (Optional) a boolean state to tell as-model use controlled mode to output instance changes.
311
+ * middleWares - (Optional) a middleWare array for reproducing state or ignore actions.
312
+
313
+ #### return
314
+
315
+ All apis above except `createSignal` and `createSelector` API.
316
+
317
+ ```js
318
+ {
319
+ createStore: (modelFnOrKey, initialState?)=>store,
320
+ createKey: (modelFn, initialState?)=>key,
321
+ createStores: (...keys)=>stores,
322
+ model: (modelFn)=>ModelUsage
323
+ }
324
+ ```
325
+
326
+ ### config(...).createStore
287
327
 
288
328
  ```js
289
329
  function createStore(modelFnOrKey, initialState?):store
@@ -317,7 +357,7 @@ A store object with model key and methods. The store object has `getInstance` me
317
357
  }
318
358
  ```
319
359
 
320
- ### createKey
360
+ ### config(...).createKey
321
361
 
322
362
  ```js
323
363
  function createKey(modelFn, initialState?):key
@@ -340,7 +380,7 @@ A model key function with `createStore` method to create a store with the model
340
380
  }
341
381
  ```
342
382
 
343
- ### createStores
383
+ ### config(...).createStores
344
384
 
345
385
  ```js
346
386
  function createStores(...keys):StoreCollection
@@ -363,6 +403,32 @@ StoreCollection created by the model keys.
363
403
  }
364
404
  ```
365
405
 
406
+ ### config(...).model
407
+
408
+ ```js
409
+ function model(modelFn):ModelUsage
410
+ ```
411
+
412
+ #### parameters
413
+
414
+ * modelFn - a model function accepts a state parameter and returns an object with action methods.
415
+
416
+ #### return
417
+
418
+ ModelUsage object with `createStore`, `createKey` methods to create store, key for the model function, and `select` method to set a default selector function (Use `createSelector(store).select()` to select the default one).
419
+
420
+ **ModelUsage** structure:
421
+
422
+ ```js
423
+ {
424
+ createStore: (initialState?)=> store,
425
+ createKey: (initialState?)=> key,
426
+ select: (
427
+ selector:(getInstance:()=>Instance)=>Record<string, any>|Array<any>
428
+ )=>ModelUsage
429
+ }
430
+ ```
431
+
366
432
  ### createSignal
367
433
 
368
434
  ```js
@@ -432,59 +498,6 @@ function createSelector(store, opts?:SelectorOptions):SelectorStore
432
498
  }
433
499
  ```
434
500
 
435
-
436
- ### model
437
-
438
- ```js
439
- function model(modelFn):ModelUsage
440
- ```
441
-
442
- #### parameters
443
-
444
- * modelFn - a model function accepts a state parameter and returns an object with action methods.
445
-
446
- #### return
447
-
448
- ModelUsage object with `createStore`, `createKey` methods to create store, key for the model function, and `select` method to set a default selector function (Use `createSelector(store).select()` to select the default one).
449
-
450
- **ModelUsage** structure:
451
-
452
- ```js
453
- {
454
- createStore: (initialState?)=> store,
455
- createKey: (initialState?)=> key,
456
- select: (
457
- selector:(getInstance:()=>Instance)=>Record<string, any>|Array<any>
458
- )=>ModelUsage
459
- }
460
- ```
461
-
462
- ### config
463
-
464
- ```js
465
- function config(options):configAPI
466
- ```
467
-
468
- #### parameters
469
-
470
- ##### options - (Optional) an object with the following properties:
471
- * notify - (Optional) a callback function for noticing an action to every subscriber, it accepts a notifier function and an action as parameters.
472
- * controlled - (Optional) a boolean state to tell as-model use controlled mode to output instance changes.
473
- * middleWares - (Optional) a middleWare array for reproducing state or ignore actions.
474
-
475
- #### return
476
-
477
- All apis above except `createSignal` and `createSelector` API.
478
-
479
- ```js
480
- {
481
- createStore: (modelFnOrKey, initialState?)=>store,
482
- createKey: (modelFn, initialState?)=>key,
483
- createStores: (...keys)=>stores,
484
- model: (modelFn)=>ModelUsage
485
- }
486
- ```
487
-
488
501
  ### validations
489
502
 
490
503
  A validate callback collection object.
package/dist/index.js CHANGED
@@ -21,12 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  config: () => config,
24
- createKey: () => createKey2,
25
24
  createSelector: () => createSelector,
26
25
  createSignal: () => createSignal,
27
- createStore: () => createStore2,
28
- createStores: () => createStores2,
29
- model: () => model,
30
26
  shallowEqual: () => shallowEqual,
31
27
  validations: () => validations
32
28
  });
@@ -420,9 +416,9 @@ function generateNotifier(updater, middleWare) {
420
416
  });
421
417
  }
422
418
  var dispatch = function dispatch2(action) {
423
- var dispatches = updater.dispatches, controlled = updater.controlled, model2 = updater.model, config2 = updater.config;
419
+ var dispatches = updater.dispatches, controlled = updater.controlled, model = updater.model, config3 = updater.config;
424
420
  var state = action.state;
425
- var nextInstance = model2(state);
421
+ var nextInstance = model(state);
426
422
  var nextAction = _object_spread_props(_object_spread({}, action), {
427
423
  instance: nextInstance
428
424
  });
@@ -465,8 +461,8 @@ function generateNotifier(updater, middleWare) {
465
461
  throw errors[0];
466
462
  };
467
463
  try {
468
- if (typeof config2.notify === "function") {
469
- config2.notify(notifyAction, nextAction);
464
+ if (typeof config3.notify === "function") {
465
+ config3.notify(notifyAction, nextAction);
470
466
  } else {
471
467
  notifyActionWithErrorThrow(nextAction);
472
468
  }
@@ -667,7 +663,7 @@ function createUpdateFn(updater, middleWare) {
667
663
  var args = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
668
664
  updater.mutate(function(u, effect) {
669
665
  var _args_model;
670
- var model2 = (_args_model = args.model) !== null && _args_model !== void 0 ? _args_model : u.model;
666
+ var model = (_args_model = args.model) !== null && _args_model !== void 0 ? _args_model : u.model;
671
667
  var hasState = Object.prototype.hasOwnProperty.call(args, "state");
672
668
  var hasInitialState = Object.prototype.hasOwnProperty.call(args, "initialState");
673
669
  var state = hasState ? args.state : u.state;
@@ -675,11 +671,11 @@ function createUpdateFn(updater, middleWare) {
675
671
  var token = createToken();
676
672
  if (u.controlled) {
677
673
  var controlledState = hasInitialState && !hasState ? args.initialState : state;
678
- var instance = model2(controlledState);
674
+ var instance = model(controlledState);
679
675
  return _object_spread_props(_object_spread({}, u), {
680
676
  state: controlledState,
681
677
  instance,
682
- model: model2
678
+ model
683
679
  });
684
680
  }
685
681
  if (u.isDestroyed) {
@@ -690,31 +686,33 @@ function createUpdateFn(updater, middleWare) {
690
686
  }
691
687
  if (isInitialize) {
692
688
  var initialState = hasInitialState ? args.initialState : state;
693
- var instance1 = model2(initialState);
689
+ var instance1 = model(initialState);
694
690
  var initializedUpdater = createInitializedUpdater(u, middleWare);
695
691
  return _object_spread(_object_spread_props(_object_spread({}, u), {
696
- model: model2,
692
+ model,
697
693
  state: initialState,
698
694
  instance: instance1,
699
695
  initialized: true,
700
696
  token
701
697
  }), initializedUpdater);
702
698
  }
703
- if (Object.is(u.model, model2) && Object.is(u.state, state)) {
699
+ if (Object.is(u.model, model) && Object.is(u.state, state)) {
704
700
  return u;
705
701
  }
706
- effect(function(up) {
707
- up.notify({
708
- type: null,
709
- method: null,
710
- prevInstance: u.instance,
711
- instance: u.instance,
712
- prevState: u.state,
713
- state
702
+ if (!args.silence) {
703
+ effect(function(up) {
704
+ up.notify({
705
+ type: null,
706
+ method: null,
707
+ prevInstance: u.instance,
708
+ instance: u.instance,
709
+ prevState: u.state,
710
+ state
711
+ });
714
712
  });
715
- });
713
+ }
716
714
  return _object_spread_props(_object_spread({}, u), {
717
- model: model2,
715
+ model,
718
716
  initialized: true,
719
717
  cacheFields: {},
720
718
  cacheMethods: {}
@@ -723,18 +721,18 @@ function createUpdateFn(updater, middleWare) {
723
721
  };
724
722
  }
725
723
  var lazyModel = createNoStateModel();
726
- function createUpdater(model2, middleWare) {
727
- var config2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
728
- var hasDefaultState = "state" in config2;
729
- var controlled = config2.controlled, defaultState = config2.state;
730
- var defaultInstance = hasDefaultState ? model2(defaultState) : lazyModel(void 0);
724
+ function createUpdater(model, middleWare) {
725
+ var config3 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
726
+ var hasDefaultState = "state" in config3;
727
+ var controlled = config3.controlled, defaultState = config3.state;
728
+ var defaultInstance = hasDefaultState ? model(defaultState) : lazyModel(void 0);
731
729
  var unInitializedUpdater = createUnInitializedUpdater();
732
730
  var updater = _object_spread({
733
731
  sidePayload: void 0,
734
732
  version: 0,
735
733
  token: createToken(),
736
734
  isDestroyed: false,
737
- model: model2,
735
+ model,
738
736
  instance: defaultInstance,
739
737
  dispatch: null,
740
738
  dispatches: [],
@@ -745,7 +743,7 @@ function createUpdater(model2, middleWare) {
745
743
  initialized: hasDefaultState,
746
744
  controlled: !!controlled,
747
745
  isSubscribing: false,
748
- config: config2,
746
+ config: config3,
749
747
  payload: function payload(setter) {
750
748
  if (typeof setter === "function") {
751
749
  updater.sidePayload = setter(updater.sidePayload);
@@ -1222,42 +1220,42 @@ function createSelector(store, opts) {
1222
1220
 
1223
1221
  // src/store/index.ts
1224
1222
  function createPrimaryKey(modelFn) {
1225
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1223
+ var config3 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1226
1224
  var ifModelKey = isModelKey(modelFn);
1227
1225
  var ifModelUsage = isModelUsage(modelFn);
1228
- var model2 = ifModelKey ? modelFn.source : modelFn;
1226
+ var model = ifModelKey ? modelFn.source : modelFn;
1229
1227
  var _config_wrapper;
1230
- var wrapper = (_config_wrapper = config2.wrapper) !== null && _config_wrapper !== void 0 ? _config_wrapper : ifModelKey || ifModelUsage ? modelFn.wrapper : function defaultSelector2(i) {
1228
+ var wrapper = (_config_wrapper = config3.wrapper) !== null && _config_wrapper !== void 0 ? _config_wrapper : ifModelKey || ifModelUsage ? modelFn.wrapper : function defaultSelector2(i) {
1231
1229
  return i();
1232
1230
  };
1233
1231
  var wrapModel = function wrapModel2(state) {
1234
- return model2(state);
1232
+ return model(state);
1235
1233
  };
1236
- wrapModel.source = model2;
1234
+ wrapModel.source = model;
1237
1235
  wrapModel.wrapper = wrapper;
1238
1236
  wrapModel.modelKeyIdentifier = modelKeyIdentifier;
1239
- if ("state" in config2) {
1240
- wrapModel.defaultState = config2.state;
1237
+ if ("state" in config3) {
1238
+ wrapModel.defaultState = config3.state;
1241
1239
  }
1242
1240
  return wrapModel;
1243
1241
  }
1244
1242
  function createStore(modelLike) {
1245
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1243
+ var config3 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1246
1244
  var ifModelKey = isModelKey(modelLike);
1247
- var model2 = ifModelKey ? modelLike.source : modelLike;
1245
+ var model = ifModelKey ? modelLike.source : modelLike;
1248
1246
  var modelKey = ifModelKey ? modelLike : void 0;
1249
1247
  var conf = function computeConfig() {
1250
- var hasConfigState = "state" in config2;
1248
+ var hasConfigState = "state" in config3;
1251
1249
  var hasKeyState = !!modelKey && "defaultState" in modelKey;
1252
1250
  if (hasConfigState) {
1253
- return config2;
1251
+ return config3;
1254
1252
  }
1255
1253
  if (hasKeyState) {
1256
- return _object_spread_props(_object_spread({}, config2), {
1254
+ return _object_spread_props(_object_spread({}, config3), {
1257
1255
  state: modelKey === null || modelKey === void 0 ? void 0 : modelKey.defaultState
1258
1256
  });
1259
1257
  }
1260
- return config2;
1258
+ return config3;
1261
1259
  }();
1262
1260
  var combinedMiddleWare = function combinedMiddleWare2(s) {
1263
1261
  return function updaterMiddleWare(next) {
@@ -1273,8 +1271,8 @@ function createStore(modelLike) {
1273
1271
  }, next);
1274
1272
  };
1275
1273
  };
1276
- var updater = createUpdater(model2, combinedMiddleWare, conf);
1277
- var key = modelKey !== null && modelKey !== void 0 ? modelKey : createPrimaryKey(model2, config2);
1274
+ var updater = createUpdater(model, combinedMiddleWare, conf);
1275
+ var key = modelKey !== null && modelKey !== void 0 ? modelKey : createPrimaryKey(model, config3);
1278
1276
  var propertiesCache = {
1279
1277
  target: updater.instance,
1280
1278
  cacheFields: {},
@@ -1317,7 +1315,7 @@ function createStore(modelLike) {
1317
1315
  updater.update(_object_spread_props(_object_spread({}, rest1), {
1318
1316
  model: updatingModel1
1319
1317
  }));
1320
- store.key = createPrimaryKey(updatingModel1, config2);
1318
+ store.key = createPrimaryKey(updatingModel1, config3);
1321
1319
  return;
1322
1320
  }
1323
1321
  updater.update(args);
@@ -1343,12 +1341,12 @@ var createField2 = createField;
1343
1341
  var createMethod2 = createMethod;
1344
1342
 
1345
1343
  // src/key/index.ts
1346
- function createKey(model2) {
1347
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1348
- var wrapModel = createPrimaryKey(model2, config2);
1344
+ function createKey(model) {
1345
+ var config3 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1346
+ var wrapModel = createPrimaryKey(model, config3);
1349
1347
  wrapModel.createStore = function createKeyStore() {
1350
1348
  var storeConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1351
- return createStore(wrapModel, _object_spread({}, config2, storeConfig));
1349
+ return createStore(wrapModel, _object_spread({}, config3, storeConfig));
1352
1350
  };
1353
1351
  wrapModel.extends = function extendsKey(e) {
1354
1352
  return Object.assign(wrapModel, e);
@@ -1357,7 +1355,7 @@ function createKey(model2) {
1357
1355
  }
1358
1356
  createKey.isModelKey = isModelKey;
1359
1357
  function createStores(modelKeys) {
1360
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1358
+ var config3 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1361
1359
  var state = {
1362
1360
  destroyed: false
1363
1361
  };
@@ -1366,9 +1364,9 @@ function createStores(modelKeys) {
1366
1364
  return modelKey.createStore();
1367
1365
  }
1368
1366
  var k = typeof modelKey === "function" ? modelKey : modelKey.key;
1369
- return createStore(k, "defaultState" in k ? _object_spread_props(_object_spread({}, config2), {
1367
+ return createStore(k, "defaultState" in k ? _object_spread_props(_object_spread({}, config3), {
1370
1368
  state: k.defaultState
1371
- }) : config2);
1369
+ }) : config3);
1372
1370
  });
1373
1371
  return {
1374
1372
  find: function find(key) {
@@ -1418,28 +1416,28 @@ function createStores(modelKeys) {
1418
1416
  }
1419
1417
 
1420
1418
  // src/model/index.ts
1421
- function configModel(config2) {
1422
- var model2 = function model3(modelFn, wrapper) {
1419
+ function configModel(config3) {
1420
+ var model = function model2(modelFn, wrapper) {
1423
1421
  var currentSelector = wrapper !== null && wrapper !== void 0 ? wrapper : defaultSelector;
1424
1422
  var modelWrapper = function modelWrapper2(state) {
1425
1423
  return modelFn(state);
1426
1424
  };
1427
1425
  modelWrapper.produce = function produce(s) {
1428
- return model3(modelFn, s);
1426
+ return model2(modelFn, s);
1429
1427
  };
1430
1428
  modelWrapper.createKey = function createModelKey(state) {
1431
- return createKey(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
1429
+ return createKey(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config3), {
1432
1430
  state,
1433
1431
  wrapper: currentSelector
1434
- }) : _object_spread_props(_object_spread({}, config2), {
1432
+ }) : _object_spread_props(_object_spread({}, config3), {
1435
1433
  wrapper: currentSelector
1436
1434
  }));
1437
1435
  };
1438
1436
  modelWrapper.createStore = function createModelStore(state) {
1439
- return createStore(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
1437
+ return createStore(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config3), {
1440
1438
  state,
1441
1439
  wrapper: currentSelector
1442
- }) : _object_spread_props(_object_spread({}, config2), {
1440
+ }) : _object_spread_props(_object_spread({}, config3), {
1443
1441
  wrapper: currentSelector
1444
1442
  }));
1445
1443
  };
@@ -1450,46 +1448,41 @@ function configModel(config2) {
1450
1448
  modelWrapper.modelUsageIdentifier = modelUsageIdentifier;
1451
1449
  return modelWrapper;
1452
1450
  };
1453
- model2.createField = createField2;
1454
- model2.createMethod = createMethod2;
1455
- return model2;
1451
+ model.createField = createField2;
1452
+ model.createMethod = createMethod2;
1453
+ return model;
1456
1454
  }
1457
1455
 
1458
1456
  // src/index.ts
1459
- function config() {
1457
+ var config = function config2() {
1460
1458
  var configuration = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1461
- var createStore3 = function createStore4(modelLike, state) {
1459
+ var createStore2 = function createStore3(modelLike, state) {
1462
1460
  return createStore(modelLike, arguments.length > 1 ? _object_spread_props(_object_spread({}, configuration), {
1463
1461
  state
1464
1462
  }) : configuration);
1465
1463
  };
1466
- var createKey3 = function createKey4(model3, state) {
1464
+ var createKey2 = function createKey3(model2, state) {
1467
1465
  var isKeySetState = arguments.length > 1;
1468
- var key = createKey(model3, isKeySetState ? _object_spread_props(_object_spread({}, configuration), {
1466
+ var key = createKey(model2, isKeySetState ? _object_spread_props(_object_spread({}, configuration), {
1469
1467
  state
1470
1468
  }) : configuration);
1471
1469
  key.createStore = function createKeyStore(s) {
1472
- return arguments.length > 0 ? createStore3(key, s) : createStore3(key);
1470
+ return arguments.length > 0 ? createStore2(key, s) : createStore2(key);
1473
1471
  };
1474
1472
  return key;
1475
1473
  };
1476
- createKey3.isModelKey = createKey.isModelKey;
1477
- var createStores3 = function createStores4() {
1474
+ createKey2.isModelKey = createKey.isModelKey;
1475
+ var createStores2 = function createStores3() {
1478
1476
  for (var _len = arguments.length, modelKeys = new Array(_len), _key = 0; _key < _len; _key++) {
1479
1477
  modelKeys[_key] = arguments[_key];
1480
1478
  }
1481
1479
  return createStores(modelKeys, configuration);
1482
1480
  };
1483
- var model2 = configModel(configuration);
1481
+ var model = configModel(configuration);
1484
1482
  return {
1485
- createStore: createStore3,
1486
- createKey: createKey3,
1487
- createStores: createStores3,
1488
- model: model2
1483
+ createStore: createStore2,
1484
+ createKey: createKey2,
1485
+ createStores: createStores2,
1486
+ model
1489
1487
  };
1490
- }
1491
- var _config = config();
1492
- var createStore2 = _config.createStore;
1493
- var createKey2 = _config.createKey;
1494
- var createStores2 = _config.createStores;
1495
- var model = _config.model;
1488
+ };
package/esm/index.js CHANGED
@@ -20,48 +20,43 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { createStore as cs } from "./store";
21
21
  import { createKey as ck, createStores as css } from "./key";
22
22
  import { configModel } from "./model";
23
- function config(configuration = {}) {
24
- const createStore2 = function createStore3(modelLike, state) {
23
+ const config = function config2(configuration = {}) {
24
+ const createStore = function createStore2(modelLike, state) {
25
25
  return cs(
26
26
  modelLike,
27
27
  arguments.length > 1 ? __spreadProps(__spreadValues({}, configuration), { state }) : configuration
28
28
  );
29
29
  };
30
- const createKey2 = function createKey3(model3, state) {
30
+ const createKey = function createKey2(model2, state) {
31
31
  const isKeySetState = arguments.length > 1;
32
32
  const key = ck(
33
- model3,
33
+ model2,
34
34
  isKeySetState ? __spreadProps(__spreadValues({}, configuration), { state }) : configuration
35
35
  );
36
36
  key.createStore = function createKeyStore(s) {
37
- return arguments.length > 0 ? createStore2(key, s) : createStore2(key);
37
+ return arguments.length > 0 ? createStore(key, s) : createStore(key);
38
38
  };
39
39
  return key;
40
40
  };
41
- createKey2.isModelKey = ck.isModelKey;
42
- const createStores2 = function createStores3(...modelKeys) {
41
+ createKey.isModelKey = ck.isModelKey;
42
+ const createStores = function createStores2(...modelKeys) {
43
43
  return css(modelKeys, configuration);
44
44
  };
45
- const model2 = configModel(configuration);
45
+ const model = configModel(configuration);
46
46
  return {
47
- createStore: createStore2,
48
- createKey: createKey2,
49
- createStores: createStores2,
50
- model: model2
47
+ createStore,
48
+ createKey,
49
+ createStores,
50
+ model
51
51
  };
52
- }
53
- const { createStore, createKey, createStores, model } = config();
52
+ };
54
53
  import { createSignal, createSelector } from "./store";
55
54
  import { validations } from "./validation";
56
55
  import { shallowEqual } from "./tools";
57
56
  export {
58
57
  config,
59
- createKey,
60
58
  createSelector,
61
59
  createSignal,
62
- createStore,
63
- createStores,
64
- model,
65
60
  shallowEqual,
66
61
  validations
67
62
  };
@@ -73,16 +73,18 @@ function createUpdateFn(updater, middleWare) {
73
73
  if (Object.is(u.model, model) && Object.is(u.state, state)) {
74
74
  return u;
75
75
  }
76
- effect((up) => {
77
- up.notify({
78
- type: null,
79
- method: null,
80
- prevInstance: u.instance,
81
- instance: u.instance,
82
- prevState: u.state,
83
- state
76
+ if (!args.silence) {
77
+ effect((up) => {
78
+ up.notify({
79
+ type: null,
80
+ method: null,
81
+ prevInstance: u.instance,
82
+ instance: u.instance,
83
+ prevState: u.state,
84
+ state
85
+ });
84
86
  });
85
- });
87
+ }
86
88
  return __spreadProps(__spreadValues({}, u), {
87
89
  model,
88
90
  initialized: true,
package/index.d.ts CHANGED
@@ -108,6 +108,7 @@ export declare interface Store<
108
108
  key?: Key<M, R>;
109
109
  initialState?: PickState<M>;
110
110
  state?: PickState<M>;
111
+ silence?: boolean;
111
112
  }) => void;
112
113
  destroy: () => void;
113
114
  payload: <P>(
@@ -117,12 +118,6 @@ export declare interface Store<
117
118
  extends: <E extends Record<string, any>>(e: E) => Store<M, R> & E;
118
119
  }
119
120
 
120
- export declare function createStore<
121
- M extends Model,
122
- D extends PickState<M>,
123
- R extends undefined | ((instance: () => Instance<M>) => any) = undefined
124
- >(model: M | Key<M, R> | ModelUsage<M, R>, state?: D): Store<M, R>;
125
-
126
121
  /** createKey * */
127
122
 
128
123
  export declare interface ModelKey<
@@ -133,12 +128,6 @@ export declare interface ModelKey<
133
128
  extends: <E extends Record<string, any>>(e: E) => ModelKey<M, R> & E;
134
129
  }
135
130
 
136
- export declare function createKey<
137
- M extends Model = Model,
138
- D extends PickState<M>,
139
- R extends undefined | ((instance: () => Instance<M>) => any) = undefined
140
- >(model: M | ModelUsage<M, R>, initialState?: D): ModelKey<M, R>;
141
-
142
131
  /** createStores * */
143
132
 
144
133
  export declare interface StoreCollection {
@@ -153,10 +142,6 @@ export declare interface StoreCollection {
153
142
  destroy: () => void;
154
143
  }
155
144
 
156
- export declare function createStores(
157
- ...modelKeys: (ModelKey<any, any> | StoreIndex<any, any>)[]
158
- ): StoreCollection;
159
-
160
145
  /** model API * */
161
146
 
162
147
  export declare type ModelUsage<
@@ -177,7 +162,7 @@ export declare type ModelUsage<
177
162
  };
178
163
 
179
164
  // eslint-disable-next-line @typescript-eslint/naming-convention
180
- export declare interface model {
165
+ declare interface model {
181
166
  <M extends Model>(modelFn: M): ModelUsage<M, undefined>;
182
167
  <M extends Model, R extends (instance: () => Instance<M>) => any>(
183
168
  modelFn: M,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "as-model",
4
- "version": "0.3.4",
4
+ "version": "0.4.1",
5
5
  "description": "This is a model state management tool",
6
6
  "license": "MIT",
7
7
  "author": "Jimmy.Harding",