as-model 0.2.3 → 0.2.5
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 +1309 -1270
- package/esm/defaults.js +6 -0
- package/esm/model/index.js +2 -3
- package/esm/store/instance.js +28 -21
- package/index.d.ts +325 -325
- package/package.json +1 -1
package/esm/defaults.js
ADDED
package/esm/model/index.js
CHANGED
|
@@ -20,11 +20,10 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { createStore, createField, createMethod } from "../store";
|
|
21
21
|
import { createKey } from "../key";
|
|
22
22
|
import { modelUsageIdentifier } from "../identifiers";
|
|
23
|
+
import { defaultSelector } from "../defaults";
|
|
23
24
|
function configModel(config) {
|
|
24
25
|
const model = function model2(modelFn, wrapper) {
|
|
25
|
-
const currentSelector = wrapper != null ? wrapper :
|
|
26
|
-
return i();
|
|
27
|
-
};
|
|
26
|
+
const currentSelector = wrapper != null ? wrapper : defaultSelector;
|
|
28
27
|
const modelWrapper = function modelWrapper2(state) {
|
|
29
28
|
return modelFn(state);
|
|
30
29
|
};
|
package/esm/store/instance.js
CHANGED
|
@@ -18,6 +18,7 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
import { createProxy, shallowEqual } from "../tools";
|
|
21
|
+
import { defaultSelector } from "../defaults";
|
|
21
22
|
import { cacheIdentify, cacheProperties } from "./cache";
|
|
22
23
|
function createField(callback, deps) {
|
|
23
24
|
const currentDeps = function computeDeps() {
|
|
@@ -139,31 +140,37 @@ function extractInstance(updater, wrapper, cache, opts) {
|
|
|
139
140
|
}
|
|
140
141
|
onGet(key, value);
|
|
141
142
|
};
|
|
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, {
|
|
148
|
-
get(target, p) {
|
|
149
|
-
const value = target[p];
|
|
150
|
-
if (typeof value === "function" && properties.indexOf(p) >= 0) {
|
|
151
|
-
const actionMethod = wrapToActionMethod(updater, p);
|
|
152
|
-
Object.assign(actionMethod, value);
|
|
153
|
-
return actionMethod;
|
|
154
|
-
}
|
|
155
|
-
return wrapToField(updater, p, value);
|
|
156
|
-
},
|
|
157
|
-
set() {
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
143
|
function generateInstance() {
|
|
162
|
-
|
|
144
|
+
const { instance } = updater;
|
|
145
|
+
if (typeof instance !== "object" || !instance) {
|
|
146
|
+
throw new Error("The instance should be an object or array.");
|
|
147
|
+
}
|
|
148
|
+
const properties = Object.getOwnPropertyNames(instance);
|
|
149
|
+
return createProxy(instance, {
|
|
150
|
+
get(target, p) {
|
|
151
|
+
const value = target[p];
|
|
152
|
+
if (typeof value === "function" && properties.indexOf(p) >= 0) {
|
|
153
|
+
const actionMethod = wrapToActionMethod(updater, p);
|
|
154
|
+
Object.assign(actionMethod, value);
|
|
155
|
+
return actionMethod;
|
|
156
|
+
}
|
|
157
|
+
return wrapToField(updater, p, value);
|
|
158
|
+
},
|
|
159
|
+
set() {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
const proxiedInstance = generateInstance();
|
|
165
|
+
if (wrapper == null || wrapper === defaultSelector) {
|
|
165
166
|
return proxiedInstance;
|
|
166
167
|
}
|
|
168
|
+
if (wrapper === defaultSelector) {
|
|
169
|
+
return cacheProperties(
|
|
170
|
+
__spreadProps(__spreadValues({}, cache), { target: proxiedInstance }),
|
|
171
|
+
handleGetter
|
|
172
|
+
)();
|
|
173
|
+
}
|
|
167
174
|
const wrapped = wrapper(generateInstance);
|
|
168
175
|
if (typeof wrapped === "object" && wrapped != null) {
|
|
169
176
|
return cacheProperties(__spreadProps(__spreadValues({}, cache), { target: wrapped }), handleGetter)();
|