@domql/state 2.31.26 → 2.31.27
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 +1 -1
- package/dist/cjs/create.js +1 -1
- package/dist/cjs/methods.js +50 -46
- package/dist/esm/create.js +1 -1
- package/dist/esm/methods.js +50 -46
- package/methods.js +49 -47
- package/package.json +5 -5
package/create.js
CHANGED
|
@@ -66,7 +66,7 @@ export const applyInitialState = async function (element, parent, options) {
|
|
|
66
66
|
applyMethods(element)
|
|
67
67
|
|
|
68
68
|
// trigger `on.stateCreated`
|
|
69
|
-
await triggerEventOn('stateCreated', element)
|
|
69
|
+
await triggerEventOn('stateCreated', element, options)
|
|
70
70
|
|
|
71
71
|
return element.state
|
|
72
72
|
}
|
package/dist/cjs/create.js
CHANGED
|
@@ -48,7 +48,7 @@ const applyInitialState = async function(element, parent, options) {
|
|
|
48
48
|
);
|
|
49
49
|
if (dependentState) element.state = dependentState;
|
|
50
50
|
applyMethods(element);
|
|
51
|
-
await (0, import_event.triggerEventOn)("stateCreated", element);
|
|
51
|
+
await (0, import_event.triggerEventOn)("stateCreated", element, options);
|
|
52
52
|
return element.state;
|
|
53
53
|
};
|
|
54
54
|
const applyDependentState = (element, state) => {
|
package/dist/cjs/methods.js
CHANGED
|
@@ -55,11 +55,10 @@ const parse = function() {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
return obj;
|
|
58
|
-
} else
|
|
59
|
-
return state.filter((item) => !import_ignore.IGNORE_STATE_PARAMS.includes(item));
|
|
58
|
+
} else {
|
|
60
59
|
}
|
|
61
60
|
};
|
|
62
|
-
const clean = function(options = {}) {
|
|
61
|
+
const clean = async function(options = {}) {
|
|
63
62
|
const state = this;
|
|
64
63
|
for (const param in state) {
|
|
65
64
|
if (!import_ignore.IGNORE_STATE_PARAMS.includes(param) && Object.hasOwnProperty.call(state, param)) {
|
|
@@ -67,16 +66,16 @@ const clean = function(options = {}) {
|
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
if (!options.preventStateUpdate) {
|
|
70
|
-
state.update(state, { replace: true, ...options });
|
|
69
|
+
await state.update(state, { replace: true, ...options });
|
|
71
70
|
}
|
|
72
71
|
return state;
|
|
73
72
|
};
|
|
74
|
-
const destroy = function(options = {}) {
|
|
73
|
+
const destroy = async function(options = {}) {
|
|
75
74
|
const state = this;
|
|
76
75
|
const element = state.__element;
|
|
77
76
|
const stateKey = element.__ref.__state;
|
|
78
77
|
if ((0, import_utils.isString)(stateKey)) {
|
|
79
|
-
element.parent.state.remove(stateKey, { isHoisted: true, ...options });
|
|
78
|
+
await element.parent.state.remove(stateKey, { isHoisted: true, ...options });
|
|
80
79
|
return element.state;
|
|
81
80
|
}
|
|
82
81
|
delete element.state;
|
|
@@ -104,66 +103,69 @@ const destroy = function(options = {}) {
|
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
|
-
element.state.update({}, { isHoisted: true, ...options });
|
|
106
|
+
await element.state.update({}, { isHoisted: true, ...options });
|
|
108
107
|
return element.state;
|
|
109
108
|
};
|
|
110
|
-
const parentUpdate = function(obj, options = {}) {
|
|
109
|
+
const parentUpdate = async function(obj, options = {}) {
|
|
111
110
|
const state = this;
|
|
112
111
|
if (!state || !state.parent) return;
|
|
113
|
-
return state.parent.update(obj, { isHoisted: true, ...options });
|
|
112
|
+
return await state.parent.update(obj, { isHoisted: true, ...options });
|
|
114
113
|
};
|
|
115
|
-
const rootUpdate = function(obj, options = {}) {
|
|
114
|
+
const rootUpdate = async function(obj, options = {}) {
|
|
116
115
|
const state = this;
|
|
117
116
|
if (!state) return;
|
|
118
117
|
const rootState = state.__element.__ref.root.state;
|
|
119
|
-
return rootState.update(obj, { isHoisted: false, ...options });
|
|
118
|
+
return await rootState.update(obj, { isHoisted: false, ...options });
|
|
120
119
|
};
|
|
121
|
-
const add = function(value, options = {}) {
|
|
120
|
+
const add = async function(value, options = {}) {
|
|
122
121
|
const state = this;
|
|
123
122
|
if ((0, import_utils.isArray)(state)) {
|
|
124
|
-
state.push(value);
|
|
125
|
-
state.update(state.parse(), { overwrite: true, ...options });
|
|
123
|
+
await state.push(value);
|
|
124
|
+
return await state.update(state.parse(), { overwrite: true, ...options });
|
|
126
125
|
} else if ((0, import_utils.isObject)(state)) {
|
|
127
126
|
const key = Object.keys(state).length;
|
|
128
|
-
state.update({ [key]: value }, options);
|
|
127
|
+
return await state.update({ [key]: value }, options);
|
|
129
128
|
}
|
|
130
129
|
};
|
|
131
|
-
const toggle = function(key, options = {}) {
|
|
130
|
+
const toggle = async function(key, options = {}) {
|
|
132
131
|
const state = this;
|
|
133
|
-
state.update({ [key]: !state[key] }, options);
|
|
132
|
+
return await state.update({ [key]: !state[key] }, options);
|
|
134
133
|
};
|
|
135
|
-
const remove = function(key, options = {}) {
|
|
134
|
+
const remove = async function(key, options = {}) {
|
|
136
135
|
const state = this;
|
|
137
136
|
if ((0, import_utils.isArray)(state)) (0, import_utils.removeFromArray)(state, key);
|
|
138
137
|
if ((0, import_utils.isObject)(state)) (0, import_utils.removeFromObject)(state, key);
|
|
139
138
|
if (options.applyReset)
|
|
140
|
-
return state.set(state.parse(), { replace: true, ...options });
|
|
141
|
-
return state.update();
|
|
139
|
+
return await state.set(state.parse(), { replace: true, ...options });
|
|
140
|
+
return await state.update();
|
|
142
141
|
};
|
|
143
|
-
const set = function(val, options = {}) {
|
|
142
|
+
const set = async function(val, options = {}) {
|
|
144
143
|
const state = this;
|
|
145
144
|
const value = (0, import_utils.deepClone)(val);
|
|
146
|
-
|
|
145
|
+
await state.clean({ preventStateUpdate: true, ...options });
|
|
146
|
+
await state.update(value, { replace: true, ...options });
|
|
147
|
+
return state;
|
|
147
148
|
};
|
|
148
|
-
const setByPath = function(path, val, options = {}) {
|
|
149
|
+
const setByPath = async function(path, val, options = {}) {
|
|
149
150
|
const state = this;
|
|
150
151
|
const value = (0, import_utils.deepClone)(val);
|
|
151
152
|
if (!options.preventReplace) (0, import_utils.setInObjectByPath)(state, path, val);
|
|
152
153
|
const update = (0, import_utils.createNestedObject)(path, value);
|
|
153
154
|
if (options.preventStateUpdate) return update;
|
|
154
|
-
return state.update(update, options);
|
|
155
|
+
return await state.update(update, options);
|
|
155
156
|
};
|
|
156
157
|
const setPathCollection = async function(changes, options = {}) {
|
|
157
158
|
const state = this;
|
|
158
|
-
const update = changes.reduce((
|
|
159
|
+
const update = await changes.reduce(async (promacc, change) => {
|
|
160
|
+
const acc = await promacc;
|
|
159
161
|
if (change[0] === "update") {
|
|
160
|
-
const result = setByPath.call(state, change[1], change[2], {
|
|
162
|
+
const result = await setByPath.call(state, change[1], change[2], {
|
|
161
163
|
...options,
|
|
162
164
|
preventStateUpdate: true
|
|
163
165
|
});
|
|
164
166
|
return (0, import_utils.overwriteDeep)(acc, result);
|
|
165
167
|
} else if (change[0] === "delete") {
|
|
166
|
-
removeByPath.call(state, change[1], options);
|
|
168
|
+
await removeByPath.call(state, change[1], options);
|
|
167
169
|
}
|
|
168
170
|
return acc;
|
|
169
171
|
}, {});
|
|
@@ -175,57 +177,59 @@ const removeByPath = async function(path, options = {}) {
|
|
|
175
177
|
if (options.preventUpdate) return path;
|
|
176
178
|
return await state.update({}, options);
|
|
177
179
|
};
|
|
178
|
-
const removePathCollection = function(changes, options = {}) {
|
|
180
|
+
const removePathCollection = async function(changes, options = {}) {
|
|
179
181
|
const state = this;
|
|
180
|
-
changes.forEach((item) => {
|
|
181
|
-
removeByPath(item, { preventUpdate: true });
|
|
182
|
+
changes.forEach(async (item) => {
|
|
183
|
+
await removeByPath(item, { preventUpdate: true });
|
|
182
184
|
});
|
|
183
|
-
return state.update({}, options);
|
|
185
|
+
return await state.update({}, options);
|
|
184
186
|
};
|
|
185
187
|
const getByPath = function(path, options = {}) {
|
|
186
188
|
const state = this;
|
|
187
189
|
return (0, import_utils.getInObjectByPath)(state, path);
|
|
188
190
|
};
|
|
189
|
-
const reset = function(options = {}) {
|
|
191
|
+
const reset = async function(options = {}) {
|
|
190
192
|
const state = this;
|
|
191
193
|
const value = (0, import_utils.deepClone)(state.parse());
|
|
192
|
-
return state.set(value, { replace: true, ...options });
|
|
194
|
+
return await state.set(value, { replace: true, ...options });
|
|
193
195
|
};
|
|
194
|
-
const apply = function(func, options = {}) {
|
|
196
|
+
const apply = async function(func, options = {}) {
|
|
195
197
|
const state = this;
|
|
196
198
|
if ((0, import_utils.isFunction)(func)) {
|
|
197
199
|
const value = func(state);
|
|
198
|
-
return state.update(value, { replace: true, ...options });
|
|
200
|
+
return await state.update(value, { replace: true, ...options });
|
|
199
201
|
}
|
|
200
202
|
};
|
|
201
|
-
const applyReplace = function(func, options = {}) {
|
|
203
|
+
const applyReplace = async function(func, options = {}) {
|
|
202
204
|
const state = this;
|
|
203
205
|
if ((0, import_utils.isFunction)(func)) {
|
|
204
206
|
const value = func(state);
|
|
205
|
-
return state.replace(value, options);
|
|
207
|
+
return await state.replace(value, options);
|
|
206
208
|
}
|
|
207
209
|
};
|
|
208
|
-
const applyFunction = function(func, options = {}) {
|
|
210
|
+
const applyFunction = async function(func, options = {}) {
|
|
209
211
|
const state = this;
|
|
210
212
|
if ((0, import_utils.isFunction)(func)) {
|
|
211
|
-
func(state);
|
|
212
|
-
|
|
213
|
+
const result = func(state);
|
|
214
|
+
if (result instanceof Promise) await result;
|
|
215
|
+
else result;
|
|
216
|
+
return await state.update(state.parse(), { replace: true, ...options });
|
|
213
217
|
}
|
|
214
218
|
};
|
|
215
|
-
const quietUpdate = function(obj, options = {}) {
|
|
219
|
+
const quietUpdate = async function(obj, options = {}) {
|
|
216
220
|
const state = this;
|
|
217
|
-
return state.update(obj, { preventUpdate: true, ...options });
|
|
221
|
+
return await state.update(obj, { preventUpdate: true, ...options });
|
|
218
222
|
};
|
|
219
|
-
const replace = function(obj, options = {}) {
|
|
223
|
+
const replace = async function(obj, options = {}) {
|
|
220
224
|
const state = this;
|
|
221
225
|
for (const param in obj) {
|
|
222
226
|
state[param] = obj[param];
|
|
223
227
|
}
|
|
224
|
-
return state.update(obj, options);
|
|
228
|
+
return await state.update(obj, options);
|
|
225
229
|
};
|
|
226
|
-
const quietReplace = function(obj, options = {}) {
|
|
230
|
+
const quietReplace = async function(obj, options = {}) {
|
|
227
231
|
const state = this;
|
|
228
|
-
return state.replace(obj, { preventUpdate: true, ...options });
|
|
232
|
+
return await state.replace(obj, { preventUpdate: true, ...options });
|
|
229
233
|
};
|
|
230
234
|
const keys = function(obj, options = {}) {
|
|
231
235
|
const state = this;
|
package/dist/esm/create.js
CHANGED
|
@@ -75,7 +75,7 @@ const applyInitialState = async function(element, parent, options) {
|
|
|
75
75
|
);
|
|
76
76
|
if (dependentState) element.state = dependentState;
|
|
77
77
|
applyMethods(element);
|
|
78
|
-
await triggerEventOn("stateCreated", element);
|
|
78
|
+
await triggerEventOn("stateCreated", element, options);
|
|
79
79
|
return element.state;
|
|
80
80
|
};
|
|
81
81
|
const applyDependentState = (element, state) => {
|
package/dist/esm/methods.js
CHANGED
|
@@ -42,11 +42,10 @@ const parse = function() {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
return obj;
|
|
45
|
-
} else
|
|
46
|
-
return state.filter((item) => !IGNORE_STATE_PARAMS.includes(item));
|
|
45
|
+
} else {
|
|
47
46
|
}
|
|
48
47
|
};
|
|
49
|
-
const clean = function(options = {}) {
|
|
48
|
+
const clean = async function(options = {}) {
|
|
50
49
|
const state = this;
|
|
51
50
|
for (const param in state) {
|
|
52
51
|
if (!IGNORE_STATE_PARAMS.includes(param) && Object.hasOwnProperty.call(state, param)) {
|
|
@@ -54,16 +53,16 @@ const clean = function(options = {}) {
|
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
if (!options.preventStateUpdate) {
|
|
57
|
-
state.update(state, __spreadValues({ replace: true }, options));
|
|
56
|
+
await state.update(state, __spreadValues({ replace: true }, options));
|
|
58
57
|
}
|
|
59
58
|
return state;
|
|
60
59
|
};
|
|
61
|
-
const destroy = function(options = {}) {
|
|
60
|
+
const destroy = async function(options = {}) {
|
|
62
61
|
const state = this;
|
|
63
62
|
const element = state.__element;
|
|
64
63
|
const stateKey = element.__ref.__state;
|
|
65
64
|
if (isString(stateKey)) {
|
|
66
|
-
element.parent.state.remove(stateKey, __spreadValues({ isHoisted: true }, options));
|
|
65
|
+
await element.parent.state.remove(stateKey, __spreadValues({ isHoisted: true }, options));
|
|
67
66
|
return element.state;
|
|
68
67
|
}
|
|
69
68
|
delete element.state;
|
|
@@ -91,65 +90,68 @@ const destroy = function(options = {}) {
|
|
|
91
90
|
}
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
|
-
element.state.update({}, __spreadValues({ isHoisted: true }, options));
|
|
93
|
+
await element.state.update({}, __spreadValues({ isHoisted: true }, options));
|
|
95
94
|
return element.state;
|
|
96
95
|
};
|
|
97
|
-
const parentUpdate = function(obj, options = {}) {
|
|
96
|
+
const parentUpdate = async function(obj, options = {}) {
|
|
98
97
|
const state = this;
|
|
99
98
|
if (!state || !state.parent) return;
|
|
100
|
-
return state.parent.update(obj, __spreadValues({ isHoisted: true }, options));
|
|
99
|
+
return await state.parent.update(obj, __spreadValues({ isHoisted: true }, options));
|
|
101
100
|
};
|
|
102
|
-
const rootUpdate = function(obj, options = {}) {
|
|
101
|
+
const rootUpdate = async function(obj, options = {}) {
|
|
103
102
|
const state = this;
|
|
104
103
|
if (!state) return;
|
|
105
104
|
const rootState = state.__element.__ref.root.state;
|
|
106
|
-
return rootState.update(obj, __spreadValues({ isHoisted: false }, options));
|
|
105
|
+
return await rootState.update(obj, __spreadValues({ isHoisted: false }, options));
|
|
107
106
|
};
|
|
108
|
-
const add = function(value, options = {}) {
|
|
107
|
+
const add = async function(value, options = {}) {
|
|
109
108
|
const state = this;
|
|
110
109
|
if (isArray(state)) {
|
|
111
|
-
state.push(value);
|
|
112
|
-
state.update(state.parse(), __spreadValues({ overwrite: true }, options));
|
|
110
|
+
await state.push(value);
|
|
111
|
+
return await state.update(state.parse(), __spreadValues({ overwrite: true }, options));
|
|
113
112
|
} else if (isObject(state)) {
|
|
114
113
|
const key = Object.keys(state).length;
|
|
115
|
-
state.update({ [key]: value }, options);
|
|
114
|
+
return await state.update({ [key]: value }, options);
|
|
116
115
|
}
|
|
117
116
|
};
|
|
118
|
-
const toggle = function(key, options = {}) {
|
|
117
|
+
const toggle = async function(key, options = {}) {
|
|
119
118
|
const state = this;
|
|
120
|
-
state.update({ [key]: !state[key] }, options);
|
|
119
|
+
return await state.update({ [key]: !state[key] }, options);
|
|
121
120
|
};
|
|
122
|
-
const remove = function(key, options = {}) {
|
|
121
|
+
const remove = async function(key, options = {}) {
|
|
123
122
|
const state = this;
|
|
124
123
|
if (isArray(state)) removeFromArray(state, key);
|
|
125
124
|
if (isObject(state)) removeFromObject(state, key);
|
|
126
125
|
if (options.applyReset)
|
|
127
|
-
return state.set(state.parse(), __spreadValues({ replace: true }, options));
|
|
128
|
-
return state.update();
|
|
126
|
+
return await state.set(state.parse(), __spreadValues({ replace: true }, options));
|
|
127
|
+
return await state.update();
|
|
129
128
|
};
|
|
130
|
-
const set = function(val, options = {}) {
|
|
129
|
+
const set = async function(val, options = {}) {
|
|
131
130
|
const state = this;
|
|
132
131
|
const value = deepClone(val);
|
|
133
|
-
|
|
132
|
+
await state.clean(__spreadValues({ preventStateUpdate: true }, options));
|
|
133
|
+
await state.update(value, __spreadValues({ replace: true }, options));
|
|
134
|
+
return state;
|
|
134
135
|
};
|
|
135
|
-
const setByPath = function(path, val, options = {}) {
|
|
136
|
+
const setByPath = async function(path, val, options = {}) {
|
|
136
137
|
const state = this;
|
|
137
138
|
const value = deepClone(val);
|
|
138
139
|
if (!options.preventReplace) setInObjectByPath(state, path, val);
|
|
139
140
|
const update = createNestedObject(path, value);
|
|
140
141
|
if (options.preventStateUpdate) return update;
|
|
141
|
-
return state.update(update, options);
|
|
142
|
+
return await state.update(update, options);
|
|
142
143
|
};
|
|
143
144
|
const setPathCollection = async function(changes, options = {}) {
|
|
144
145
|
const state = this;
|
|
145
|
-
const update = changes.reduce((
|
|
146
|
+
const update = await changes.reduce(async (promacc, change) => {
|
|
147
|
+
const acc = await promacc;
|
|
146
148
|
if (change[0] === "update") {
|
|
147
|
-
const result = setByPath.call(state, change[1], change[2], __spreadProps(__spreadValues({}, options), {
|
|
149
|
+
const result = await setByPath.call(state, change[1], change[2], __spreadProps(__spreadValues({}, options), {
|
|
148
150
|
preventStateUpdate: true
|
|
149
151
|
}));
|
|
150
152
|
return overwriteDeep(acc, result);
|
|
151
153
|
} else if (change[0] === "delete") {
|
|
152
|
-
removeByPath.call(state, change[1], options);
|
|
154
|
+
await removeByPath.call(state, change[1], options);
|
|
153
155
|
}
|
|
154
156
|
return acc;
|
|
155
157
|
}, {});
|
|
@@ -161,57 +163,59 @@ const removeByPath = async function(path, options = {}) {
|
|
|
161
163
|
if (options.preventUpdate) return path;
|
|
162
164
|
return await state.update({}, options);
|
|
163
165
|
};
|
|
164
|
-
const removePathCollection = function(changes, options = {}) {
|
|
166
|
+
const removePathCollection = async function(changes, options = {}) {
|
|
165
167
|
const state = this;
|
|
166
|
-
changes.forEach((item) => {
|
|
167
|
-
removeByPath(item, { preventUpdate: true });
|
|
168
|
+
changes.forEach(async (item) => {
|
|
169
|
+
await removeByPath(item, { preventUpdate: true });
|
|
168
170
|
});
|
|
169
|
-
return state.update({}, options);
|
|
171
|
+
return await state.update({}, options);
|
|
170
172
|
};
|
|
171
173
|
const getByPath = function(path, options = {}) {
|
|
172
174
|
const state = this;
|
|
173
175
|
return getInObjectByPath(state, path);
|
|
174
176
|
};
|
|
175
|
-
const reset = function(options = {}) {
|
|
177
|
+
const reset = async function(options = {}) {
|
|
176
178
|
const state = this;
|
|
177
179
|
const value = deepClone(state.parse());
|
|
178
|
-
return state.set(value, __spreadValues({ replace: true }, options));
|
|
180
|
+
return await state.set(value, __spreadValues({ replace: true }, options));
|
|
179
181
|
};
|
|
180
|
-
const apply = function(func, options = {}) {
|
|
182
|
+
const apply = async function(func, options = {}) {
|
|
181
183
|
const state = this;
|
|
182
184
|
if (isFunction(func)) {
|
|
183
185
|
const value = func(state);
|
|
184
|
-
return state.update(value, __spreadValues({ replace: true }, options));
|
|
186
|
+
return await state.update(value, __spreadValues({ replace: true }, options));
|
|
185
187
|
}
|
|
186
188
|
};
|
|
187
|
-
const applyReplace = function(func, options = {}) {
|
|
189
|
+
const applyReplace = async function(func, options = {}) {
|
|
188
190
|
const state = this;
|
|
189
191
|
if (isFunction(func)) {
|
|
190
192
|
const value = func(state);
|
|
191
|
-
return state.replace(value, options);
|
|
193
|
+
return await state.replace(value, options);
|
|
192
194
|
}
|
|
193
195
|
};
|
|
194
|
-
const applyFunction = function(func, options = {}) {
|
|
196
|
+
const applyFunction = async function(func, options = {}) {
|
|
195
197
|
const state = this;
|
|
196
198
|
if (isFunction(func)) {
|
|
197
|
-
func(state);
|
|
198
|
-
|
|
199
|
+
const result = func(state);
|
|
200
|
+
if (result instanceof Promise) await result;
|
|
201
|
+
else result;
|
|
202
|
+
return await state.update(state.parse(), __spreadValues({ replace: true }, options));
|
|
199
203
|
}
|
|
200
204
|
};
|
|
201
|
-
const quietUpdate = function(obj, options = {}) {
|
|
205
|
+
const quietUpdate = async function(obj, options = {}) {
|
|
202
206
|
const state = this;
|
|
203
|
-
return state.update(obj, __spreadValues({ preventUpdate: true }, options));
|
|
207
|
+
return await state.update(obj, __spreadValues({ preventUpdate: true }, options));
|
|
204
208
|
};
|
|
205
|
-
const replace = function(obj, options = {}) {
|
|
209
|
+
const replace = async function(obj, options = {}) {
|
|
206
210
|
const state = this;
|
|
207
211
|
for (const param in obj) {
|
|
208
212
|
state[param] = obj[param];
|
|
209
213
|
}
|
|
210
|
-
return state.update(obj, options);
|
|
214
|
+
return await state.update(obj, options);
|
|
211
215
|
};
|
|
212
|
-
const quietReplace = function(obj, options = {}) {
|
|
216
|
+
const quietReplace = async function(obj, options = {}) {
|
|
213
217
|
const state = this;
|
|
214
|
-
return state.replace(obj, __spreadValues({ preventUpdate: true }, options));
|
|
218
|
+
return await state.replace(obj, __spreadValues({ preventUpdate: true }, options));
|
|
215
219
|
};
|
|
216
220
|
const keys = function(obj, options = {}) {
|
|
217
221
|
const state = this;
|
package/methods.js
CHANGED
|
@@ -27,12 +27,11 @@ export const parse = function () {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
return obj
|
|
30
|
-
} else
|
|
31
|
-
return state.filter(item => !IGNORE_STATE_PARAMS.includes(item))
|
|
30
|
+
} else {
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
export const clean = function (options = {}) {
|
|
34
|
+
export const clean = async function (options = {}) {
|
|
36
35
|
const state = this
|
|
37
36
|
for (const param in state) {
|
|
38
37
|
if (
|
|
@@ -43,18 +42,18 @@ export const clean = function (options = {}) {
|
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
if (!options.preventStateUpdate) {
|
|
46
|
-
state.update(state, { replace: true, ...options })
|
|
45
|
+
await state.update(state, { replace: true, ...options })
|
|
47
46
|
}
|
|
48
47
|
return state
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
export const destroy = function (options = {}) {
|
|
50
|
+
export const destroy = async function (options = {}) {
|
|
52
51
|
const state = this
|
|
53
52
|
const element = state.__element
|
|
54
53
|
|
|
55
54
|
const stateKey = element.__ref.__state
|
|
56
55
|
if (isString(stateKey)) {
|
|
57
|
-
element.parent.state.remove(stateKey, { isHoisted: true, ...options })
|
|
56
|
+
await element.parent.state.remove(stateKey, { isHoisted: true, ...options })
|
|
58
57
|
return element.state
|
|
59
58
|
}
|
|
60
59
|
|
|
@@ -83,76 +82,77 @@ export const destroy = function (options = {}) {
|
|
|
83
82
|
}
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
element.state.update({}, { isHoisted: true, ...options })
|
|
85
|
+
await element.state.update({}, { isHoisted: true, ...options })
|
|
87
86
|
return element.state
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
export const parentUpdate = function (obj, options = {}) {
|
|
89
|
+
export const parentUpdate = async function (obj, options = {}) {
|
|
91
90
|
const state = this
|
|
92
91
|
if (!state || !state.parent) return
|
|
93
|
-
return state.parent.update(obj, { isHoisted: true, ...options })
|
|
92
|
+
return await state.parent.update(obj, { isHoisted: true, ...options })
|
|
94
93
|
}
|
|
95
94
|
|
|
96
|
-
export const rootUpdate = function (obj, options = {}) {
|
|
95
|
+
export const rootUpdate = async function (obj, options = {}) {
|
|
97
96
|
const state = this
|
|
98
97
|
if (!state) return
|
|
99
98
|
const rootState = state.__element.__ref.root.state
|
|
100
|
-
return rootState.update(obj, { isHoisted: false, ...options })
|
|
99
|
+
return await rootState.update(obj, { isHoisted: false, ...options })
|
|
101
100
|
}
|
|
102
101
|
|
|
103
|
-
export const add = function (value, options = {}) {
|
|
102
|
+
export const add = async function (value, options = {}) {
|
|
104
103
|
const state = this
|
|
105
104
|
if (isArray(state)) {
|
|
106
|
-
state.push(value)
|
|
107
|
-
state.update(state.parse(), { overwrite: true, ...options })
|
|
105
|
+
await state.push(value)
|
|
106
|
+
return await state.update(state.parse(), { overwrite: true, ...options })
|
|
108
107
|
} else if (isObject(state)) {
|
|
109
108
|
const key = Object.keys(state).length
|
|
110
|
-
state.update({ [key]: value }, options)
|
|
109
|
+
return await state.update({ [key]: value }, options)
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
export const toggle = function (key, options = {}) {
|
|
113
|
+
export const toggle = async function (key, options = {}) {
|
|
115
114
|
const state = this
|
|
116
|
-
state.update({ [key]: !state[key] }, options)
|
|
115
|
+
return await state.update({ [key]: !state[key] }, options)
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
export const remove = function (key, options = {}) {
|
|
118
|
+
export const remove = async function (key, options = {}) {
|
|
120
119
|
const state = this
|
|
121
120
|
if (isArray(state)) removeFromArray(state, key)
|
|
122
121
|
if (isObject(state)) removeFromObject(state, key)
|
|
123
122
|
if (options.applyReset)
|
|
124
|
-
return state.set(state.parse(), { replace: true, ...options })
|
|
125
|
-
return state.update()
|
|
123
|
+
return await state.set(state.parse(), { replace: true, ...options })
|
|
124
|
+
return await state.update()
|
|
126
125
|
}
|
|
127
126
|
|
|
128
|
-
export const set = function (val, options = {}) {
|
|
127
|
+
export const set = async function (val, options = {}) {
|
|
129
128
|
const state = this
|
|
130
129
|
const value = deepClone(val)
|
|
130
|
+
await state.clean({ preventStateUpdate: true, ...options })
|
|
131
|
+
await state.update(value, { replace: true, ...options })
|
|
131
132
|
return state
|
|
132
|
-
.clean({ preventStateUpdate: true, ...options })
|
|
133
|
-
.update(value, { replace: true, ...options })
|
|
134
133
|
}
|
|
135
134
|
|
|
136
|
-
export const setByPath = function (path, val, options = {}) {
|
|
135
|
+
export const setByPath = async function (path, val, options = {}) {
|
|
137
136
|
const state = this
|
|
138
137
|
const value = deepClone(val)
|
|
139
138
|
if (!options.preventReplace) setInObjectByPath(state, path, val)
|
|
140
139
|
const update = createNestedObject(path, value)
|
|
141
140
|
if (options.preventStateUpdate) return update
|
|
142
|
-
return state.update(update, options)
|
|
141
|
+
return await state.update(update, options)
|
|
143
142
|
}
|
|
144
143
|
|
|
145
144
|
export const setPathCollection = async function (changes, options = {}) {
|
|
146
145
|
const state = this
|
|
147
|
-
const update = changes.reduce((
|
|
146
|
+
const update = await changes.reduce(async (promacc, change) => {
|
|
147
|
+
const acc = await promacc
|
|
148
148
|
if (change[0] === 'update') {
|
|
149
|
-
const result = setByPath.call(state, change[1], change[2], {
|
|
149
|
+
const result = await setByPath.call(state, change[1], change[2], {
|
|
150
150
|
...options,
|
|
151
151
|
preventStateUpdate: true
|
|
152
152
|
})
|
|
153
153
|
return overwriteDeep(acc, result)
|
|
154
154
|
} else if (change[0] === 'delete') {
|
|
155
|
-
removeByPath.call(state, change[1], options)
|
|
155
|
+
await removeByPath.call(state, change[1], options)
|
|
156
156
|
}
|
|
157
157
|
return acc
|
|
158
158
|
}, {})
|
|
@@ -166,12 +166,12 @@ export const removeByPath = async function (path, options = {}) {
|
|
|
166
166
|
return await state.update({}, options)
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
export const removePathCollection = function (changes, options = {}) {
|
|
169
|
+
export const removePathCollection = async function (changes, options = {}) {
|
|
170
170
|
const state = this
|
|
171
|
-
changes.forEach(item => {
|
|
172
|
-
removeByPath(item, { preventUpdate: true })
|
|
171
|
+
changes.forEach(async (item) => {
|
|
172
|
+
await removeByPath(item, { preventUpdate: true })
|
|
173
173
|
})
|
|
174
|
-
return state.update({}, options)
|
|
174
|
+
return await state.update({}, options)
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
export const getByPath = function (path, options = {}) {
|
|
@@ -179,54 +179,56 @@ export const getByPath = function (path, options = {}) {
|
|
|
179
179
|
return getInObjectByPath(state, path)
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
export const reset = function (options = {}) {
|
|
182
|
+
export const reset = async function (options = {}) {
|
|
183
183
|
const state = this
|
|
184
184
|
const value = deepClone(state.parse())
|
|
185
|
-
return state.set(value, { replace: true, ...options })
|
|
185
|
+
return await state.set(value, { replace: true, ...options })
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
export const apply = function (func, options = {}) {
|
|
188
|
+
export const apply = async function (func, options = {}) {
|
|
189
189
|
const state = this
|
|
190
190
|
if (isFunction(func)) {
|
|
191
191
|
const value = func(state)
|
|
192
|
-
return state.update(value, { replace: true, ...options })
|
|
192
|
+
return await state.update(value, { replace: true, ...options })
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
export const applyReplace = function (func, options = {}) {
|
|
196
|
+
export const applyReplace = async function (func, options = {}) {
|
|
197
197
|
const state = this
|
|
198
198
|
if (isFunction(func)) {
|
|
199
199
|
const value = func(state)
|
|
200
|
-
return state.replace(value, options)
|
|
200
|
+
return await state.replace(value, options)
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
export const applyFunction = function (func, options = {}) {
|
|
204
|
+
export const applyFunction = async function (func, options = {}) {
|
|
205
205
|
const state = this
|
|
206
206
|
if (isFunction(func)) {
|
|
207
|
-
func(state)
|
|
208
|
-
|
|
207
|
+
const result = func(state)
|
|
208
|
+
if (result instanceof Promise) await result
|
|
209
|
+
else result
|
|
210
|
+
return await state.update(state.parse(), { replace: true, ...options })
|
|
209
211
|
}
|
|
210
212
|
}
|
|
211
213
|
|
|
212
|
-
export const quietUpdate = function (obj, options = {}) {
|
|
214
|
+
export const quietUpdate = async function (obj, options = {}) {
|
|
213
215
|
const state = this
|
|
214
|
-
return state.update(obj, { preventUpdate: true, ...options })
|
|
216
|
+
return await state.update(obj, { preventUpdate: true, ...options })
|
|
215
217
|
}
|
|
216
218
|
|
|
217
|
-
export const replace = function (obj, options = {}) {
|
|
219
|
+
export const replace = async function (obj, options = {}) {
|
|
218
220
|
const state = this
|
|
219
221
|
|
|
220
222
|
for (const param in obj) {
|
|
221
223
|
state[param] = obj[param]
|
|
222
224
|
}
|
|
223
225
|
|
|
224
|
-
return state.update(obj, options)
|
|
226
|
+
return await state.update(obj, options)
|
|
225
227
|
}
|
|
226
228
|
|
|
227
|
-
export const quietReplace = function (obj, options = {}) {
|
|
229
|
+
export const quietReplace = async function (obj, options = {}) {
|
|
228
230
|
const state = this
|
|
229
|
-
return state.replace(obj, { preventUpdate: true, ...options })
|
|
231
|
+
return await state.replace(obj, { preventUpdate: true, ...options })
|
|
230
232
|
}
|
|
231
233
|
|
|
232
234
|
export const keys = function (obj, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.31.
|
|
3
|
+
"version": "2.31.27",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"prepublish": "npx rimraf -I dist && npm run build && npm run copy:package:cjs"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@domql/event": "^2.31.
|
|
32
|
-
"@domql/report": "^2.31.
|
|
33
|
-
"@domql/utils": "^2.31.
|
|
31
|
+
"@domql/event": "^2.31.27",
|
|
32
|
+
"@domql/report": "^2.31.27",
|
|
33
|
+
"@domql/utils": "^2.31.27"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "0edcd5aae5c16b6a53a7e9b6512bb2562e8eb8a1"
|
|
36
36
|
}
|