as-model 0.1.9 → 0.1.11
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 +1 -3
- package/esm/index.js +34 -19
- package/esm/key/index.js +43 -38
- package/esm/model/index.js +30 -17
- package/esm/store/enhance/selector.js +43 -50
- package/esm/store/enhance/signal.js +21 -29
- package/esm/store/index.js +56 -40
- package/esm/store/instance.js +41 -55
- package/esm/tools/proxy.js +34 -14
- package/esm/tools/shallowEqual.js +11 -12
- package/esm/updater/index.js +61 -47
- package/esm/updater/notifier.js +59 -71
- package/esm/updater/tunnel.js +61 -63
- package/esm/validation/index.js +7 -7
- package/index.d.ts +1 -3
- package/package.json +1 -1
- package/esm/model/type.js +0 -0
- package/esm/tools.js +0 -78
package/dist/index.js
CHANGED
|
@@ -858,9 +858,7 @@
|
|
|
858
858
|
signal.subscribe = function subscribe(dispatchCallback) {
|
|
859
859
|
return store.subscribe(dispatchCallback);
|
|
860
860
|
};
|
|
861
|
-
signal.
|
|
862
|
-
return store.payload(callback);
|
|
863
|
-
};
|
|
861
|
+
signal.store = store;
|
|
864
862
|
signalStore.enabled = true;
|
|
865
863
|
signalStore.started = true;
|
|
866
864
|
return signal;
|
package/esm/index.js
CHANGED
|
@@ -1,33 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
3
20
|
import { createStore as cs } from "./store";
|
|
4
21
|
import { createKey as ck, createStores as css } from "./key";
|
|
5
22
|
import { configModel } from "./model";
|
|
6
|
-
function config() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
state
|
|
11
|
-
|
|
23
|
+
function config(configuration = {}) {
|
|
24
|
+
const createStore2 = function createStore3(modelLike, state) {
|
|
25
|
+
return cs(
|
|
26
|
+
modelLike,
|
|
27
|
+
arguments.length > 1 ? __spreadProps(__spreadValues({}, configuration), { state }) : configuration
|
|
28
|
+
);
|
|
12
29
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
const createKey2 = function createKey3(model3, state) {
|
|
31
|
+
const isKeySetState = arguments.length > 1;
|
|
32
|
+
const key = ck(
|
|
33
|
+
model3,
|
|
34
|
+
isKeySetState ? __spreadProps(__spreadValues({}, configuration), { state }) : configuration
|
|
35
|
+
);
|
|
18
36
|
key.createStore = function createKeyStore(s) {
|
|
19
37
|
return arguments.length > 0 ? createStore2(key, s) : createStore2(key);
|
|
20
38
|
};
|
|
21
39
|
return key;
|
|
22
40
|
};
|
|
23
41
|
createKey2.isModelKey = ck.isModelKey;
|
|
24
|
-
|
|
25
|
-
for (var _len = arguments.length, modelKeys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
26
|
-
modelKeys[_key] = arguments[_key];
|
|
27
|
-
}
|
|
42
|
+
const createStores2 = function createStores3(...modelKeys) {
|
|
28
43
|
return css(modelKeys, configuration);
|
|
29
44
|
};
|
|
30
|
-
|
|
45
|
+
const model2 = configModel(configuration);
|
|
31
46
|
return {
|
|
32
47
|
createStore: createStore2,
|
|
33
48
|
createKey: createKey2,
|
|
@@ -35,7 +50,7 @@ function config() {
|
|
|
35
50
|
model: model2
|
|
36
51
|
};
|
|
37
52
|
}
|
|
38
|
-
|
|
53
|
+
const { createStore, createKey, createStores, model } = config();
|
|
39
54
|
import { createSignal, createSelector } from "./store";
|
|
40
55
|
import { validations } from "./validation";
|
|
41
56
|
import { shallowEqual } from "./tools";
|
package/esm/key/index.js
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
3
20
|
import { createStore, createPrimaryKey } from "../store";
|
|
4
21
|
import { isModelKey, validations } from "../validation";
|
|
5
|
-
function createKey(model) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var storeConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
10
|
-
return createStore(wrapModel, _object_spread({}, config, storeConfig));
|
|
22
|
+
function createKey(model, config = {}) {
|
|
23
|
+
const wrapModel = createPrimaryKey(model, config);
|
|
24
|
+
wrapModel.createStore = function createKeyStore(storeConfig = {}) {
|
|
25
|
+
return createStore(wrapModel, __spreadValues(__spreadValues({}, config), storeConfig));
|
|
11
26
|
};
|
|
12
27
|
wrapModel.extends = function extendsKey(e) {
|
|
13
28
|
return Object.assign(wrapModel, e);
|
|
@@ -15,23 +30,21 @@ function createKey(model) {
|
|
|
15
30
|
return wrapModel;
|
|
16
31
|
}
|
|
17
32
|
createKey.isModelKey = isModelKey;
|
|
18
|
-
function createStores(modelKeys) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
destroyed: false
|
|
22
|
-
};
|
|
23
|
-
var storeUnits = modelKeys.map(function(modelKey) {
|
|
33
|
+
function createStores(modelKeys, config = {}) {
|
|
34
|
+
const state = { destroyed: false };
|
|
35
|
+
const storeUnits = modelKeys.map((modelKey) => {
|
|
24
36
|
if (typeof modelKey === "function") {
|
|
25
37
|
return modelKey.createStore();
|
|
26
38
|
}
|
|
27
|
-
|
|
28
|
-
return createStore(
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
const k = modelKey.key;
|
|
40
|
+
return createStore(
|
|
41
|
+
k,
|
|
42
|
+
"defaultState" in k ? __spreadProps(__spreadValues({}, config), { state: k.defaultState }) : config
|
|
43
|
+
);
|
|
31
44
|
});
|
|
32
45
|
return {
|
|
33
|
-
find
|
|
34
|
-
|
|
46
|
+
find(key) {
|
|
47
|
+
const found = storeUnits.find((c) => {
|
|
35
48
|
if (typeof key === "function") {
|
|
36
49
|
return c.key === key;
|
|
37
50
|
}
|
|
@@ -42,36 +55,28 @@ function createStores(modelKeys) {
|
|
|
42
55
|
}
|
|
43
56
|
return found;
|
|
44
57
|
},
|
|
45
|
-
update
|
|
46
|
-
for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
47
|
-
keys[_key] = arguments[_key];
|
|
48
|
-
}
|
|
58
|
+
update(...keys) {
|
|
49
59
|
if (state.destroyed) {
|
|
50
60
|
return;
|
|
51
61
|
}
|
|
52
|
-
storeUnits.forEach(
|
|
53
|
-
|
|
62
|
+
storeUnits.forEach((un, i) => {
|
|
63
|
+
const keyLike = keys[i];
|
|
54
64
|
if (!keyLike) {
|
|
55
65
|
return;
|
|
56
66
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
Object.assign(un, {
|
|
60
|
-
key
|
|
61
|
-
});
|
|
67
|
+
const ifIsModelKey = validations.isModelKey(keyLike);
|
|
68
|
+
const key = ifIsModelKey ? keyLike : keyLike.key;
|
|
69
|
+
Object.assign(un, { key });
|
|
62
70
|
un.update({
|
|
63
71
|
model: ifIsModelKey ? keyLike.source : keyLike.key.source
|
|
64
72
|
});
|
|
65
73
|
});
|
|
66
74
|
},
|
|
67
|
-
keys
|
|
68
|
-
return storeUnits.map(
|
|
69
|
-
var key = param.key;
|
|
70
|
-
return key;
|
|
71
|
-
});
|
|
75
|
+
keys() {
|
|
76
|
+
return storeUnits.map(({ key }) => key);
|
|
72
77
|
},
|
|
73
|
-
destroy
|
|
74
|
-
storeUnits.forEach(
|
|
78
|
+
destroy() {
|
|
79
|
+
storeUnits.forEach((unit) => {
|
|
75
80
|
unit.destroy();
|
|
76
81
|
});
|
|
77
82
|
state.destroyed = true;
|
package/esm/model/index.js
CHANGED
|
@@ -1,34 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
3
20
|
import { createStore, createField, createMethod } from "../store";
|
|
4
21
|
import { createKey } from "../key";
|
|
5
22
|
import { modelUsageIdentifier } from "../identifiers";
|
|
6
23
|
function configModel(config) {
|
|
7
|
-
|
|
8
|
-
|
|
24
|
+
const model = function model2(modelFn, selector) {
|
|
25
|
+
const currentSelector = selector != null ? selector : function defaultSelector(i) {
|
|
9
26
|
return i();
|
|
10
27
|
};
|
|
11
|
-
|
|
28
|
+
const modelWrapper = function modelWrapper2(state) {
|
|
12
29
|
return modelFn(state);
|
|
13
30
|
};
|
|
14
31
|
modelWrapper.select = function select(s) {
|
|
15
32
|
return model2(modelFn, s);
|
|
16
33
|
};
|
|
17
34
|
modelWrapper.createKey = function createModelKey(state) {
|
|
18
|
-
return createKey(
|
|
19
|
-
|
|
20
|
-
selector: currentSelector
|
|
21
|
-
|
|
22
|
-
selector: currentSelector
|
|
23
|
-
}));
|
|
35
|
+
return createKey(
|
|
36
|
+
modelFn,
|
|
37
|
+
arguments.length ? __spreadProps(__spreadValues({}, config), { state, selector: currentSelector }) : __spreadProps(__spreadValues({}, config), { selector: currentSelector })
|
|
38
|
+
);
|
|
24
39
|
};
|
|
25
40
|
modelWrapper.createStore = function createModelStore(state) {
|
|
26
|
-
return createStore(
|
|
27
|
-
|
|
28
|
-
selector: currentSelector
|
|
29
|
-
|
|
30
|
-
selector: currentSelector
|
|
31
|
-
}));
|
|
41
|
+
return createStore(
|
|
42
|
+
modelFn,
|
|
43
|
+
arguments.length ? __spreadProps(__spreadValues({}, config), { state, selector: currentSelector }) : __spreadProps(__spreadValues({}, config), { selector: currentSelector })
|
|
44
|
+
);
|
|
32
45
|
};
|
|
33
46
|
modelWrapper.extends = function extendsModelUsage(e) {
|
|
34
47
|
return Object.assign(modelWrapper, e);
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
2
|
-
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
3
1
|
import { cacheIdentify } from "../instance";
|
|
4
2
|
import { createProxy, shallowEqual } from "../../tools";
|
|
5
3
|
function wrapToField(cache, propertyName, value, onGot) {
|
|
6
|
-
|
|
4
|
+
const { cacheFields } = cache;
|
|
7
5
|
if (!cacheIdentify.field(value)) {
|
|
8
6
|
if (onGot) {
|
|
9
7
|
onGot(propertyName, value);
|
|
10
8
|
}
|
|
11
9
|
return value;
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const field = value;
|
|
12
|
+
const cachedField = cacheFields[propertyName];
|
|
15
13
|
if (cachedField) {
|
|
16
14
|
return cachedField.getter;
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
get
|
|
20
|
-
|
|
16
|
+
const getter = {
|
|
17
|
+
get() {
|
|
18
|
+
const currentField = cache.target[propertyName];
|
|
21
19
|
if (!cacheIdentify.field(currentField)) {
|
|
22
20
|
throw new Error("Field should always be field.");
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const current = currentField.get();
|
|
23
|
+
const fieldInCache = cache.cacheFields[propertyName];
|
|
26
24
|
if (!currentField.deps || fieldInCache == null) {
|
|
27
25
|
cacheFields[propertyName] = {
|
|
28
26
|
getter,
|
|
@@ -42,105 +40,100 @@ function wrapToField(cache, propertyName, value, onGot) {
|
|
|
42
40
|
return current;
|
|
43
41
|
}
|
|
44
42
|
};
|
|
45
|
-
cacheFields[propertyName] = {
|
|
46
|
-
getter,
|
|
47
|
-
value: field.value,
|
|
48
|
-
deps: field.deps
|
|
49
|
-
};
|
|
43
|
+
cacheFields[propertyName] = { getter, value: field.value, deps: field.deps };
|
|
50
44
|
return getter;
|
|
51
45
|
}
|
|
52
46
|
function wrapToActionMethod(cache, methodName) {
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
const { cacheMethods } = cache;
|
|
48
|
+
const cachedMethod = cacheMethods[methodName];
|
|
55
49
|
if (typeof cachedMethod === "function") {
|
|
56
50
|
return cachedMethod;
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
var target = cache.target;
|
|
63
|
-
var method = target[methodName];
|
|
52
|
+
const actionMethod = function actionMethod2(...args) {
|
|
53
|
+
const { target } = cache;
|
|
54
|
+
const method = target[methodName];
|
|
64
55
|
if (typeof method !== "function") {
|
|
65
56
|
throw new Error("Can not change methods in runtime.");
|
|
66
57
|
}
|
|
67
|
-
return method
|
|
58
|
+
return method(...args);
|
|
68
59
|
};
|
|
69
60
|
cacheMethods[methodName] = actionMethod;
|
|
70
61
|
return actionMethod;
|
|
71
62
|
}
|
|
72
|
-
|
|
63
|
+
const cacheProperties = (cache, onGet) => {
|
|
73
64
|
return function createCachePropertiesProxy() {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
65
|
+
const instance = cache.target;
|
|
66
|
+
const properties = Object.getOwnPropertyNames(instance);
|
|
67
|
+
const handleGetter = function handleGetter2(key, value) {
|
|
77
68
|
if (!onGet) {
|
|
78
69
|
return;
|
|
79
70
|
}
|
|
80
71
|
onGet(key, value);
|
|
81
72
|
};
|
|
82
73
|
return createProxy(instance, {
|
|
83
|
-
get
|
|
84
|
-
|
|
74
|
+
get(target, p) {
|
|
75
|
+
const value = target[p];
|
|
85
76
|
if (typeof value === "function" && properties.indexOf(p) >= 0) {
|
|
86
|
-
|
|
77
|
+
const actionMethod = wrapToActionMethod(cache, p);
|
|
87
78
|
Object.assign(actionMethod, value);
|
|
88
79
|
handleGetter(p, actionMethod);
|
|
89
80
|
return actionMethod;
|
|
90
81
|
}
|
|
91
82
|
return wrapToField(cache, p, value, handleGetter);
|
|
92
83
|
},
|
|
93
|
-
set
|
|
84
|
+
set() {
|
|
94
85
|
return false;
|
|
95
86
|
}
|
|
96
87
|
});
|
|
97
88
|
};
|
|
98
89
|
};
|
|
99
90
|
function createSelector(store, opts) {
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
const { equality } = opts != null ? opts : {};
|
|
92
|
+
const selectStore = {
|
|
102
93
|
selectedInstance: store.getInstance()
|
|
103
94
|
};
|
|
104
|
-
|
|
95
|
+
const cache = {
|
|
105
96
|
equality,
|
|
106
|
-
setSelect
|
|
97
|
+
setSelect(selector) {
|
|
107
98
|
cache.selector = selector;
|
|
108
99
|
if (!selector) {
|
|
109
100
|
return;
|
|
110
101
|
}
|
|
111
|
-
|
|
112
|
-
|
|
102
|
+
const currentSelectedInstance = selectStore.selectedInstance;
|
|
103
|
+
const nextSelectedInstance = selector(store.getInstance);
|
|
113
104
|
if (currentSelectedInstance === nextSelectedInstance || equality && equality(currentSelectedInstance, nextSelectedInstance)) {
|
|
114
105
|
return;
|
|
115
106
|
}
|
|
116
107
|
selectStore.selectedInstance = nextSelectedInstance;
|
|
117
108
|
}
|
|
118
109
|
};
|
|
119
|
-
|
|
110
|
+
const propertiesCache = {
|
|
120
111
|
target: store.getInstance(),
|
|
121
112
|
cacheFields: {},
|
|
122
113
|
cacheMethods: {}
|
|
123
114
|
};
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
const generateSelectedInstance = function generateSelectedInstance2(getInstance) {
|
|
116
|
+
const { key: storeKey } = store;
|
|
126
117
|
if (cache.selector) {
|
|
127
118
|
return cache.selector(getInstance);
|
|
128
119
|
}
|
|
129
|
-
if (!(storeKey
|
|
120
|
+
if (!(storeKey == null ? void 0 : storeKey.selector)) {
|
|
130
121
|
return getInstance();
|
|
131
122
|
}
|
|
132
|
-
|
|
133
|
-
if (result == null ||
|
|
134
|
-
throw new Error(
|
|
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
|
+
);
|
|
135
128
|
}
|
|
136
129
|
propertiesCache.target = result;
|
|
137
130
|
return cacheProperties(propertiesCache)();
|
|
138
131
|
};
|
|
139
132
|
selectStore.selectedInstance = generateSelectedInstance(store.getInstance);
|
|
140
|
-
|
|
141
|
-
return
|
|
142
|
-
|
|
143
|
-
|
|
133
|
+
const enhance = (dispatcher) => {
|
|
134
|
+
return (action) => {
|
|
135
|
+
const currentSelectedInstance = selectStore.selectedInstance;
|
|
136
|
+
const nextSelectedInstance = generateSelectedInstance(store.getInstance);
|
|
144
137
|
if (currentSelectedInstance === nextSelectedInstance || cache.equality && cache.equality(currentSelectedInstance, nextSelectedInstance)) {
|
|
145
138
|
return;
|
|
146
139
|
}
|
|
@@ -157,7 +150,7 @@ function createSelector(store, opts) {
|
|
|
157
150
|
}
|
|
158
151
|
return {
|
|
159
152
|
key: store.key,
|
|
160
|
-
subscribe
|
|
153
|
+
subscribe(dispatcher) {
|
|
161
154
|
return store.subscribe(enhance(dispatcher));
|
|
162
155
|
},
|
|
163
156
|
select
|
|
@@ -1,61 +1,55 @@
|
|
|
1
1
|
import { cacheIdentify, extractInstance } from "../instance";
|
|
2
2
|
import { shallowEqual } from "../../tools";
|
|
3
3
|
function createSignal(store) {
|
|
4
|
-
|
|
4
|
+
const signalStore = {
|
|
5
5
|
collection: null,
|
|
6
6
|
started: false,
|
|
7
7
|
enabled: false
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
return
|
|
9
|
+
const enhance = (dispatcher) => {
|
|
10
|
+
return (action) => {
|
|
11
11
|
if (!signalStore.enabled) {
|
|
12
|
-
dispatcher
|
|
12
|
+
dispatcher == null ? void 0 : dispatcher(action);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
const { collection } = signalStore;
|
|
16
16
|
if (collection == null) {
|
|
17
|
-
dispatcher
|
|
17
|
+
dispatcher == null ? void 0 : dispatcher(action);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const current = extractInstance(store.updater);
|
|
21
|
+
const keys = Object.keys(collection);
|
|
22
|
+
const currentCollectionEntries = keys.map((key) => {
|
|
23
|
+
const field = current[key];
|
|
24
24
|
if (cacheIdentify.field(field)) {
|
|
25
|
-
return [
|
|
26
|
-
key,
|
|
27
|
-
field.get()
|
|
28
|
-
];
|
|
25
|
+
return [key, field.get()];
|
|
29
26
|
}
|
|
30
|
-
return [
|
|
31
|
-
key,
|
|
32
|
-
field
|
|
33
|
-
];
|
|
27
|
+
return [key, field];
|
|
34
28
|
});
|
|
35
|
-
|
|
29
|
+
const currentCollection = Object.fromEntries(currentCollectionEntries);
|
|
36
30
|
if (!shallowEqual(collection, currentCollection)) {
|
|
37
|
-
dispatcher
|
|
31
|
+
dispatcher == null ? void 0 : dispatcher(action);
|
|
38
32
|
}
|
|
39
33
|
};
|
|
40
34
|
};
|
|
41
|
-
|
|
35
|
+
const { key: storeKey } = store;
|
|
42
36
|
return {
|
|
43
37
|
key: storeKey,
|
|
44
|
-
subscribe
|
|
38
|
+
subscribe(dispatcher) {
|
|
45
39
|
return store.subscribe(enhance(dispatcher));
|
|
46
40
|
},
|
|
47
|
-
getSignal
|
|
48
|
-
|
|
41
|
+
getSignal() {
|
|
42
|
+
const collectUsedFields = function collectUsedFields2(key, val) {
|
|
49
43
|
if (!signalStore.started) {
|
|
50
44
|
return;
|
|
51
45
|
}
|
|
52
46
|
signalStore.collection = signalStore.collection || {};
|
|
53
47
|
signalStore.collection[key] = val;
|
|
54
48
|
};
|
|
55
|
-
|
|
49
|
+
const getInstance = function getInstance2() {
|
|
56
50
|
return extractInstance(store.updater, collectUsedFields);
|
|
57
51
|
};
|
|
58
|
-
|
|
52
|
+
const signal = function signal2() {
|
|
59
53
|
return getInstance();
|
|
60
54
|
};
|
|
61
55
|
signal.startStatistics = function startStatistics() {
|
|
@@ -67,9 +61,7 @@ function createSignal(store) {
|
|
|
67
61
|
signal.subscribe = function subscribe(dispatchCallback) {
|
|
68
62
|
return store.subscribe(dispatchCallback);
|
|
69
63
|
};
|
|
70
|
-
signal.
|
|
71
|
-
return store.payload(callback);
|
|
72
|
-
};
|
|
64
|
+
signal.store = store;
|
|
73
65
|
signalStore.enabled = true;
|
|
74
66
|
signalStore.started = true;
|
|
75
67
|
return signal;
|