as-model 0.1.0 → 0.1.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/dist/index.js CHANGED
@@ -55,33 +55,6 @@
55
55
  return target;
56
56
  }
57
57
 
58
- // node_modules/@swc/helpers/esm/_type_of.js
59
- function _type_of(obj) {
60
- "@swc/helpers - typeof";
61
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
62
- }
63
-
64
- // src/validation/index.ts
65
- var noStateAModelKey = "no-state-a-model-key";
66
- function createNoStateModel() {
67
- return function noStateModel(state) {
68
- return _define_property({}, noStateAModelKey, true);
69
- };
70
- }
71
- function isInstanceFromNoStateModel(instance) {
72
- if (instance == null) {
73
- return false;
74
- }
75
- if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object") {
76
- return false;
77
- }
78
- var ins = instance;
79
- return !!ins[noStateAModelKey];
80
- }
81
- var validations = {
82
- isInstanceFromNoStateModel
83
- };
84
-
85
58
  // node_modules/@swc/helpers/esm/_array_like_to_array.js
86
59
  function _array_like_to_array(arr, len) {
87
60
  if (len == null || len > arr.length) len = arr.length;
@@ -121,13 +94,60 @@
121
94
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
122
95
  }
123
96
 
97
+ // node_modules/@swc/helpers/esm/_type_of.js
98
+ function _type_of(obj) {
99
+ "@swc/helpers - typeof";
100
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
101
+ }
102
+
103
+ // src/identifiers/index.ts
104
+ function modelKeyIdentifier() {
105
+ return true;
106
+ }
107
+ function modelUsageIdentifier() {
108
+ return true;
109
+ }
110
+
111
+ // src/validation/index.ts
112
+ var noStateAModelKey = "no-state-a-model-key";
113
+ function createNoStateModel() {
114
+ return function noStateModel(state) {
115
+ return _define_property({}, noStateAModelKey, true);
116
+ };
117
+ }
118
+ function isInstanceFromNoStateModel(instance) {
119
+ if (instance == null) {
120
+ return false;
121
+ }
122
+ if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object") {
123
+ return false;
124
+ }
125
+ var ins = instance;
126
+ return !!ins[noStateAModelKey];
127
+ }
128
+ var validations = {
129
+ isInstanceFromNoStateModel
130
+ };
131
+ function isModelKey(data) {
132
+ if (!data) {
133
+ return false;
134
+ }
135
+ return data.modelKeyIdentifier === modelKeyIdentifier && data.modelKeyIdentifier();
136
+ }
137
+ function isModelUsage(data) {
138
+ if (!data) {
139
+ return false;
140
+ }
141
+ return data.modelUsageIdentifier === modelUsageIdentifier && data.modelUsageIdentifier();
142
+ }
143
+
124
144
  // src/updater/notifier.ts
125
145
  function defaultNotifyImplement(dispatches, action) {
126
146
  dispatches.forEach(function(callback) {
127
147
  callback(action);
128
148
  });
129
149
  }
