@domql/state 3.2.3 → 3.2.8
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/create.js +3 -3
- package/dist/cjs/create.js +3 -4
- package/dist/cjs/methods.js +11 -13
- package/dist/cjs/updateState.js +5 -6
- package/dist/esm/create.js +3 -3
- package/dist/esm/methods.js +28 -48
- package/dist/esm/updateState.js +14 -30
- package/dist/iife/index.js +1051 -0
- package/methods.js +10 -11
- package/package.json +26 -14
- package/updateState.js +2 -2
- package/dist/cjs/package.json +0 -4
package/create.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { triggerEventOn } from '@domql/event'
|
|
4
3
|
import {
|
|
5
4
|
applyDependentState,
|
|
6
5
|
checkForStateTypes,
|
|
7
6
|
checkIfInherits,
|
|
8
7
|
createInheritedState,
|
|
9
|
-
isUndefined
|
|
8
|
+
isUndefined,
|
|
9
|
+
triggerEventOn
|
|
10
10
|
} from '@domql/utils'
|
|
11
11
|
|
|
12
|
-
import { applyStateMethods } from './methods'
|
|
12
|
+
import { applyStateMethods } from './methods.js'
|
|
13
13
|
|
|
14
14
|
export const createState = function (element, parent, options) {
|
|
15
15
|
element.state = applyInitialState(element, parent, options)
|
package/dist/cjs/create.js
CHANGED
|
@@ -22,9 +22,8 @@ __export(create_exports, {
|
|
|
22
22
|
createState: () => createState
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(create_exports);
|
|
25
|
-
var import_event = require("@domql/event");
|
|
26
25
|
var import_utils = require("@domql/utils");
|
|
27
|
-
var import_methods = require("./methods");
|
|
26
|
+
var import_methods = require("./methods.js");
|
|
28
27
|
const createState = function(element, parent, options) {
|
|
29
28
|
element.state = applyInitialState(element, parent, options);
|
|
30
29
|
return element.state;
|
|
@@ -33,7 +32,7 @@ const applyInitialState = function(element, parent, options) {
|
|
|
33
32
|
const objectizeState = (0, import_utils.checkForStateTypes)(element);
|
|
34
33
|
if (objectizeState === false) return parent.state || {};
|
|
35
34
|
else element.state = objectizeState;
|
|
36
|
-
const whatInitReturns = (0,
|
|
35
|
+
const whatInitReturns = (0, import_utils.triggerEventOn)("stateInit", element, options);
|
|
37
36
|
if (whatInitReturns === false) return element.state;
|
|
38
37
|
if ((0, import_utils.checkIfInherits)(element)) {
|
|
39
38
|
const inheritedState = (0, import_utils.createInheritedState)(element, parent);
|
|
@@ -45,6 +44,6 @@ const applyInitialState = function(element, parent, options) {
|
|
|
45
44
|
);
|
|
46
45
|
if (dependentState) element.state = dependentState;
|
|
47
46
|
(0, import_methods.applyStateMethods)(element);
|
|
48
|
-
(0,
|
|
47
|
+
(0, import_utils.triggerEventOn)("stateCreated", element);
|
|
49
48
|
return element.state;
|
|
50
49
|
};
|
package/dist/cjs/methods.js
CHANGED
|
@@ -52,19 +52,19 @@ const parse = function() {
|
|
|
52
52
|
if ((0, import_utils.isObject)(state)) {
|
|
53
53
|
const obj = {};
|
|
54
54
|
for (const param in state) {
|
|
55
|
-
if (!import_utils.STATE_METHODS.
|
|
55
|
+
if (!import_utils.STATE_METHODS.has(param)) {
|
|
56
56
|
obj[param] = state[param];
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
return obj;
|
|
60
60
|
} else if ((0, import_utils.isArray)(state)) {
|
|
61
|
-
return state.filter((item) => !import_utils.STATE_METHODS.
|
|
61
|
+
return state.filter((item) => !import_utils.STATE_METHODS.has(item));
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
const clean = function(options = {}) {
|
|
65
65
|
const state = this;
|
|
66
66
|
for (const param in state) {
|
|
67
|
-
if (!import_utils.STATE_METHODS.
|
|
67
|
+
if (!import_utils.STATE_METHODS.has(param) && Object.prototype.hasOwnProperty.call(state, param)) {
|
|
68
68
|
delete state[param];
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -137,7 +137,7 @@ const toggle = function(key, options = {}) {
|
|
|
137
137
|
const remove = function(key, options = {}) {
|
|
138
138
|
const state = this;
|
|
139
139
|
if ((0, import_utils.isArray)(state)) (0, import_utils.removeFromArray)(state, key);
|
|
140
|
-
if ((0, import_utils.isObject)(state)) (0, import_utils.removeFromObject)(state, key);
|
|
140
|
+
else if ((0, import_utils.isObject)(state)) (0, import_utils.removeFromObject)(state, key);
|
|
141
141
|
if (options.applyReset) {
|
|
142
142
|
return state.set(state.parse(), { replace: true, ...options });
|
|
143
143
|
}
|
|
@@ -159,8 +159,7 @@ const setByPath = function(path, val, options = {}) {
|
|
|
159
159
|
};
|
|
160
160
|
const setPathCollection = function(changes, options = {}) {
|
|
161
161
|
const state = this;
|
|
162
|
-
const update = changes.reduce((
|
|
163
|
-
const acc = promise;
|
|
162
|
+
const update = changes.reduce((acc, change) => {
|
|
164
163
|
if (change[0] === "update") {
|
|
165
164
|
const result = setByPath.call(state, change[1], change[2], {
|
|
166
165
|
preventStateUpdate: true
|
|
@@ -173,7 +172,7 @@ const setPathCollection = function(changes, options = {}) {
|
|
|
173
172
|
});
|
|
174
173
|
}
|
|
175
174
|
return acc;
|
|
176
|
-
},
|
|
175
|
+
}, {});
|
|
177
176
|
return state.update(update, options);
|
|
178
177
|
};
|
|
179
178
|
const removeByPath = function(path, options = {}) {
|
|
@@ -184,9 +183,9 @@ const removeByPath = function(path, options = {}) {
|
|
|
184
183
|
};
|
|
185
184
|
const removePathCollection = function(changes, options = {}) {
|
|
186
185
|
const state = this;
|
|
187
|
-
changes.
|
|
188
|
-
removeByPath(
|
|
189
|
-
}
|
|
186
|
+
for (let i = 0; i < changes.length; i++) {
|
|
187
|
+
removeByPath(changes[i], { preventUpdate: true });
|
|
188
|
+
}
|
|
190
189
|
return state.update({}, options);
|
|
191
190
|
};
|
|
192
191
|
const getByPath = function(path, options = {}) {
|
|
@@ -243,7 +242,6 @@ const values = function(obj, options = {}) {
|
|
|
243
242
|
return Object.values(state);
|
|
244
243
|
};
|
|
245
244
|
const applyStateMethods = (element) => {
|
|
246
|
-
var _a;
|
|
247
245
|
const state = element.state;
|
|
248
246
|
const ref = element.__ref;
|
|
249
247
|
const proto = {
|
|
@@ -265,7 +263,7 @@ const applyStateMethods = (element) => {
|
|
|
265
263
|
replace: replace.bind(state),
|
|
266
264
|
quietReplace: quietReplace.bind(state),
|
|
267
265
|
reset: reset.bind(state),
|
|
268
|
-
parent:
|
|
266
|
+
parent: element.parent?.state || state,
|
|
269
267
|
setByPath: setByPath.bind(state),
|
|
270
268
|
setPathCollection: setPathCollection.bind(state),
|
|
271
269
|
removeByPath: removeByPath.bind(state),
|
|
@@ -275,7 +273,7 @@ const applyStateMethods = (element) => {
|
|
|
275
273
|
values: values.bind(state),
|
|
276
274
|
__element: element,
|
|
277
275
|
__children: {},
|
|
278
|
-
root:
|
|
276
|
+
root: ref?.root ? ref.root.state : state
|
|
279
277
|
};
|
|
280
278
|
if ((0, import_utils.isArray)(state)) {
|
|
281
279
|
(0, import_utils.addProtoToArray)(state, proto);
|
package/dist/cjs/updateState.js
CHANGED
|
@@ -23,7 +23,6 @@ __export(updateState_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(updateState_exports);
|
|
25
25
|
var import_report = require("@domql/report");
|
|
26
|
-
var import_event = require("@domql/event");
|
|
27
26
|
var import_utils = require("@domql/utils");
|
|
28
27
|
const STATE_UPDATE_OPTIONS = {
|
|
29
28
|
overwrite: true,
|
|
@@ -42,7 +41,7 @@ const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
|
42
41
|
options.preventInheritAtCurrentState = state;
|
|
43
42
|
} else if (options.preventInheritAtCurrentState) return;
|
|
44
43
|
if (!options.preventBeforeStateUpdateListener) {
|
|
45
|
-
const beforeStateUpdateReturns = (0,
|
|
44
|
+
const beforeStateUpdateReturns = (0, import_utils.triggerEventOnUpdate)(
|
|
46
45
|
"beforeStateUpdate",
|
|
47
46
|
obj,
|
|
48
47
|
element,
|
|
@@ -56,15 +55,15 @@ const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
|
56
55
|
updateDependentState(state, obj, options);
|
|
57
56
|
applyElementUpdate(state, obj, options);
|
|
58
57
|
if (!options.preventStateUpdateListener) {
|
|
59
|
-
(0,
|
|
58
|
+
(0, import_utils.triggerEventOnUpdate)("stateUpdate", obj, element, options);
|
|
60
59
|
}
|
|
61
60
|
return state;
|
|
62
61
|
};
|
|
63
62
|
const hoistStateUpdate = (state, obj, options) => {
|
|
64
63
|
const element = state.__element;
|
|
65
64
|
const { parent, __ref: ref } = element;
|
|
66
|
-
const stateKey = ref
|
|
67
|
-
const stateType = ref
|
|
65
|
+
const stateKey = ref?.__state;
|
|
66
|
+
const stateType = ref?.__stateType;
|
|
68
67
|
if (!stateKey) return;
|
|
69
68
|
const asksForInherit = (0, import_utils.checkIfInherits)(element);
|
|
70
69
|
const inheritedState = (0, import_utils.findInheritedState)(element, parent, {
|
|
@@ -89,7 +88,7 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
89
88
|
});
|
|
90
89
|
const hasNotUpdated = options.preventUpdate !== true || !options.preventHoistElementUpdate;
|
|
91
90
|
if (!options.preventStateUpdateListener && hasNotUpdated) {
|
|
92
|
-
(0,
|
|
91
|
+
(0, import_utils.triggerEventOnUpdate)("stateUpdate", obj, element, options);
|
|
93
92
|
}
|
|
94
93
|
return true;
|
|
95
94
|
};
|
package/dist/esm/create.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { triggerEventOn } from "@domql/event";
|
|
2
1
|
import {
|
|
3
2
|
applyDependentState,
|
|
4
3
|
checkForStateTypes,
|
|
5
4
|
checkIfInherits,
|
|
6
5
|
createInheritedState,
|
|
7
|
-
isUndefined
|
|
6
|
+
isUndefined,
|
|
7
|
+
triggerEventOn
|
|
8
8
|
} from "@domql/utils";
|
|
9
|
-
import { applyStateMethods } from "./methods";
|
|
9
|
+
import { applyStateMethods } from "./methods.js";
|
|
10
10
|
const createState = function(element, parent, options) {
|
|
11
11
|
element.state = applyInitialState(element, parent, options);
|
|
12
12
|
return element.state;
|
package/dist/esm/methods.js
CHANGED
|
@@ -1,22 +1,3 @@
|
|
|
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));
|
|
20
1
|
import {
|
|
21
2
|
isArray,
|
|
22
3
|
deepClone,
|
|
@@ -40,24 +21,24 @@ const parse = function() {
|
|
|
40
21
|
if (isObject(state)) {
|
|
41
22
|
const obj = {};
|
|
42
23
|
for (const param in state) {
|
|
43
|
-
if (!STATE_METHODS.
|
|
24
|
+
if (!STATE_METHODS.has(param)) {
|
|
44
25
|
obj[param] = state[param];
|
|
45
26
|
}
|
|
46
27
|
}
|
|
47
28
|
return obj;
|
|
48
29
|
} else if (isArray(state)) {
|
|
49
|
-
return state.filter((item) => !STATE_METHODS.
|
|
30
|
+
return state.filter((item) => !STATE_METHODS.has(item));
|
|
50
31
|
}
|
|
51
32
|
};
|
|
52
33
|
const clean = function(options = {}) {
|
|
53
34
|
const state = this;
|
|
54
35
|
for (const param in state) {
|
|
55
|
-
if (!STATE_METHODS.
|
|
36
|
+
if (!STATE_METHODS.has(param) && Object.prototype.hasOwnProperty.call(state, param)) {
|
|
56
37
|
delete state[param];
|
|
57
38
|
}
|
|
58
39
|
}
|
|
59
40
|
if (!options.preventStateUpdate) {
|
|
60
|
-
state.update(state,
|
|
41
|
+
state.update(state, { replace: true, ...options });
|
|
61
42
|
}
|
|
62
43
|
return state;
|
|
63
44
|
};
|
|
@@ -66,7 +47,7 @@ const destroy = function(options = {}) {
|
|
|
66
47
|
const element = state.__element;
|
|
67
48
|
const stateKey = element.__ref.__state;
|
|
68
49
|
if (isString(stateKey)) {
|
|
69
|
-
element.parent.state.remove(stateKey,
|
|
50
|
+
element.parent.state.remove(stateKey, { isHoisted: true, ...options });
|
|
70
51
|
return element.state;
|
|
71
52
|
}
|
|
72
53
|
delete element.state;
|
|
@@ -94,25 +75,25 @@ const destroy = function(options = {}) {
|
|
|
94
75
|
}
|
|
95
76
|
}
|
|
96
77
|
}
|
|
97
|
-
element.state.update({},
|
|
78
|
+
element.state.update({}, { isHoisted: true, ...options });
|
|
98
79
|
return element.state;
|
|
99
80
|
};
|
|
100
81
|
const parentUpdate = function(obj, options = {}) {
|
|
101
82
|
const state = this;
|
|
102
83
|
if (!state || !state.parent) return;
|
|
103
|
-
return state.parent.update(obj,
|
|
84
|
+
return state.parent.update(obj, { isHoisted: true, ...options });
|
|
104
85
|
};
|
|
105
86
|
const rootUpdate = function(obj, options = {}) {
|
|
106
87
|
const state = this;
|
|
107
88
|
if (!state) return;
|
|
108
89
|
const rootState = state.__element.__ref.root.state;
|
|
109
|
-
return rootState.update(obj,
|
|
90
|
+
return rootState.update(obj, { isHoisted: false, ...options });
|
|
110
91
|
};
|
|
111
92
|
const add = function(value, options = {}) {
|
|
112
93
|
const state = this;
|
|
113
94
|
if (isArray(state)) {
|
|
114
95
|
state.push(value);
|
|
115
|
-
state.update(state.parse(),
|
|
96
|
+
state.update(state.parse(), { overwrite: true, ...options });
|
|
116
97
|
} else if (isObject(state)) {
|
|
117
98
|
const key = Object.keys(state).length;
|
|
118
99
|
state.update({ [key]: value }, options);
|
|
@@ -125,17 +106,17 @@ const toggle = function(key, options = {}) {
|
|
|
125
106
|
const remove = function(key, options = {}) {
|
|
126
107
|
const state = this;
|
|
127
108
|
if (isArray(state)) removeFromArray(state, key);
|
|
128
|
-
if (isObject(state)) removeFromObject(state, key);
|
|
109
|
+
else if (isObject(state)) removeFromObject(state, key);
|
|
129
110
|
if (options.applyReset) {
|
|
130
|
-
return state.set(state.parse(),
|
|
111
|
+
return state.set(state.parse(), { replace: true, ...options });
|
|
131
112
|
}
|
|
132
113
|
return state.update({}, options);
|
|
133
114
|
};
|
|
134
115
|
const set = function(val, options = {}) {
|
|
135
116
|
const state = this;
|
|
136
117
|
const value = deepClone(val);
|
|
137
|
-
const cleanState = state.clean(
|
|
138
|
-
return cleanState.update(value,
|
|
118
|
+
const cleanState = state.clean({ preventStateUpdate: true, ...options });
|
|
119
|
+
return cleanState.update(value, { replace: true, ...options });
|
|
139
120
|
};
|
|
140
121
|
const setByPath = function(path, val, options = {}) {
|
|
141
122
|
const state = this;
|
|
@@ -147,20 +128,20 @@ const setByPath = function(path, val, options = {}) {
|
|
|
147
128
|
};
|
|
148
129
|
const setPathCollection = function(changes, options = {}) {
|
|
149
130
|
const state = this;
|
|
150
|
-
const update = changes.reduce((
|
|
151
|
-
const acc = promise;
|
|
131
|
+
const update = changes.reduce((acc, change) => {
|
|
152
132
|
if (change[0] === "update") {
|
|
153
133
|
const result = setByPath.call(state, change[1], change[2], {
|
|
154
134
|
preventStateUpdate: true
|
|
155
135
|
});
|
|
156
136
|
return overwriteDeep(acc, result);
|
|
157
137
|
} else if (change[0] === "delete") {
|
|
158
|
-
removeByPath.call(state, change[1],
|
|
138
|
+
removeByPath.call(state, change[1], {
|
|
139
|
+
...options,
|
|
159
140
|
preventUpdate: true
|
|
160
|
-
})
|
|
141
|
+
});
|
|
161
142
|
}
|
|
162
143
|
return acc;
|
|
163
|
-
},
|
|
144
|
+
}, {});
|
|
164
145
|
return state.update(update, options);
|
|
165
146
|
};
|
|
166
147
|
const removeByPath = function(path, options = {}) {
|
|
@@ -171,9 +152,9 @@ const removeByPath = function(path, options = {}) {
|
|
|
171
152
|
};
|
|
172
153
|
const removePathCollection = function(changes, options = {}) {
|
|
173
154
|
const state = this;
|
|
174
|
-
changes.
|
|
175
|
-
removeByPath(
|
|
176
|
-
}
|
|
155
|
+
for (let i = 0; i < changes.length; i++) {
|
|
156
|
+
removeByPath(changes[i], { preventUpdate: true });
|
|
157
|
+
}
|
|
177
158
|
return state.update({}, options);
|
|
178
159
|
};
|
|
179
160
|
const getByPath = function(path, options = {}) {
|
|
@@ -183,13 +164,13 @@ const getByPath = function(path, options = {}) {
|
|
|
183
164
|
const reset = function(options = {}) {
|
|
184
165
|
const state = this;
|
|
185
166
|
const value = deepClone(state.parse());
|
|
186
|
-
return state.set(value,
|
|
167
|
+
return state.set(value, { replace: true, ...options });
|
|
187
168
|
};
|
|
188
169
|
const apply = function(func, options = {}) {
|
|
189
170
|
const state = this;
|
|
190
171
|
if (isFunction(func)) {
|
|
191
172
|
const value = func(state);
|
|
192
|
-
return state.update(value,
|
|
173
|
+
return state.update(value, { replace: true, ...options });
|
|
193
174
|
}
|
|
194
175
|
};
|
|
195
176
|
const applyReplace = function(func, options = {}) {
|
|
@@ -203,12 +184,12 @@ const applyFunction = function(func, options = {}) {
|
|
|
203
184
|
const state = this;
|
|
204
185
|
if (isFunction(func)) {
|
|
205
186
|
func(state);
|
|
206
|
-
return state.update(state.parse(),
|
|
187
|
+
return state.update(state.parse(), { replace: true, ...options });
|
|
207
188
|
}
|
|
208
189
|
};
|
|
209
190
|
const quietUpdate = function(obj, options = {}) {
|
|
210
191
|
const state = this;
|
|
211
|
-
return state.update(obj,
|
|
192
|
+
return state.update(obj, { preventUpdate: true, ...options });
|
|
212
193
|
};
|
|
213
194
|
const replace = function(obj, options = {}) {
|
|
214
195
|
const state = this;
|
|
@@ -219,7 +200,7 @@ const replace = function(obj, options = {}) {
|
|
|
219
200
|
};
|
|
220
201
|
const quietReplace = function(obj, options = {}) {
|
|
221
202
|
const state = this;
|
|
222
|
-
return state.replace(obj,
|
|
203
|
+
return state.replace(obj, { preventUpdate: true, ...options });
|
|
223
204
|
};
|
|
224
205
|
const keys = function(obj, options = {}) {
|
|
225
206
|
const state = this;
|
|
@@ -230,7 +211,6 @@ const values = function(obj, options = {}) {
|
|
|
230
211
|
return Object.values(state);
|
|
231
212
|
};
|
|
232
213
|
const applyStateMethods = (element) => {
|
|
233
|
-
var _a;
|
|
234
214
|
const state = element.state;
|
|
235
215
|
const ref = element.__ref;
|
|
236
216
|
const proto = {
|
|
@@ -252,7 +232,7 @@ const applyStateMethods = (element) => {
|
|
|
252
232
|
replace: replace.bind(state),
|
|
253
233
|
quietReplace: quietReplace.bind(state),
|
|
254
234
|
reset: reset.bind(state),
|
|
255
|
-
parent:
|
|
235
|
+
parent: element.parent?.state || state,
|
|
256
236
|
setByPath: setByPath.bind(state),
|
|
257
237
|
setPathCollection: setPathCollection.bind(state),
|
|
258
238
|
removeByPath: removeByPath.bind(state),
|
|
@@ -262,7 +242,7 @@ const applyStateMethods = (element) => {
|
|
|
262
242
|
values: values.bind(state),
|
|
263
243
|
__element: element,
|
|
264
244
|
__children: {},
|
|
265
|
-
root:
|
|
245
|
+
root: ref?.root ? ref.root.state : state
|
|
266
246
|
};
|
|
267
247
|
if (isArray(state)) {
|
|
268
248
|
addProtoToArray(state, proto);
|
package/dist/esm/updateState.js
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
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));
|
|
20
1
|
import { report } from "@domql/report";
|
|
21
|
-
import { triggerEventOnUpdate } from "@domql/event";
|
|
22
2
|
import {
|
|
23
3
|
checkIfInherits,
|
|
24
4
|
createNestedObjectByKeyPath,
|
|
@@ -27,7 +7,8 @@ import {
|
|
|
27
7
|
getRootStateInKey,
|
|
28
8
|
merge,
|
|
29
9
|
overwriteDeep,
|
|
30
|
-
overwriteState
|
|
10
|
+
overwriteState,
|
|
11
|
+
triggerEventOnUpdate
|
|
31
12
|
} from "@domql/utils";
|
|
32
13
|
const STATE_UPDATE_OPTIONS = {
|
|
33
14
|
overwrite: true,
|
|
@@ -67,8 +48,8 @@ const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
|
|
|
67
48
|
const hoistStateUpdate = (state, obj, options) => {
|
|
68
49
|
const element = state.__element;
|
|
69
50
|
const { parent, __ref: ref } = element;
|
|
70
|
-
const stateKey = ref
|
|
71
|
-
const stateType = ref
|
|
51
|
+
const stateKey = ref?.__state;
|
|
52
|
+
const stateType = ref?.__stateType;
|
|
72
53
|
if (!stateKey) return;
|
|
73
54
|
const asksForInherit = checkIfInherits(element);
|
|
74
55
|
const inheritedState = findInheritedState(element, parent, {
|
|
@@ -84,12 +65,13 @@ const hoistStateUpdate = (state, obj, options) => {
|
|
|
84
65
|
const changesValue = createNestedObjectByKeyPath(stateKey, passedValue);
|
|
85
66
|
const targetParent = findRootState || findGrandParentState || parent.state;
|
|
86
67
|
if (options.replace) overwriteDeep(targetParent, changesValue || value);
|
|
87
|
-
targetParent.update(changesValue,
|
|
68
|
+
targetParent.update(changesValue, {
|
|
88
69
|
execStateFunction: false,
|
|
89
70
|
isHoisted: true,
|
|
90
71
|
preventUpdate: options.preventHoistElementUpdate,
|
|
91
|
-
overwrite: !options.replace
|
|
92
|
-
|
|
72
|
+
overwrite: !options.replace,
|
|
73
|
+
...options
|
|
74
|
+
});
|
|
93
75
|
const hasNotUpdated = options.preventUpdate !== true || !options.preventHoistElementUpdate;
|
|
94
76
|
if (!options.preventStateUpdateListener && hasNotUpdated) {
|
|
95
77
|
triggerEventOnUpdate("stateUpdate", obj, element, options);
|
|
@@ -109,18 +91,20 @@ const applyElementUpdate = (state, obj, options) => {
|
|
|
109
91
|
if (options.preventUpdate !== true) {
|
|
110
92
|
element.update(
|
|
111
93
|
{},
|
|
112
|
-
|
|
94
|
+
{
|
|
95
|
+
...options,
|
|
113
96
|
updateByState: true
|
|
114
|
-
}
|
|
97
|
+
}
|
|
115
98
|
);
|
|
116
99
|
} else if (options.preventUpdate === "recursive") {
|
|
117
100
|
element.update(
|
|
118
101
|
{},
|
|
119
|
-
|
|
102
|
+
{
|
|
103
|
+
...options,
|
|
120
104
|
isHoisted: false,
|
|
121
105
|
updateByState: true,
|
|
122
106
|
preventUpdate: true
|
|
123
|
-
}
|
|
107
|
+
}
|
|
124
108
|
);
|
|
125
109
|
}
|
|
126
110
|
};
|