as-model 0.1.27 → 0.2.0
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 +159 -144
- package/esm/model/index.js +6 -6
- package/esm/store/cache.js +108 -0
- package/esm/store/enhance/selector.js +1 -107
- package/esm/store/enhance/signal.js +15 -3
- package/esm/store/index.js +11 -6
- package/esm/store/instance.js +47 -30
- package/index.d.ts +8 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -747,7 +747,7 @@
|
|
|
747
747
|
return updater;
|
|
748
748
|
}
|
|
749
749
|
|
|
750
|
-
// src/store/
|
|
750
|
+
// src/store/cache.ts
|
|
751
751
|
var cacheIdentify = {
|
|
752
752
|
field: function field(d) {
|
|
753
753
|
if (!d) {
|
|
@@ -764,6 +764,102 @@
|
|
|
764
764
|
return m.identifier === cacheIdentify.method;
|
|
765
765
|
}
|
|
766
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
|
+
}
|
|
775
|
+
var field2 = value;
|
|
776
|
+
var cachedField = cacheFields[propertyName];
|
|
777
|
+
if (cachedField) {
|
|
778
|
+
return cachedField.getter;
|
|
779
|
+
}
|
|
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;
|
|
813
|
+
}
|
|
814
|
+
function wrapToActionMethod(cache, methodName) {
|
|
815
|
+
var cacheMethods = cache.cacheMethods;
|
|
816
|
+
var cachedMethod = cacheMethods[methodName];
|
|
817
|
+
if (typeof cachedMethod === "function") {
|
|
818
|
+
return cachedMethod;
|
|
819
|
+
}
|
|
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
|
|
767
863
|
function createField(callback, deps) {
|
|
768
864
|
var currentDeps = function computeDeps() {
|
|
769
865
|
if (deps == null) {
|
|
@@ -802,7 +898,7 @@
|
|
|
802
898
|
replace.identifier = cacheIdentify.method;
|
|
803
899
|
return replace;
|
|
804
900
|
}
|
|
805
|
-
function
|
|
901
|
+
function wrapToActionMethod2(updater, methodName) {
|
|
806
902
|
var cacheMethods = updater.cacheMethods;
|
|
807
903
|
var cachedMethod = cacheMethods[methodName];
|
|
808
904
|
if (typeof cachedMethod === "function") {
|
|
@@ -835,18 +931,23 @@
|
|
|
835
931
|
cacheMethods[methodName] = actionMethod;
|
|
836
932
|
return actionMethod;
|
|
837
933
|
}
|
|
838
|
-
function
|
|
839
|
-
|
|
840
|
-
if (!cacheIdentify.field(value)) {
|
|
934
|
+
function wrapToField2(updater, propertyName, value, onGot) {
|
|
935
|
+
function collect(pName, v) {
|
|
841
936
|
if (onGot) {
|
|
842
|
-
onGot(
|
|
937
|
+
onGot(pName, v);
|
|
843
938
|
}
|
|
939
|
+
}
|
|
940
|
+
var cacheFields = updater.cacheFields;
|
|
941
|
+
if (!cacheIdentify.field(value)) {
|
|
942
|
+
collect(propertyName, value);
|
|
844
943
|
return value;
|
|
845
944
|
}
|
|
846
945
|
var field2 = value;
|
|
847
946
|
var cachedField = cacheFields[propertyName];
|
|
848
|
-
if (cachedField) {
|
|
849
|
-
|
|
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;
|
|
850
951
|
}
|
|
851
952
|
var getter = {
|
|
852
953
|
get: function get() {
|
|
@@ -880,35 +981,46 @@
|
|
|
880
981
|
value: field2.value,
|
|
881
982
|
deps: field2.deps
|
|
882
983
|
};
|
|
984
|
+
collect(propertyName, getter);
|
|
883
985
|
return getter;
|
|
884
986
|
}
|
|
885
|
-
function extractInstance(updater,
|
|
886
|
-
var
|
|
887
|
-
if ((typeof instance === "undefined" ? "undefined" : _type_of(instance)) !== "object" || !instance) {
|
|
888
|
-
throw new Error("The instance should be an object or array.");
|
|
889
|
-
}
|
|
890
|
-
var properties = Object.getOwnPropertyNames(instance);
|
|
987
|
+
function extractInstance(updater, wrapper, cache, opts) {
|
|
988
|
+
var onGet = (opts || {}).onGet;
|
|
891
989
|
var handleGetter = function handleGetter2(key, value) {
|
|
892
990
|
if (!onGet) {
|
|
893
991
|
return;
|
|
894
992
|
}
|
|
895
993
|
onGet(key, value);
|
|
896
994
|
};
|
|
897
|
-
|
|
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, {
|
|
898
1001
|
get: function get(target, p) {
|
|
899
1002
|
var value = target[p];
|
|
900
1003
|
if (typeof value === "function" && properties.indexOf(p) >= 0) {
|
|
901
|
-
var actionMethod =
|
|
1004
|
+
var actionMethod = wrapToActionMethod2(updater, p);
|
|
902
1005
|
Object.assign(actionMethod, value);
|
|
903
|
-
handleGetter(p, actionMethod);
|
|
904
1006
|
return actionMethod;
|
|
905
1007
|
}
|
|
906
|
-
return
|
|
1008
|
+
return wrapToField2(updater, p, value);
|
|
907
1009
|
},
|
|
908
1010
|
set: function set() {
|
|
909
1011
|
return false;
|
|
910
1012
|
}
|
|
911
1013
|
});
|
|
1014
|
+
function generateInstance() {
|
|
1015
|
+
return proxiedInstance;
|
|
1016
|
+
}
|
|
1017
|
+
var wrapped = wrapper(generateInstance);
|
|
1018
|
+
if ((typeof wrapped === "undefined" ? "undefined" : _type_of(wrapped)) === "object" && wrapped != null) {
|
|
1019
|
+
return cacheProperties(_object_spread_props(_object_spread({}, cache), {
|
|
1020
|
+
target: wrapped
|
|
1021
|
+
}), handleGetter)();
|
|
1022
|
+
}
|
|
1023
|
+
return wrapped;
|
|
912
1024
|
}
|
|
913
1025
|
|
|
914
1026
|
// src/store/enhance/signal.ts
|
|
@@ -918,6 +1030,11 @@
|
|
|
918
1030
|
started: false,
|
|
919
1031
|
enabled: false
|
|
920
1032
|
};
|
|
1033
|
+
var propertiesCache = {
|
|
1034
|
+
target: store.getInstance(),
|
|
1035
|
+
cacheFields: {},
|
|
1036
|
+
cacheMethods: {}
|
|
1037
|
+
};
|
|
921
1038
|
var enhance = function(dispatcher) {
|
|
922
1039
|
return function(action) {
|
|
923
1040
|
if (!signalStore.enabled) {
|
|
@@ -928,7 +1045,7 @@
|
|
|
928
1045
|
if (collection == null) {
|
|
929
1046
|
return;
|
|
930
1047
|
}
|
|
931
|
-
var storeInstance = extractInstance(store.updater);
|
|
1048
|
+
var storeInstance = extractInstance(store.updater, store.key.wrapper, propertiesCache);
|
|
932
1049
|
var keys = Object.keys(collection);
|
|
933
1050
|
if (!keys.length) {
|
|
934
1051
|
return;
|
|
@@ -964,7 +1081,9 @@
|
|
|
964
1081
|
};
|
|
965
1082
|
var getInstance = function getInstance2(options) {
|
|
966
1083
|
var cutOff = (options !== null && options !== void 0 ? options : {}).cutOff;
|
|
967
|
-
return extractInstance(store.updater,
|
|
1084
|
+
return extractInstance(store.updater, store.key.wrapper, propertiesCache, {
|
|
1085
|
+
onGet: cutOff ? void 0 : collectUsedFields
|
|
1086
|
+
});
|
|
968
1087
|
};
|
|
969
1088
|
var signal = function signal2(options) {
|
|
970
1089
|
return getInstance(options);
|
|
@@ -988,100 +1107,6 @@
|
|
|
988
1107
|
}
|
|
989
1108
|
|
|
990
1109
|
// src/store/enhance/selector.ts
|
|
991
|
-
function wrapToField2(cache, propertyName, value, onGot) {
|
|
992
|
-
var cacheFields = cache.cacheFields;
|
|
993
|
-
if (!cacheIdentify.field(value)) {
|
|
994
|
-
if (onGot) {
|
|
995
|
-
onGot(propertyName, value);
|
|
996
|
-
}
|
|
997
|
-
return value;
|
|
998
|
-
}
|
|
999
|
-
var field2 = value;
|
|
1000
|
-
var cachedField = cacheFields[propertyName];
|
|
1001
|
-
if (cachedField) {
|
|
1002
|
-
return cachedField.getter;
|
|
1003
|
-
}
|
|
1004
|
-
var getter = {
|
|
1005
|
-
get: function get() {
|
|
1006
|
-
var currentField = cache.target[propertyName];
|
|
1007
|
-
if (!cacheIdentify.field(currentField)) {
|
|
1008
|
-
throw new Error("Field should always be field.");
|
|
1009
|
-
}
|
|
1010
|
-
var current = currentField.get();
|
|
1011
|
-
var fieldInCache = cache.cacheFields[propertyName];
|
|
1012
|
-
if (!currentField.deps || fieldInCache == null) {
|
|
1013
|
-
cacheFields[propertyName] = {
|
|
1014
|
-
getter,
|
|
1015
|
-
value: current,
|
|
1016
|
-
deps: currentField.deps
|
|
1017
|
-
};
|
|
1018
|
-
return current;
|
|
1019
|
-
}
|
|
1020
|
-
if (shallowEqual(currentField.deps, fieldInCache.deps)) {
|
|
1021
|
-
return fieldInCache.value;
|
|
1022
|
-
}
|
|
1023
|
-
cacheFields[propertyName] = {
|
|
1024
|
-
getter,
|
|
1025
|
-
value: current,
|
|
1026
|
-
deps: currentField.deps
|
|
1027
|
-
};
|
|
1028
|
-
return current;
|
|
1029
|
-
}
|
|
1030
|
-
};
|
|
1031
|
-
cacheFields[propertyName] = {
|
|
1032
|
-
getter,
|
|
1033
|
-
value: field2.value,
|
|
1034
|
-
deps: field2.deps
|
|
1035
|
-
};
|
|
1036
|
-
return getter;
|
|
1037
|
-
}
|
|
1038
|
-
function wrapToActionMethod2(cache, methodName) {
|
|
1039
|
-
var cacheMethods = cache.cacheMethods;
|
|
1040
|
-
var cachedMethod = cacheMethods[methodName];
|
|
1041
|
-
if (typeof cachedMethod === "function") {
|
|
1042
|
-
return cachedMethod;
|
|
1043
|
-
}
|
|
1044
|
-
var actionMethod = function actionMethod2() {
|
|
1045
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1046
|
-
args[_key] = arguments[_key];
|
|
1047
|
-
}
|
|
1048
|
-
var target = cache.target;
|
|
1049
|
-
var method2 = target[methodName];
|
|
1050
|
-
if (typeof method2 !== "function") {
|
|
1051
|
-
throw new Error("Can not change methods in runtime.");
|
|
1052
|
-
}
|
|
1053
|
-
return method2.apply(void 0, _to_consumable_array(args));
|
|
1054
|
-
};
|
|
1055
|
-
cacheMethods[methodName] = actionMethod;
|
|
1056
|
-
return actionMethod;
|
|
1057
|
-
}
|
|
1058
|
-
var cacheProperties = function(cache, onGet) {
|
|
1059
|
-
return function createCachePropertiesProxy() {
|
|
1060
|
-
var instance = cache.target;
|
|
1061
|
-
var properties = Object.getOwnPropertyNames(instance);
|
|
1062
|
-
var handleGetter = function handleGetter2(key, value) {
|
|
1063
|
-
if (!onGet) {
|
|
1064
|
-
return;
|
|
1065
|
-
}
|
|
1066
|
-
onGet(key, value);
|
|
1067
|
-
};
|
|
1068
|
-
return createProxy(instance, {
|
|
1069
|
-
get: function get(target, p) {
|
|
1070
|
-
var value = target[p];
|
|
1071
|
-
if (typeof value === "function" && properties.indexOf(p) >= 0) {
|
|
1072
|
-
var actionMethod = wrapToActionMethod2(cache, p);
|
|
1073
|
-
Object.assign(actionMethod, value);
|
|
1074
|
-
handleGetter(p, actionMethod);
|
|
1075
|
-
return actionMethod;
|
|
1076
|
-
}
|
|
1077
|
-
return wrapToField2(cache, p, value, handleGetter);
|
|
1078
|
-
},
|
|
1079
|
-
set: function set() {
|
|
1080
|
-
return false;
|
|
1081
|
-
}
|
|
1082
|
-
});
|
|
1083
|
-
};
|
|
1084
|
-
};
|
|
1085
1110
|
function createSelector(store, opts) {
|
|
1086
1111
|
var equality = (opts !== null && opts !== void 0 ? opts : {}).equality;
|
|
1087
1112
|
var selectStore = {
|
|
@@ -1102,25 +1127,11 @@
|
|
|
1102
1127
|
selectStore.selectedInstance = nextSelectedInstance;
|
|
1103
1128
|
}
|
|
1104
1129
|
};
|
|
1105
|
-
var propertiesCache = {
|
|
1106
|
-
target: store.getInstance(),
|
|
1107
|
-
cacheFields: {},
|
|
1108
|
-
cacheMethods: {}
|
|
1109
|
-
};
|
|
1110
1130
|
var generateSelectedInstance = function generateSelectedInstance2(getInstance) {
|
|
1111
|
-
var storeKey = store.key;
|
|
1112
1131
|
if (cache.selector) {
|
|
1113
1132
|
return cache.selector(getInstance);
|
|
1114
1133
|
}
|
|
1115
|
-
|
|
1116
|
-
return getInstance();
|
|
1117
|
-
}
|
|
1118
|
-
var result = storeKey === null || storeKey === void 0 ? void 0 : storeKey.selector(getInstance);
|
|
1119
|
-
if (result == null || (typeof result === "undefined" ? "undefined" : _type_of(result)) !== "object") {
|
|
1120
|
-
throw new Error("The default selector result should be an object or array");
|
|
1121
|
-
}
|
|
1122
|
-
propertiesCache.target = result;
|
|
1123
|
-
return cacheProperties(propertiesCache)();
|
|
1134
|
+
return getInstance();
|
|
1124
1135
|
};
|
|
1125
1136
|
selectStore.selectedInstance = generateSelectedInstance(store.getInstance);
|
|
1126
1137
|
var enhance = function(dispatcher) {
|
|
@@ -1159,15 +1170,15 @@
|
|
|
1159
1170
|
var ifModelKey = isModelKey(modelFn);
|
|
1160
1171
|
var ifModelUsage = isModelUsage(modelFn);
|
|
1161
1172
|
var model2 = ifModelKey ? modelFn.source : modelFn;
|
|
1162
|
-
var
|
|
1163
|
-
var
|
|
1173
|
+
var _config_wrapper;
|
|
1174
|
+
var wrapper = (_config_wrapper = config2.wrapper) !== null && _config_wrapper !== void 0 ? _config_wrapper : ifModelKey || ifModelUsage ? modelFn.wrapper : function defaultSelector(i) {
|
|
1164
1175
|
return i();
|
|
1165
1176
|
};
|
|
1166
1177
|
var wrapModel = function wrapModel2(state) {
|
|
1167
1178
|
return model2(state);
|
|
1168
1179
|
};
|
|
1169
1180
|
wrapModel.source = model2;
|
|
1170
|
-
wrapModel.
|
|
1181
|
+
wrapModel.wrapper = wrapper;
|
|
1171
1182
|
wrapModel.modelKeyIdentifier = modelKeyIdentifier;
|
|
1172
1183
|
if ("state" in config2) {
|
|
1173
1184
|
wrapModel.defaultState = config2.state;
|
|
@@ -1208,8 +1219,10 @@
|
|
|
1208
1219
|
};
|
|
1209
1220
|
var updater = createUpdater(model2, combinedMiddleWare, conf);
|
|
1210
1221
|
var key = modelKey !== null && modelKey !== void 0 ? modelKey : createPrimaryKey(model2, config2);
|
|
1211
|
-
var
|
|
1212
|
-
|
|
1222
|
+
var propertiesCache = {
|
|
1223
|
+
target: updater.instance,
|
|
1224
|
+
cacheFields: {},
|
|
1225
|
+
cacheMethods: {}
|
|
1213
1226
|
};
|
|
1214
1227
|
var store = {
|
|
1215
1228
|
key,
|
|
@@ -1217,11 +1230,13 @@
|
|
|
1217
1230
|
return updater.token;
|
|
1218
1231
|
},
|
|
1219
1232
|
subscribe: function subscribe(dispatcher) {
|
|
1220
|
-
var _updater_createTunnel = updater.createTunnel(dispatcher), connect = _updater_createTunnel.connect, disconnect = _updater_createTunnel.disconnect;
|
|
1233
|
+
var _updater_createTunnel = updater.createTunnel(dispatcher || noop), connect = _updater_createTunnel.connect, disconnect = _updater_createTunnel.disconnect;
|
|
1221
1234
|
connect();
|
|
1222
1235
|
return disconnect;
|
|
1223
1236
|
},
|
|
1224
|
-
getInstance
|
|
1237
|
+
getInstance: function getInstance() {
|
|
1238
|
+
return extractInstance(updater, key.wrapper, propertiesCache);
|
|
1239
|
+
},
|
|
1225
1240
|
update: function update(args) {
|
|
1226
1241
|
var updateArgs = args !== null && args !== void 0 ? args : {};
|
|
1227
1242
|
if (updateArgs.key) {
|
|
@@ -1345,36 +1360,36 @@
|
|
|
1345
1360
|
|
|
1346
1361
|
// src/model/index.ts
|
|
1347
1362
|
function configModel(config2) {
|
|
1348
|
-
var model2 = function model3(modelFn,
|
|
1349
|
-
var currentSelector =
|
|
1363
|
+
var model2 = function model3(modelFn, wrapper) {
|
|
1364
|
+
var currentSelector = wrapper !== null && wrapper !== void 0 ? wrapper : function defaultSelector(i) {
|
|
1350
1365
|
return i();
|
|
1351
1366
|
};
|
|
1352
1367
|
var modelWrapper = function modelWrapper2(state) {
|
|
1353
1368
|
return modelFn(state);
|
|
1354
1369
|
};
|
|
1355
|
-
modelWrapper.
|
|
1370
|
+
modelWrapper.pipe = function pipe(s) {
|
|
1356
1371
|
return model3(modelFn, s);
|
|
1357
1372
|
};
|
|
1358
1373
|
modelWrapper.createKey = function createModelKey(state) {
|
|
1359
1374
|
return createKey(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
|
|
1360
1375
|
state,
|
|
1361
|
-
|
|
1376
|
+
wrapper: currentSelector
|
|
1362
1377
|
}) : _object_spread_props(_object_spread({}, config2), {
|
|
1363
|
-
|
|
1378
|
+
wrapper: currentSelector
|
|
1364
1379
|
}));
|
|
1365
1380
|
};
|
|
1366
1381
|
modelWrapper.createStore = function createModelStore(state) {
|
|
1367
1382
|
return createStore(modelFn, arguments.length ? _object_spread_props(_object_spread({}, config2), {
|
|
1368
1383
|
state,
|
|
1369
|
-
|
|
1384
|
+
wrapper: currentSelector
|
|
1370
1385
|
}) : _object_spread_props(_object_spread({}, config2), {
|
|
1371
|
-
|
|
1386
|
+
wrapper: currentSelector
|
|
1372
1387
|
}));
|
|
1373
1388
|
};
|
|
1374
1389
|
modelWrapper.extends = function extendsModelUsage(e) {
|
|
1375
1390
|
return Object.assign(modelWrapper, e);
|
|
1376
1391
|
};
|
|
1377
|
-
modelWrapper.
|
|
1392
|
+
modelWrapper.wrapper = currentSelector;
|
|
1378
1393
|
modelWrapper.modelUsageIdentifier = modelUsageIdentifier;
|
|
1379
1394
|
return modelWrapper;
|
|
1380
1395
|
};
|
package/esm/model/index.js
CHANGED
|
@@ -21,32 +21,32 @@ import { createStore, createField, createMethod } from "../store";
|
|
|
21
21
|
import { createKey } from "../key";
|
|
22
22
|
import { modelUsageIdentifier } from "../identifiers";
|
|
23
23
|
function configModel(config) {
|
|
24
|
-
const model = function model2(modelFn,
|
|
25
|
-
const currentSelector =
|
|
24
|
+
const model = function model2(modelFn, wrapper) {
|
|
25
|
+
const currentSelector = wrapper != null ? wrapper : function defaultSelector(i) {
|
|
26
26
|
return i();
|
|
27
27
|
};
|
|
28
28
|
const modelWrapper = function modelWrapper2(state) {
|
|
29
29
|
return modelFn(state);
|
|
30
30
|
};
|
|
31
|
-
modelWrapper.
|
|
31
|
+
modelWrapper.pipe = function pipe(s) {
|
|
32
32
|
return model2(modelFn, s);
|
|
33
33
|
};
|
|
34
34
|
modelWrapper.createKey = function createModelKey(state) {
|
|
35
35
|
return createKey(
|
|
36
36
|
modelFn,
|
|
37
|
-
arguments.length ? __spreadProps(__spreadValues({}, config), { state,
|
|
37
|
+
arguments.length ? __spreadProps(__spreadValues({}, config), { state, wrapper: currentSelector }) : __spreadProps(__spreadValues({}, config), { wrapper: currentSelector })
|
|
38
38
|
);
|
|
39
39
|
};
|
|
40
40
|
modelWrapper.createStore = function createModelStore(state) {
|
|
41
41
|
return createStore(
|
|
42
42
|
modelFn,
|
|
43
|
-
arguments.length ? __spreadProps(__spreadValues({}, config), { state,
|
|
43
|
+
arguments.length ? __spreadProps(__spreadValues({}, config), { state, wrapper: currentSelector }) : __spreadProps(__spreadValues({}, config), { wrapper: currentSelector })
|
|
44
44
|
);
|
|
45
45
|
};
|
|
46
46
|
modelWrapper.extends = function extendsModelUsage(e) {
|
|
47
47
|
return Object.assign(modelWrapper, e);
|
|
48
48
|
};
|
|
49
|
-
modelWrapper.
|
|
49
|
+
modelWrapper.wrapper = currentSelector;
|
|
50
50
|
modelWrapper.modelUsageIdentifier = modelUsageIdentifier;
|
|
51
51
|
return modelWrapper;
|
|
52
52
|
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createProxy, shallowEqual } from "../tools";
|
|
2
|
+
const cacheIdentify = {
|
|
3
|
+
field(d) {
|
|
4
|
+
if (!d) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const f = d;
|
|
8
|
+
return f.identifier === cacheIdentify.field;
|
|
9
|
+
},
|
|
10
|
+
method(d) {
|
|
11
|
+
if (typeof d !== "function") {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const m = d;
|
|
15
|
+
return m.identifier === cacheIdentify.method;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function wrapToField(cache, propertyName, value, onGot) {
|
|
19
|
+
const { cacheFields } = cache;
|
|
20
|
+
if (!cacheIdentify.field(value)) {
|
|
21
|
+
if (onGot) {
|
|
22
|
+
onGot(propertyName, value);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
const field = value;
|
|
27
|
+
const cachedField = cacheFields[propertyName];
|
|
28
|
+
if (cachedField) {
|
|
29
|
+
return cachedField.getter;
|
|
30
|
+
}
|
|
31
|
+
const getter = {
|
|
32
|
+
get() {
|
|
33
|
+
const currentField = cache.target[propertyName];
|
|
34
|
+
if (!cacheIdentify.field(currentField)) {
|
|
35
|
+
throw new Error("Field should always be field.");
|
|
36
|
+
}
|
|
37
|
+
const current = currentField.get();
|
|
38
|
+
const fieldInCache = cache.cacheFields[propertyName];
|
|
39
|
+
if (!currentField.deps || fieldInCache == null) {
|
|
40
|
+
cacheFields[propertyName] = {
|
|
41
|
+
getter,
|
|
42
|
+
value: current,
|
|
43
|
+
deps: currentField.deps
|
|
44
|
+
};
|
|
45
|
+
return current;
|
|
46
|
+
}
|
|
47
|
+
if (shallowEqual(currentField.deps, fieldInCache.deps)) {
|
|
48
|
+
return fieldInCache.value;
|
|
49
|
+
}
|
|
50
|
+
cacheFields[propertyName] = {
|
|
51
|
+
getter,
|
|
52
|
+
value: current,
|
|
53
|
+
deps: currentField.deps
|
|
54
|
+
};
|
|
55
|
+
return current;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
cacheFields[propertyName] = { getter, value: field.value, deps: field.deps };
|
|
59
|
+
return getter;
|
|
60
|
+
}
|
|
61
|
+
function wrapToActionMethod(cache, methodName) {
|
|
62
|
+
const { cacheMethods } = cache;
|
|
63
|
+
const cachedMethod = cacheMethods[methodName];
|
|
64
|
+
if (typeof cachedMethod === "function") {
|
|
65
|
+
return cachedMethod;
|
|
66
|
+
}
|
|
67
|
+
const actionMethod = function actionMethod2(...args) {
|
|
68
|
+
const { target } = cache;
|
|
69
|
+
const method = target[methodName];
|
|
70
|
+
if (typeof method !== "function") {
|
|
71
|
+
throw new Error("Can not change methods in runtime.");
|
|
72
|
+
}
|
|
73
|
+
return method(...args);
|
|
74
|
+
};
|
|
75
|
+
cacheMethods[methodName] = actionMethod;
|
|
76
|
+
return actionMethod;
|
|
77
|
+
}
|
|
78
|
+
const cacheProperties = (cache, onGet) => {
|
|
79
|
+
return function createCachePropertiesProxy() {
|
|
80
|
+
const instance = cache.target;
|
|
81
|
+
const properties = Object.getOwnPropertyNames(instance);
|
|
82
|
+
const handleGetter = function handleGetter2(key, value) {
|
|
83
|
+
if (!onGet) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
onGet(key, value);
|
|
87
|
+
};
|
|
88
|
+
return createProxy(instance, {
|
|
89
|
+
get(target, p) {
|
|
90
|
+
const value = target[p];
|
|
91
|
+
if (typeof value === "function" && properties.indexOf(p) >= 0) {
|
|
92
|
+
const actionMethod = wrapToActionMethod(cache, p);
|
|
93
|
+
Object.assign(actionMethod, value);
|
|
94
|
+
handleGetter(p, actionMethod);
|
|
95
|
+
return actionMethod;
|
|
96
|
+
}
|
|
97
|
+
return wrapToField(cache, p, value, handleGetter);
|
|
98
|
+
},
|
|
99
|
+
set() {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
export {
|
|
106
|
+
cacheIdentify,
|
|
107
|
+
cacheProperties
|
|
108
|
+
};
|
|
@@ -1,92 +1,3 @@
|
|
|
1
|
-
import { cacheIdentify } from "../instance";
|
|
2
|
-
import { createProxy, shallowEqual } from "../../tools";
|
|
3
|
-
function wrapToField(cache, propertyName, value, onGot) {
|
|
4
|
-
const { cacheFields } = cache;
|
|
5
|
-
if (!cacheIdentify.field(value)) {
|
|
6
|
-
if (onGot) {
|
|
7
|
-
onGot(propertyName, value);
|
|
8
|
-
}
|
|
9
|
-
return value;
|
|
10
|
-
}
|
|
11
|
-
const field = value;
|
|
12
|
-
const cachedField = cacheFields[propertyName];
|
|
13
|
-
if (cachedField) {
|
|
14
|
-
return cachedField.getter;
|
|
15
|
-
}
|
|
16
|
-
const getter = {
|
|
17
|
-
get() {
|
|
18
|
-
const currentField = cache.target[propertyName];
|
|
19
|
-
if (!cacheIdentify.field(currentField)) {
|
|
20
|
-
throw new Error("Field should always be field.");
|
|
21
|
-
}
|
|
22
|
-
const current = currentField.get();
|
|
23
|
-
const fieldInCache = cache.cacheFields[propertyName];
|
|
24
|
-
if (!currentField.deps || fieldInCache == null) {
|
|
25
|
-
cacheFields[propertyName] = {
|
|
26
|
-
getter,
|
|
27
|
-
value: current,
|
|
28
|
-
deps: currentField.deps
|
|
29
|
-
};
|
|
30
|
-
return current;
|
|
31
|
-
}
|
|
32
|
-
if (shallowEqual(currentField.deps, fieldInCache.deps)) {
|
|
33
|
-
return fieldInCache.value;
|
|
34
|
-
}
|
|
35
|
-
cacheFields[propertyName] = {
|
|
36
|
-
getter,
|
|
37
|
-
value: current,
|
|
38
|
-
deps: currentField.deps
|
|
39
|
-
};
|
|
40
|
-
return current;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
cacheFields[propertyName] = { getter, value: field.value, deps: field.deps };
|
|
44
|
-
return getter;
|
|
45
|
-
}
|
|
46
|
-
function wrapToActionMethod(cache, methodName) {
|
|
47
|
-
const { cacheMethods } = cache;
|
|
48
|
-
const cachedMethod = cacheMethods[methodName];
|
|
49
|
-
if (typeof cachedMethod === "function") {
|
|
50
|
-
return cachedMethod;
|
|
51
|
-
}
|
|
52
|
-
const actionMethod = function actionMethod2(...args) {
|
|
53
|
-
const { target } = cache;
|
|
54
|
-
const method = target[methodName];
|
|
55
|
-
if (typeof method !== "function") {
|
|
56
|
-
throw new Error("Can not change methods in runtime.");
|
|
57
|
-
}
|
|
58
|
-
return method(...args);
|
|
59
|
-
};
|
|
60
|
-
cacheMethods[methodName] = actionMethod;
|
|
61
|
-
return actionMethod;
|
|
62
|
-
}
|
|
63
|
-
const cacheProperties = (cache, onGet) => {
|
|
64
|
-
return function createCachePropertiesProxy() {
|
|
65
|
-
const instance = cache.target;
|
|
66
|
-
const properties = Object.getOwnPropertyNames(instance);
|
|
67
|
-
const handleGetter = function handleGetter2(key, value) {
|
|
68
|
-
if (!onGet) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
onGet(key, value);
|
|
72
|
-
};
|
|
73
|
-
return createProxy(instance, {
|
|
74
|
-
get(target, p) {
|
|
75
|
-
const value = target[p];
|
|
76
|
-
if (typeof value === "function" && properties.indexOf(p) >= 0) {
|
|
77
|
-
const actionMethod = wrapToActionMethod(cache, p);
|
|
78
|
-
Object.assign(actionMethod, value);
|
|
79
|
-
handleGetter(p, actionMethod);
|
|
80
|
-
return actionMethod;
|
|
81
|
-
}
|
|
82
|
-
return wrapToField(cache, p, value, handleGetter);
|
|
83
|
-
},
|
|
84
|
-
set() {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
1
|
function createSelector(store, opts) {
|
|
91
2
|
const { equality } = opts != null ? opts : {};
|
|
92
3
|
const selectStore = {
|
|
@@ -107,27 +18,11 @@ function createSelector(store, opts) {
|
|
|
107
18
|
selectStore.selectedInstance = nextSelectedInstance;
|
|
108
19
|
}
|
|
109
20
|
};
|
|
110
|
-
const propertiesCache = {
|
|
111
|
-
target: store.getInstance(),
|
|
112
|
-
cacheFields: {},
|
|
113
|
-
cacheMethods: {}
|
|
114
|
-
};
|
|
115
21
|
const generateSelectedInstance = function generateSelectedInstance2(getInstance) {
|
|
116
|
-
const { key: storeKey } = store;
|
|
117
22
|
if (cache.selector) {
|
|
118
23
|
return cache.selector(getInstance);
|
|
119
24
|
}
|
|
120
|
-
|
|
121
|
-
return getInstance();
|
|
122
|
-
}
|
|
123
|
-
const result = storeKey == null ? void 0 : storeKey.selector(getInstance);
|
|
124
|
-
if (result == null || typeof result !== "object") {
|
|
125
|
-
throw new Error(
|
|
126
|
-
"The default selector result should be an object or array"
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
propertiesCache.target = result;
|
|
130
|
-
return cacheProperties(propertiesCache)();
|
|
25
|
+
return getInstance();
|
|
131
26
|
};
|
|
132
27
|
selectStore.selectedInstance = generateSelectedInstance(store.getInstance);
|
|
133
28
|
const enhance = (dispatcher) => {
|
|
@@ -160,6 +55,5 @@ function createSelector(store, opts) {
|
|
|
160
55
|
};
|
|
161
56
|
}
|
|
162
57
|
export {
|
|
163
|
-
cacheProperties,
|
|
164
58
|
createSelector
|
|
165
59
|
};
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { extractInstance } from "../instance";
|
|
2
|
+
import { cacheIdentify } from "../cache";
|
|
2
3
|
function createSignal(store) {
|
|
3
4
|
const signalStore = {
|
|
4
5
|
collection: {},
|
|
5
6
|
started: false,
|
|
6
7
|
enabled: false
|
|
7
8
|
};
|
|
9
|
+
const propertiesCache = {
|
|
10
|
+
target: store.getInstance(),
|
|
11
|
+
cacheFields: {},
|
|
12
|
+
cacheMethods: {}
|
|
13
|
+
};
|
|
8
14
|
const enhance = (dispatcher) => {
|
|
9
15
|
return (action) => {
|
|
10
16
|
if (!signalStore.enabled) {
|
|
@@ -15,7 +21,11 @@ function createSignal(store) {
|
|
|
15
21
|
if (collection == null) {
|
|
16
22
|
return;
|
|
17
23
|
}
|
|
18
|
-
const storeInstance = extractInstance(
|
|
24
|
+
const storeInstance = extractInstance(
|
|
25
|
+
store.updater,
|
|
26
|
+
store.key.wrapper,
|
|
27
|
+
propertiesCache
|
|
28
|
+
);
|
|
19
29
|
const keys = Object.keys(collection);
|
|
20
30
|
if (!keys.length) {
|
|
21
31
|
return;
|
|
@@ -53,7 +63,9 @@ function createSignal(store) {
|
|
|
53
63
|
const { cutOff } = options != null ? options : {};
|
|
54
64
|
return extractInstance(
|
|
55
65
|
store.updater,
|
|
56
|
-
|
|
66
|
+
store.key.wrapper,
|
|
67
|
+
propertiesCache,
|
|
68
|
+
{ onGet: cutOff ? void 0 : collectUsedFields }
|
|
57
69
|
);
|
|
58
70
|
};
|
|
59
71
|
const signal = function signal2(options) {
|
package/esm/store/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var __objRest = (source, exclude) => {
|
|
|
32
32
|
import { createUpdater } from "../updater";
|
|
33
33
|
import { isModelKey, isModelUsage } from "../validation";
|
|
34
34
|
import { modelKeyIdentifier, modelStoreIdentifier } from "../identifiers";
|
|
35
|
+
import { noop } from "../tools";
|
|
35
36
|
import {
|
|
36
37
|
extractInstance,
|
|
37
38
|
createField as createInstanceField,
|
|
@@ -42,14 +43,14 @@ function createPrimaryKey(modelFn, config = {}) {
|
|
|
42
43
|
const ifModelKey = isModelKey(modelFn);
|
|
43
44
|
const ifModelUsage = isModelUsage(modelFn);
|
|
44
45
|
const model = ifModelKey ? modelFn.source : modelFn;
|
|
45
|
-
const
|
|
46
|
+
const wrapper = (_a = config.wrapper) != null ? _a : ifModelKey || ifModelUsage ? modelFn.wrapper : function defaultSelector(i) {
|
|
46
47
|
return i();
|
|
47
48
|
};
|
|
48
49
|
const wrapModel = function wrapModel2(state) {
|
|
49
50
|
return model(state);
|
|
50
51
|
};
|
|
51
52
|
wrapModel.source = model;
|
|
52
|
-
wrapModel.
|
|
53
|
+
wrapModel.wrapper = wrapper;
|
|
53
54
|
wrapModel.modelKeyIdentifier = modelKeyIdentifier;
|
|
54
55
|
if ("state" in config) {
|
|
55
56
|
wrapModel.defaultState = config.state;
|
|
@@ -87,8 +88,10 @@ function createStore(modelLike, config = {}) {
|
|
|
87
88
|
};
|
|
88
89
|
const updater = createUpdater(model, combinedMiddleWare, conf);
|
|
89
90
|
const key = modelKey != null ? modelKey : createPrimaryKey(model, config);
|
|
90
|
-
const
|
|
91
|
-
|
|
91
|
+
const propertiesCache = {
|
|
92
|
+
target: updater.instance,
|
|
93
|
+
cacheFields: {},
|
|
94
|
+
cacheMethods: {}
|
|
92
95
|
};
|
|
93
96
|
const store = {
|
|
94
97
|
key,
|
|
@@ -96,11 +99,13 @@ function createStore(modelLike, config = {}) {
|
|
|
96
99
|
return updater.token;
|
|
97
100
|
},
|
|
98
101
|
subscribe(dispatcher) {
|
|
99
|
-
const { connect, disconnect } = updater.createTunnel(dispatcher);
|
|
102
|
+
const { connect, disconnect } = updater.createTunnel(dispatcher || noop);
|
|
100
103
|
connect();
|
|
101
104
|
return disconnect;
|
|
102
105
|
},
|
|
103
|
-
getInstance
|
|
106
|
+
getInstance() {
|
|
107
|
+
return extractInstance(updater, key.wrapper, propertiesCache);
|
|
108
|
+
},
|
|
104
109
|
update(args) {
|
|
105
110
|
const updateArgs = args != null ? args : {};
|
|
106
111
|
if (updateArgs.key) {
|
package/esm/store/instance.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
16
|
}
|
|
14
|
-
|
|
15
|
-
return m.identifier === cacheIdentify.method;
|
|
16
|
-
}
|
|
17
|
+
return a;
|
|
17
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { createProxy, shallowEqual } from "../tools";
|
|
21
|
+
import { cacheIdentify, cacheProperties } from "./cache";
|
|
18
22
|
function createField(callback, deps) {
|
|
19
23
|
const currentDeps = function computeDeps() {
|
|
20
24
|
if (deps == null) {
|
|
@@ -79,17 +83,22 @@ function wrapToActionMethod(updater, methodName) {
|
|
|
79
83
|
return actionMethod;
|
|
80
84
|
}
|
|
81
85
|
function wrapToField(updater, propertyName, value, onGot) {
|
|
82
|
-
|
|
83
|
-
if (!cacheIdentify.field(value)) {
|
|
86
|
+
function collect(pName, v) {
|
|
84
87
|
if (onGot) {
|
|
85
|
-
onGot(
|
|
88
|
+
onGot(pName, v);
|
|
86
89
|
}
|
|
90
|
+
}
|
|
91
|
+
const { cacheFields } = updater;
|
|
92
|
+
if (!cacheIdentify.field(value)) {
|
|
93
|
+
collect(propertyName, value);
|
|
87
94
|
return value;
|
|
88
95
|
}
|
|
89
96
|
const field = value;
|
|
90
97
|
const cachedField = cacheFields[propertyName];
|
|
91
|
-
if (cachedField) {
|
|
92
|
-
|
|
98
|
+
if (cachedField && (field.deps && shallowEqual(cachedField.deps, field.deps) || !field.deps && cachedField.value === field.value)) {
|
|
99
|
+
const cacheFieldGetter = cachedField.getter;
|
|
100
|
+
collect(propertyName, cacheFieldGetter);
|
|
101
|
+
return cacheFieldGetter;
|
|
93
102
|
}
|
|
94
103
|
const getter = {
|
|
95
104
|
get() {
|
|
@@ -119,38 +128,46 @@ function wrapToField(updater, propertyName, value, onGot) {
|
|
|
119
128
|
}
|
|
120
129
|
};
|
|
121
130
|
cacheFields[propertyName] = { getter, value: field.value, deps: field.deps };
|
|
131
|
+
collect(propertyName, getter);
|
|
122
132
|
return getter;
|
|
123
133
|
}
|
|
124
|
-
function extractInstance(updater,
|
|
125
|
-
const {
|
|
126
|
-
if (typeof instance !== "object" || !instance) {
|
|
127
|
-
throw new Error("The instance should be an object or array.");
|
|
128
|
-
}
|
|
129
|
-
const properties = Object.getOwnPropertyNames(instance);
|
|
134
|
+
function extractInstance(updater, wrapper, cache, opts) {
|
|
135
|
+
const { onGet } = opts || {};
|
|
130
136
|
const handleGetter = function handleGetter2(key, value) {
|
|
131
137
|
if (!onGet) {
|
|
132
138
|
return;
|
|
133
139
|
}
|
|
134
140
|
onGet(key, value);
|
|
135
141
|
};
|
|
136
|
-
|
|
142
|
+
const { instance } = updater;
|
|
143
|
+
if (typeof instance !== "object" || !instance) {
|
|
144
|
+
throw new Error("The instance should be an object or array.");
|
|
145
|
+
}
|
|
146
|
+
const properties = Object.getOwnPropertyNames(instance);
|
|
147
|
+
const proxiedInstance = createProxy(instance, {
|
|
137
148
|
get(target, p) {
|
|
138
149
|
const value = target[p];
|
|
139
150
|
if (typeof value === "function" && properties.indexOf(p) >= 0) {
|
|
140
151
|
const actionMethod = wrapToActionMethod(updater, p);
|
|
141
152
|
Object.assign(actionMethod, value);
|
|
142
|
-
handleGetter(p, actionMethod);
|
|
143
153
|
return actionMethod;
|
|
144
154
|
}
|
|
145
|
-
return wrapToField(updater, p, value
|
|
155
|
+
return wrapToField(updater, p, value);
|
|
146
156
|
},
|
|
147
157
|
set() {
|
|
148
158
|
return false;
|
|
149
159
|
}
|
|
150
160
|
});
|
|
161
|
+
function generateInstance() {
|
|
162
|
+
return proxiedInstance;
|
|
163
|
+
}
|
|
164
|
+
const wrapped = wrapper(generateInstance);
|
|
165
|
+
if (typeof wrapped === "object" && wrapped != null) {
|
|
166
|
+
return cacheProperties(__spreadProps(__spreadValues({}, cache), { target: wrapped }), handleGetter)();
|
|
167
|
+
}
|
|
168
|
+
return wrapped;
|
|
151
169
|
}
|
|
152
170
|
export {
|
|
153
|
-
cacheIdentify,
|
|
154
171
|
createField,
|
|
155
172
|
createMethod,
|
|
156
173
|
extractInstance
|
package/index.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ export declare interface Store<
|
|
|
99
99
|
> extends StoreIndex<S, T, R> {
|
|
100
100
|
subscribe: (dispatcher: Dispatch) => () => void;
|
|
101
101
|
getToken: () => Token;
|
|
102
|
-
getInstance: () =>
|
|
102
|
+
getInstance: () => ReturnType<R>;
|
|
103
103
|
update: (args?: {
|
|
104
104
|
model?: Model<S, T>;
|
|
105
105
|
key?: Key<S, T, R>;
|
|
@@ -172,10 +172,10 @@ export declare interface ModelUsage<
|
|
|
172
172
|
(s: S): ValidInstance<S, T>;
|
|
173
173
|
createKey: <D extends S>(state?: D) => ModelKey<S, T, R>;
|
|
174
174
|
createStore: <D extends S>(state?: D) => Store<S, T, R>;
|
|
175
|
-
|
|
175
|
+
pipe: <C extends (instance: () => T) => any = (instance: () => T) => T>(
|
|
176
176
|
s: C
|
|
177
177
|
) => ModelUsage<S, T, C>;
|
|
178
|
-
|
|
178
|
+
wrapper: R;
|
|
179
179
|
extends: <E extends Record<string, any>>(e: E) => ModelUsage<S, T, R> & E;
|
|
180
180
|
}
|
|
181
181
|
|
|
@@ -213,7 +213,7 @@ declare interface SignalStore<
|
|
|
213
213
|
getToken: () => Token;
|
|
214
214
|
subscribe: (dispatcher: Dispatch) => () => void;
|
|
215
215
|
getSignal: () => {
|
|
216
|
-
(options?: SignalOptions):
|
|
216
|
+
(options?: SignalOptions): ReturnType<R>;
|
|
217
217
|
startStatistics: () => void;
|
|
218
218
|
stopStatistics: () => void;
|
|
219
219
|
subscribe: (dispatcher: Dispatch) => () => void;
|
|
@@ -224,14 +224,14 @@ declare interface SignalStore<
|
|
|
224
224
|
export declare function createSignal<
|
|
225
225
|
S,
|
|
226
226
|
T extends ModelInstance,
|
|
227
|
-
R extends (instance: () => T) => any = (instance: () => T) =>
|
|
227
|
+
R extends (instance: () => T) => any = (instance: () => T) => T
|
|
228
228
|
>(store: Store<S, T, R>): SignalStore<S, T, R>;
|
|
229
229
|
|
|
230
230
|
/** createSelector * */
|
|
231
231
|
|
|
232
232
|
declare type SelectMethod<
|
|
233
233
|
T extends ModelInstance = any,
|
|
234
|
-
R extends (instance: () => T) => any = (instance: () => T) =>
|
|
234
|
+
R extends (instance: () => T) => any = (instance: () => T) => T
|
|
235
235
|
> = {
|
|
236
236
|
(): ReturnType<R>;
|
|
237
237
|
<C extends (instance: () => T) => any>(selector: C): ReturnType<C>;
|
|
@@ -244,7 +244,7 @@ declare type SelectMethod<
|
|
|
244
244
|
declare interface SelectorStore<
|
|
245
245
|
S = any,
|
|
246
246
|
T extends ModelInstance = any,
|
|
247
|
-
R extends (instance: () => T) => any = (instance: () => T) =>
|
|
247
|
+
R extends (instance: () => T) => any = (instance: () => T) => T
|
|
248
248
|
> extends StoreIndex<S, T, R> {
|
|
249
249
|
getToken: () => Token;
|
|
250
250
|
subscribe: (dispatcher: Dispatch) => () => void;
|
|
@@ -258,7 +258,7 @@ declare interface SelectorOption<T = any> {
|
|
|
258
258
|
export declare function createSelector<
|
|
259
259
|
S,
|
|
260
260
|
T extends ModelInstance,
|
|
261
|
-
R extends (instance: () => T) => any = (instance: () => T) =>
|
|
261
|
+
R extends (instance: () => T) => any = (instance: () => T) => T
|
|
262
262
|
>(store: Store<S, T, R>, opts?: SelectorOption): SelectorStore<S, T, R>;
|
|
263
263
|
|
|
264
264
|
/** config * */
|