130
- function generateNotifier(updater) {
150
+ function generateNotifier(updater, middleWare) {
131
151
  function pendAction(value) {
132
152
  updater.mutate(function(u) {
133
153
  var dispatching = u.dispatching;
@@ -196,9 +216,37 @@
196
216
  call(initializedAction);
197
217
  });
198
218
  }
199
- var config2 = updater.config;
219
+ var config2 = updater.config, model2 = updater.model;
220
+ var dispatch = function dispatch2(action) {
221
+ var dispatches = updater.dispatches, controlled = updater.controlled;
222
+ var dispatchCallbacks = _to_consumable_array(dispatches);
223
+ var state = action.state;
224
+ if (!controlled) {
225
+ updater.mutate(function(u) {
226
+ return _object_spread_props(_object_spread({}, u), {
227
+ state,
228
+ instance: model2(state),
229
+ version: u.version + 1
230
+ });
231
+ });
232
+ }
233
+ try {
234
+ if (typeof config2.batchNotify === "function") {
235
+ config2.batchNotify(dispatchCallbacks, action);
236
+ } else {
237
+ defaultNotifyImplement(dispatchCallbacks, action);
238
+ }
239
+ } catch (e) {
240
+ updater.mutate(function(u) {
241
+ return _object_spread_props(_object_spread({}, u), {
242
+ dispatching: void 0
243
+ });
244
+ });
245
+ throw e;
246
+ }
247
+ };
200
248
  return function notify(action) {
201
- if (action == null) {
249
+ if (action == null || updater.isDestroyed) {
202
250
  return;
203
251
  }
204
252
  var dispatching = updater.dispatching;
@@ -209,22 +257,15 @@
209
257
  while (updater.dispatching) {
210
258
  var wrap = updater.dispatching;
211
259
  if (wrap) {
212
- var dispatches = updater.dispatches;
213
- var dispatchCallbacks = _to_consumable_array(dispatches);
214
- try {
215
- if (typeof config2.batchNotify === "function" && dispatchCallbacks.length) {
216
- config2.batchNotify(dispatchCallbacks, wrap.value);
217
- } else {
218
- defaultNotifyImplement(dispatchCallbacks, wrap.value);
219
- }
220
- } catch (e) {
221
- updater.mutate(function(u) {
222
- return _object_spread_props(_object_spread({}, u), {
223
- dispatching: void 0
224
- });
225
- });
226
- throw e;
227
- }
260
+ middleWare({
261
+ getState: function getState() {
262
+ return {
263
+ state: updater.state,
264
+ instance: updater.instance
265
+ };
266
+ },
267
+ dispatch: notify
268
+ })(dispatch)(wrap.value);
228
269
  unshiftAction();
229
270
  } else {
230
271
  updater.mutate(function(u) {
@@ -238,7 +279,7 @@
238
279
  };
239
280
  }
240
281
 
241
- // src/tools.ts
282
+ // src/tools/proxy.ts
242
283
  function getDescriptors(target, receiver, ownOrPrototype, handler) {
243
284
  var it = Object.keys(ownOrPrototype);
244
285
  var result = {};
@@ -277,6 +318,8 @@
277
318
  }
278
319
  return new Proxy(target, handler);
279
320
  };
321
+
322
+ // src/tools/shallowEqual.ts
280
323
  function isObject(data) {
281
324
  return data && (typeof data === "undefined" ? "undefined" : _type_of(data)) === "object";
282
325
  }
@@ -307,6 +350,8 @@
307
350
  });
308
351
  return !hasDiffValue;
309
352
  }
353
+
354
+ // src/tools/index.ts
310
355
  function noop() {
311
356
  }
312
357
 
@@ -442,14 +487,14 @@
442
487
  }
443
488
 
444
489
  // src/updater/index.ts
445
- function createInitializedUpdater(updater) {
490
+ function createInitializedUpdater(updater, middleWare) {
446
491
  var createTunnel = generateTunnelCreator(updater);
447
492
  return {
448
- notify: generateNotifier(updater),
493
+ notify: generateNotifier(updater, middleWare),
449
494
  createTunnel
450
495
  };
451
496
  }
452
- function createUpdateFn(updater) {
497
+ function createUpdateFn(updater, middleWare) {
453
498
  return function update() {
454
499
  var args = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
455
500
  updater.mutate(function(u, effect) {
@@ -473,7 +518,7 @@
473
518
  }
474
519
  if (!u.initialized) {
475
520
  var instance1 = model2(initialState);
476
- var initializedUpdater = createInitializedUpdater(u);
521
+ var initializedUpdater = createInitializedUpdater(u, middleWare);
477
522
  return _object_spread(_object_spread_props(_object_spread({}, u), {
478
523
  model: model2,
479
524
  state: initialState,
@@ -505,8 +550,8 @@
505
550
  };
506
551
  }
507
552
  var lazyModel = createNoStateModel();
508
- function createUpdater(model2) {
509
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
553
+ function createUpdater(model2, middleWare) {
554
+ var config2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
510
555
  var hasDefaultState = "state" in config2;
511
556
  var controlled = config2.controlled, defaultState = config2.state;
512
557
  var defaultInstance = hasDefaultState ? model2(defaultState) : lazyModel(void 0);
@@ -557,9 +602,9 @@
557
602
  destroy(updater);
558
603
  }
559
604
  }, unInitializedUpdater);
560
- var initialized = createInitializedUpdater(updater);
605
+ var initialized = createInitializedUpdater(updater, middleWare);
561
606
  Object.assign(updater, initialized, {
562
- update: createUpdateFn(updater)
607
+ update: createUpdateFn(updater, middleWare)
563
608
  });
564
609
  return updater;
565
610
  }
@@ -630,7 +675,7 @@
630
675
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
631
676
  args[_key] = arguments[_key];
632
677
  }
633
- var instance = updater.instance, isDestroyed = updater.isDestroyed, controlled = updater.controlled, model2 = updater.model;
678
+ var instance = updater.instance, model2 = updater.model;
634
679
  var method2 = instance[methodName];
635
680
  if (typeof method2 !== "function") {
636
681
  throw new Error("Can not change methods in runtime.");
@@ -639,9 +684,6 @@
639
684
  return method2.apply(void 0, _to_consumable_array(args));
640
685
  }
641
686
  var state = method2.apply(void 0, _to_consumable_array(args));
642
- if (isDestroyed) {
643
- return state;
644
- }
645
687
  var action = {
646
688
  type: methodName,
647
689
  state,
@@ -650,30 +692,7 @@
650
692
  prevInstance: updater.instance,
651
693
  method: actionMethod2
652
694
  };
653
- if (controlled) {
654
- updater.notify(action);
655
- return state;
656
- }
657
- var prevState = updater.state;
658
- var prevInstance = updater.instance;
659
- var newestInstance = model2(state);
660
- updater.mutate(function(up, effect) {
661
- effect(function(u) {
662
- u.notify({
663
- type: methodName,
664
- state,
665
- prevState,
666
- instance: newestInstance,
667
- prevInstance,
668
- method: actionMethod2
669
- });
670
- });
671
- return _object_spread_props(_object_spread({}, up), {
672
- instance: newestInstance,
673
- state,
674
- version: up.version + 1
675
- });
676
- });
695
+ updater.notify(action);
677
696
  return state;
678
697
  };
679
698
  cacheMethods[methodName] = actionMethod;
@@ -755,87 +774,22 @@
755
774
  });
756
775
  }
757
776
 
758
- // src/store/index.ts
759
- function modelKeyIdentifier() {
760
- return true;
761
- }
762
- function isModelKey(data) {
763
- if (!data) {
764
- return false;
765
- }
766
- return data.modelKeyIdentifier === modelKeyIdentifier;
767
- }
768
- function createPrimaryKey(modelFn, defaultState) {
769
- var model2 = isModelKey(modelFn) ? modelFn.source : modelFn;
770
- var wrapModel = function wrapModel2(state) {
771
- return model2(state);
772
- };
773
- wrapModel.source = model2;
774
- wrapModel.modelKeyIdentifier = modelKeyIdentifier;
775
- if (arguments.length > 1) {
776
- wrapModel.defaultState = defaultState;
777
- }
778
- return wrapModel;
779
- }
780
- function createStore(modelLike) {
781
- var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
782
- var model2 = isModelKey(modelLike) ? modelLike.source : modelLike;
783
- var modelKey = isModelKey(modelLike) ? modelLike : void 0;
784
- var conf = function computeConfig() {
785
- var hasConfigState = "state" in config2;
786
- var hasKeyState = !!modelKey && "defaultState" in modelKey;
787
- if (hasConfigState) {
788
- return config2;
789
- }
790
- if (hasKeyState) {
791
- return _object_spread_props(_object_spread({}, config2), {
792
- state: modelKey === null || modelKey === void 0 ? void 0 : modelKey.defaultState
793
- });
794
- }
795
- return config2;
796
- }();
797
- var updater = createUpdater(model2, conf);
798
- var store = {
799
- key: modelKey !== null && modelKey !== void 0 ? modelKey : "state" in config2 ? createPrimaryKey(model2, config2.state) : createPrimaryKey(model2),
800
- subscribe: function subscribe(dispatcher) {
801
- var _updater_createTunnel = updater.createTunnel(dispatcher), connect = _updater_createTunnel.connect, disconnect = _updater_createTunnel.disconnect;
802
- connect();
803
- return disconnect;
804
- },
805
- getInstance: function getInstance() {
806
- return extractInstance(updater);
807
- },
808
- update: function update(args) {
809
- updater.update(args);
810
- },
811
- destroy: function destroy2() {
812
- updater.destroy();
813
- },
814
- payload: function payload(callback) {
815
- return updater.payload(callback);
816
- },
817
- isDestroyed: function isDestroyed() {
818
- return updater.isDestroyed;
819
- },
820
- updater
821
- };
822
- return store;
823
- }
777
+ // src/store/enhance/signal.ts
824
778
  function createSignal(store) {
825
779
  var signalStore = {
826
780
  collection: null,
827
781
  started: false,
828
782
  enabled: false
829
783
  };
830
- var middleWare = function(dispatcher) {
784
+ var enhance = function(dispatcher) {
831
785
  return function(action) {
832
786
  if (!signalStore.enabled) {
833
- dispatcher(action);
787
+ dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher(action);
834
788
  return;
835
789
  }
836
790
  var collection = signalStore.collection;
837
791
  if (collection == null) {
838
- dispatcher(action);
792
+ dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher(action);
839
793
  return;
840
794
  }
841
795
  var current = extractInstance(store.updater);
@@ -855,14 +809,15 @@
855
809
  });
856
810
  var currentCollection = Object.fromEntries(currentCollectionEntries);
857
811
  if (!shallowEqual(collection, currentCollection)) {
858
- dispatcher(action);
812
+ dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher(action);
859
813
  }
860
814
  };
861
815
  };
816
+ var storeKey = store.key;
862
817
  return {
863
- key: store.key,
818
+ key: storeKey,
864
819
  subscribe: function subscribe(dispatcher) {
865
- return store.subscribe(middleWare(dispatcher));
820
+ return store.subscribe(enhance(dispatcher));
866
821
  },
867
822
  getSignal: function getSignal() {
868
823
  var collectUsedFields = function collectUsedFields2(key, val) {
@@ -872,9 +827,12 @@
872
827
  signalStore.collection = signalStore.collection || {};
873
828
  signalStore.collection[key] = val;
874
829
  };
875
- var signal = function signal2() {
830
+ var getInstance = function getInstance2() {
876
831
  return extractInstance(store.updater, collectUsedFields);
877
832
  };
833
+ var signal = function signal2() {
834
+ return getInstance();
835
+ };
878
836
  signal.startStatistics = function startStatistics() {
879
837
  signalStore.started = true;
880
838
  };
@@ -893,14 +851,259 @@
893
851
  }
894
852
  };
895
853
  }
854
+
855
+ // src/store/enhance/selector.ts
856
+ function wrapToField2(cache, propertyName, value, onGot) {
857
+ var cacheFields = cache.cacheFields;
858
+ if (!cacheIdentify.field(value)) {
859
+ if (onGot) {
860
+ onGot(propertyName, value);
861
+ }
862
+ return value;
863
+ }
864
+ var field2 = value;
865
+ var cachedField = cacheFields[propertyName];
866
+ if (cachedField) {
867
+ return cachedField.getter;
868
+ }
869
+ var getter = {
870
+ get: function get() {
871
+ var currentField = cache.target[propertyName];
872
+ if (!cacheIdentify.field(currentField)) {
873
+ throw new Error("Field should always be field.");
874
+ }
875
+ var current = currentField.get();
876
+ var fieldInCache = cache.cacheFields[propertyName];
877
+ if (!currentField.deps || fieldInCache == null) {
878
+ cacheFields[propertyName] = {
879
+ getter,
880
+ value: current,
881
+ deps: currentField.deps
882
+ };
883
+ return current;
884
+ }
885
+ if (shallowEqual(currentField.deps, fieldInCache.deps)) {
886
+ return fieldInCache.value;
887
+ }
888
+ cacheFields[propertyName] = {
889
+ getter,
890
+ value: current,
891
+ deps: currentField.deps
892
+ };
893
+ return current;
894
+ }
895
+ };
896
+ cacheFields[propertyName] = {
897
+ getter,
898
+ value: field2.value,
899
+ deps: field2.deps
900
+ };
901
+ return getter;
902
+ }
903
+ function wrapToActionMethod2(cache, methodName) {
904
+ var cacheMethods = cache.cacheMethods;
905
+ var cachedMethod = cacheMethods[methodName];
906
+ if (typeof cachedMethod === "function") {
907
+ return cachedMethod;
908
+ }
909
+ var actionMethod = function actionMethod2() {
910
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
911
+ args[_key] = arguments[_key];
912
+ }
913
+ var target = cache.target;
914
+ var method2 = target[methodName];
915
+ if (typeof method2 !== "function") {
916
+ throw new Error("Can not change methods in runtime.");
917
+ }
918
+ return method2.apply(void 0, _to_consumable_array(args));
919
+ };
920
+ cacheMethods[methodName] = actionMethod;
921
+ return actionMethod;
922
+ }
923
+ var cacheProperties = function(cache, onGet) {
924
+ return function createCachePropertiesProxy() {
925
+ var instance = cache.target;
926
+ var properties = Object.getOwnPropertyNames(instance);
927
+ var handleGetter = function handleGetter2(key, value) {
928
+ if (!onGet) {
929
+ return;
930
+ }
931
+ onGet(key, value);
932
+ };
933
+ return createProxy(instance, {
934
+ get: function get(target, p) {
935
+ var value = target[p];
936
+ if (typeof value === "function" && properties.indexOf(p) >= 0) {
937
+ var actionMethod = wrapToActionMethod2(cache, p);
938
+ Object.assign(actionMethod, value);
939
+ handleGetter(p, actionMethod);
940
+ return actionMethod;
941
+ }
942
+ return wrapToField2(cache, p, value, handleGetter);
943
+ },
944
+ set: function set() {
945
+ return false;
946
+ }
947
+ });
948
+ };
949
+ };
950
+ function createSelector(store, opts) {
951
+ var equality = (opts !== null && opts !== void 0 ? opts : {}).equality;
952
+ var selectStore = {
953
+ selectedInstance: store.getInstance()
954
+ };
955
+ var cache = {
956
+ equality,
957
+ setSelect: function setSelect(selector) {
958
+ cache.selector = selector;
959
+ if (!selector) {
960
+ return;
961
+ }
962
+ var currentSelectedInstance = selectStore.selectedInstance;
963
+ var nextSelectedInstance = selector(store.getInstance);
964
+ if (currentSelectedInstance === nextSelectedInstance || equality && equality(currentSelectedInstance, nextSelectedInstance)) {
965
+ return;
966
+ }
967
+ selectStore.selectedInstance = nextSelectedInstance;
968
+ }
969
+ };
970
+ var propertiesCache = {
971
+ target: store.getInstance(),
972
+ cacheFields: {},
973
+ cacheMethods: {}
974
+ };
975
+ var generateSelectedInstance = function generateSelectedInstance2(getInstance) {
976
+ var storeKey = store.key;
977
+ if (cache.selector) {
978
+ return cache.selector(getInstance);
979
+ }
980
+ if (!(storeKey === null || storeKey === void 0 ? void 0 : storeKey.selector)) {
981
+ return getInstance();
982
+ }
983
+ var result = storeKey === null || storeKey === void 0 ? void 0 : storeKey.selector(getInstance);
984
+ if (result == null || (typeof result === "undefined" ? "undefined" : _type_of(result)) !== "object") {
985
+ throw new Error("The default selector result should be an object or array");
986
+ }
987
+ propertiesCache.target = result;
988
+ return cacheProperties(propertiesCache)();
989
+ };
990
+ selectStore.selectedInstance = generateSelectedInstance(store.getInstance);
991
+ var enhance = function(dispatcher) {
992
+ return function(action) {
993
+ var currentSelectedInstance = selectStore.selectedInstance;
994
+ var nextSelectedInstance = generateSelectedInstance(store.getInstance);
995
+ if (currentSelectedInstance === nextSelectedInstance || cache.equality && cache.equality(currentSelectedInstance, nextSelectedInstance)) {
996
+ return;
997
+ }
998
+ selectStore.selectedInstance = nextSelectedInstance;
999
+ if (dispatcher == null) {
1000
+ return;
1001
+ }
1002
+ dispatcher(action);
1003
+ };
1004
+ };
1005
+ function select(selector) {
1006
+ cache.setSelect(selector);
1007
+ return selectStore.selectedInstance;
1008
+ }
1009
+ return {
1010
+ key: store.key,
1011
+ subscribe: function subscribe(dispatcher) {
1012
+ return store.subscribe(enhance(dispatcher));
1013
+ },
1014
+ select
1015
+ };
1016
+ }
1017
+
1018
+ // src/store/index.ts
1019
+ function createPrimaryKey(modelFn) {
1020
+ var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1021
+ var ifModelKey = isModelKey(modelFn);
1022
+ var ifModelUsage = isModelUsage(modelFn);
1023
+ var model2 = ifModelKey ? modelFn.source : modelFn;
1024
+ var _config_selector;
1025
+ var selector = (_config_selector = config2.selector) !== null && _config_selector !== void 0 ? _config_selector : ifModelKey || ifModelUsage ? modelFn.selector : function defaultSelector(i) {
1026
+ return i();
1027
+ };
1028
+ var wrapModel = function wrapModel2(state) {
1029
+ return model2(state);
1030
+ };
1031
+ wrapModel.source = model2;
1032
+ wrapModel.selector = selector;
1033
+ wrapModel.modelKeyIdentifier = modelKeyIdentifier;
1034
+ if ("state" in config2) {
1035
+ wrapModel.defaultState = config2.state;
1036
+ }
1037
+ return wrapModel;
1038
+ }
1039
+ function createStore(modelLike) {
1040
+ var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1041
+ var ifModelKey = isModelKey(modelLike);
1042
+ var model2 = ifModelKey ? modelLike.source : modelLike;
1043
+ var modelKey = ifModelKey ? modelLike : void 0;
1044
+ var conf = function computeConfig() {
1045
+ var hasConfigState = "state" in config2;
1046
+ var hasKeyState = !!modelKey && "defaultState" in modelKey;
1047
+ if (hasConfigState) {
1048
+ return config2;
1049
+ }
1050
+ if (hasKeyState) {
1051
+ return _object_spread_props(_object_spread({}, config2), {
1052
+ state: modelKey === null || modelKey === void 0 ? void 0 : modelKey.defaultState
1053
+ });
1054
+ }
1055
+ return config2;
1056
+ }();
1057
+ var combinedMiddleWare = function combinedMiddleWare2(s) {
1058
+ return function updaterMiddleWare(next) {
1059
+ var middleWares = conf.middleWares;
1060
+ if (middleWares == null) {
1061
+ return next;
1062
+ }
1063
+ var updateMiddleWares = _to_consumable_array(middleWares).reverse().map(function(middleWare) {
1064
+ return middleWare(s);
1065
+ });
1066
+ return updateMiddleWares.reduce(function(finalDispatcher, um) {
1067
+ return um(finalDispatcher);
1068
+ }, next);
1069
+ };
1070
+ };
1071
+ var updater = createUpdater(model2, combinedMiddleWare, conf);
1072
+ var key = modelKey !== null && modelKey !== void 0 ? modelKey : createPrimaryKey(model2, config2);
1073
+ var getInstance = function getInstance2() {
1074
+ return extractInstance(updater);
1075
+ };
1076
+ var store = {
1077
+ key,
1078
+ subscribe: function subscribe(dispatcher) {
1079
+ var _updater_createTunnel = updater.createTunnel(dispatcher), connect = _updater_createTunnel.connect, disconnect = _updater_createTunnel.disconnect;
1080
+ connect();
1081
+ return disconnect;
1082
+ },
1083
+ getInstance,
1084
+ update: function update(args) {
1085
+ updater.update(args);
1086
+ },
1087
+ destroy: function destroy2() {
1088
+ updater.destroy();
1089
+ },
1090
+ payload: function payload(callback) {
1091
+ return updater.payload(callback);
1092
+ },
1093
+ isDestroyed: function isDestroyed() {
1094
+ return updater.isDestroyed;
1095
+ },
1096
+ updater
1097
+ };
1098
+ return store;
1099
+ }
896
1100
  var createField2 = createField;
