@domql/state 2.28.59 → 2.28.60
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/cjs/methods.js +7 -3
- package/dist/esm/methods.js +9 -3
- package/methods.js +14 -6
- package/package.json +5 -5
package/dist/cjs/methods.js
CHANGED
|
@@ -136,7 +136,8 @@ const remove = function(key, options = {}) {
|
|
|
136
136
|
const state = this;
|
|
137
137
|
if ((0, import_utils.isArray)(state)) (0, import_utils.removeFromArray)(state, key);
|
|
138
138
|
if ((0, import_utils.isObject)(state)) (0, import_utils.removeFromObject)(state, key);
|
|
139
|
-
if (options.applyReset)
|
|
139
|
+
if (options.applyReset)
|
|
140
|
+
return state.set(state.parse(), { replace: true, ...options });
|
|
140
141
|
return state.update();
|
|
141
142
|
};
|
|
142
143
|
const set = function(val, options = {}) {
|
|
@@ -147,7 +148,7 @@ const set = function(val, options = {}) {
|
|
|
147
148
|
const setByPath = function(path, val, options = {}) {
|
|
148
149
|
const state = this;
|
|
149
150
|
const value = (0, import_utils.deepClone)(val);
|
|
150
|
-
(0, import_utils.setInObjectByPath)(state, path, val);
|
|
151
|
+
if (!options.preventReplace) (0, import_utils.setInObjectByPath)(state, path, val);
|
|
151
152
|
const update = (0, import_utils.createNestedObject)(path, value);
|
|
152
153
|
if (options.preventStateUpdate) return update;
|
|
153
154
|
return state.update(update, options);
|
|
@@ -156,7 +157,10 @@ const setPathCollection = async function(changes, options = {}) {
|
|
|
156
157
|
const state = this;
|
|
157
158
|
const update = changes.reduce((acc, change) => {
|
|
158
159
|
if (change[0] === "update") {
|
|
159
|
-
const result = setByPath.call(state, change[1], change[2], {
|
|
160
|
+
const result = setByPath.call(state, change[1], change[2], {
|
|
161
|
+
...options,
|
|
162
|
+
preventStateUpdate: true
|
|
163
|
+
});
|
|
160
164
|
return (0, import_utils.overwriteDeep)(acc, result);
|
|
161
165
|
} else if (change[0] === "delete") {
|
|
162
166
|
removeByPath.call(state, change[1], options);
|
package/dist/esm/methods.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
import {
|
|
18
21
|
isArray,
|
|
19
22
|
deepClone,
|
|
@@ -120,7 +123,8 @@ const remove = function(key, options = {}) {
|
|
|
120
123
|
const state = this;
|
|
121
124
|
if (isArray(state)) removeFromArray(state, key);
|
|
122
125
|
if (isObject(state)) removeFromObject(state, key);
|
|
123
|
-
if (options.applyReset)
|
|
126
|
+
if (options.applyReset)
|
|
127
|
+
return state.set(state.parse(), __spreadValues({ replace: true }, options));
|
|
124
128
|
return state.update();
|
|
125
129
|
};
|
|
126
130
|
const set = function(val, options = {}) {
|
|
@@ -131,7 +135,7 @@ const set = function(val, options = {}) {
|
|
|
131
135
|
const setByPath = function(path, val, options = {}) {
|
|
132
136
|
const state = this;
|
|
133
137
|
const value = deepClone(val);
|
|
134
|
-
setInObjectByPath(state, path, val);
|
|
138
|
+
if (!options.preventReplace) setInObjectByPath(state, path, val);
|
|
135
139
|
const update = createNestedObject(path, value);
|
|
136
140
|
if (options.preventStateUpdate) return update;
|
|
137
141
|
return state.update(update, options);
|
|
@@ -140,7 +144,9 @@ const setPathCollection = async function(changes, options = {}) {
|
|
|
140
144
|
const state = this;
|
|
141
145
|
const update = changes.reduce((acc, change) => {
|
|
142
146
|
if (change[0] === "update") {
|
|
143
|
-
const result = setByPath.call(state, change[1], change[2], {
|
|
147
|
+
const result = setByPath.call(state, change[1], change[2], __spreadProps(__spreadValues({}, options), {
|
|
148
|
+
preventStateUpdate: true
|
|
149
|
+
}));
|
|
144
150
|
return overwriteDeep(acc, result);
|
|
145
151
|
} else if (change[0] === "delete") {
|
|
146
152
|
removeByPath.call(state, change[1], options);
|
package/methods.js
CHANGED
|
@@ -35,7 +35,10 @@ export const parse = function () {
|
|
|
35
35
|
export const clean = function (options = {}) {
|
|
36
36
|
const state = this
|
|
37
37
|
for (const param in state) {
|
|
38
|
-
if (
|
|
38
|
+
if (
|
|
39
|
+
!IGNORE_STATE_PARAMS.includes(param) &&
|
|
40
|
+
Object.hasOwnProperty.call(state, param)
|
|
41
|
+
) {
|
|
39
42
|
delete state[param]
|
|
40
43
|
}
|
|
41
44
|
}
|
|
@@ -93,7 +96,7 @@ export const parentUpdate = function (obj, options = {}) {
|
|
|
93
96
|
export const rootUpdate = function (obj, options = {}) {
|
|
94
97
|
const state = this
|
|
95
98
|
if (!state) return
|
|
96
|
-
const rootState =
|
|
99
|
+
const rootState = state.__element.__ref.root.state
|
|
97
100
|
return rootState.update(obj, { isHoisted: false, ...options })
|
|
98
101
|
}
|
|
99
102
|
|
|
@@ -117,21 +120,23 @@ export const remove = function (key, options = {}) {
|
|
|
117
120
|
const state = this
|
|
118
121
|
if (isArray(state)) removeFromArray(state, key)
|
|
119
122
|
if (isObject(state)) removeFromObject(state, key)
|
|
120
|
-
if (options.applyReset)
|
|
123
|
+
if (options.applyReset)
|
|
124
|
+
return state.set(state.parse(), { replace: true, ...options })
|
|
121
125
|
return state.update()
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
export const set = function (val, options = {}) {
|
|
125
129
|
const state = this
|
|
126
130
|
const value = deepClone(val)
|
|
127
|
-
return state
|
|
131
|
+
return state
|
|
132
|
+
.clean({ preventStateUpdate: true, ...options })
|
|
128
133
|
.update(value, { replace: true, ...options })
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
export const setByPath = function (path, val, options = {}) {
|
|
132
137
|
const state = this
|
|
133
138
|
const value = deepClone(val)
|
|
134
|
-
setInObjectByPath(state, path, val)
|
|
139
|
+
if (!options.preventReplace) setInObjectByPath(state, path, val)
|
|
135
140
|
const update = createNestedObject(path, value)
|
|
136
141
|
if (options.preventStateUpdate) return update
|
|
137
142
|
return state.update(update, options)
|
|
@@ -141,7 +146,10 @@ export const setPathCollection = async function (changes, options = {}) {
|
|
|
141
146
|
const state = this
|
|
142
147
|
const update = changes.reduce((acc, change) => {
|
|
143
148
|
if (change[0] === 'update') {
|
|
144
|
-
const result = setByPath.call(state, change[1], change[2], {
|
|
149
|
+
const result = setByPath.call(state, change[1], change[2], {
|
|
150
|
+
...options,
|
|
151
|
+
preventStateUpdate: true
|
|
152
|
+
})
|
|
145
153
|
return overwriteDeep(acc, result)
|
|
146
154
|
} else if (change[0] === 'delete') {
|
|
147
155
|
removeByPath.call(state, change[1], options)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/state",
|
|
3
|
-
"version": "2.28.
|
|
3
|
+
"version": "2.28.60",
|
|
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.28.
|
|
32
|
-
"@domql/report": "^2.28.
|
|
33
|
-
"@domql/utils": "^2.28.
|
|
31
|
+
"@domql/event": "^2.28.60",
|
|
32
|
+
"@domql/report": "^2.28.60",
|
|
33
|
+
"@domql/utils": "^2.28.60"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "0ec4d7cf10409440f682ecd5cf2cbf47573a14eb"
|
|
36
36
|
}
|