897
1101
  var createMethod2 = createMethod;
898
1102
 
899
1103
  // src/key/index.ts
900
1104
  function createKey(model2) {
901
1105
  var config2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
902
- var hasDefaultState = "state" in config2;
903
- var wrapModel = hasDefaultState ? createPrimaryKey(model2, config2.state) : createPrimaryKey(model2);
1106
+ var wrapModel = createPrimaryKey(model2, config2);
904
1107
  wrapModel.createStore = function createKeyStore() {
905
1108
  var storeConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
906
1109
  return createStore(wrapModel, _object_spread({}, config2, storeConfig));
@@ -966,20 +1169,34 @@
966
1169
 
967
1170
  // src/model/index.ts
968
1171
  function configModel(config2) {
969
- var model2 = function model3(modelFn) {
1172
+ var model2 = function model3(modelFn, selector) {
1173
+ var currentSelector = selector !== null && selector !== void 0 ? selector : function defaultSelector(i) {
1174
+ return i();
1175
+ };
970
1176
  var modelWrapper = function modelWrapper2(state) {
971
1177
  return modelFn(state);
972
1178
  };
1179
+ modelWrapper.select = function select(s) {
1180
+ return model3(modelFn, s);
1181
+ };
973
1182
  modelWrapper.createKey = function createModelKey(state) {
974
- return createKey(modelWrapper, arguments.length ? _object_spread_props(_object_spread({}, config2), {
975
- state
976
- }) : config2);
1183
+ return createKey(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
1184
+ state,
1185
+ selector: currentSelector
1186
+ }) : _object_spread_props(_object_spread({}, config2), {
1187
+ selector: currentSelector
1188
+ }));
977
1189
  };
978
1190
  modelWrapper.createStore = function createModelStore(state) {
979
- return createStore(modelWrapper, arguments.length ? _object_spread_props(_object_spread({}, config2), {
980
- state
981
- }) : config2);
1191
+ return createStore(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
1192
+ state,
1193
+ selector: currentSelector
1194
+ }) : _object_spread_props(_object_spread({}, config2), {
1195
+ selector: currentSelector
1196
+ }));
982
1197
  };
1198
+ modelWrapper.selector = currentSelector;
1199
+ modelWrapper.modelUsageIdentifier = modelUsageIdentifier;
983
1200
  return modelWrapper;
984
1201
  };
985
1202
  model2.createField = createField2;