@domql/state 2.5.178 → 2.5.179

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.
@@ -24,16 +24,21 @@ __export(methods_exports, {
24
24
  applyReplace: () => applyReplace,
25
25
  clean: () => clean,
26
26
  destroy: () => destroy,
27
+ getByPath: () => getByPath,
27
28
  keys: () => keys,
28
29
  parentUpdate: () => parentUpdate,
29
30
  parse: () => parse,
30
31
  quietReplace: () => quietReplace,
31
32
  quietUpdate: () => quietUpdate,
32
33
  remove: () => remove,
34
+ removeByPath: () => removeByPath,
35
+ removePathCollection: () => removePathCollection,
33
36
  replace: () => replace,
34
37
  reset: () => reset,
35
38
  rootUpdate: () => rootUpdate,
36
39
  set: () => set,
40
+ setByPath: () => setByPath,
41
+ setPathCollection: () => setPathCollection,
37
42
  toggle: () => toggle,
38
43
  values: () => values
39
44
  });
@@ -144,6 +149,41 @@ const set = function(val, options = {}) {
144
149
  const value = (0, import_utils.deepClone)(val);
145
150
  return state.clean({ preventStateUpdate: true, ...options }).update(value, { replace: true, ...options });
146
151
  };
152
+ const setByPath = function(path, val, options = {}) {
153
+ const state = this;
154
+ const value = (0, import_utils.deepClone)(val);
155
+ (0, import_utils.setInObjectByPath)(state, path, val);
156
+ const update = (0, import_utils.createNestedObject)(path, value);
157
+ if (options.preventUpdate)
158
+ return update;
159
+ return state.update(update, options);
160
+ };
161
+ const setPathCollection = function(changes, options = {}) {
162
+ const state = this;
163
+ const update = changes.reduce((acc, change) => {
164
+ const result = setByPath(...change, { preventUpdate: true });
165
+ return (0, import_utils.overwriteDeep)(acc, result);
166
+ }, {});
167
+ return state.update(update, options);
168
+ };
169
+ const removeByPath = function(path, options = {}) {
170
+ const state = this;
171
+ (0, import_utils.removeNestedKeyByPath)(state, path);
172
+ if (options.preventUpdate)
173
+ return path;
174
+ return state.update({}, options);
175
+ };
176
+ const removePathCollection = function(changes, options = {}) {
177
+ const state = this;
178
+ changes.forEach((item) => {
179
+ removeByPath(item, { preventUpdate: true });
180
+ });
181
+ return state.update({}, options);
182
+ };
183
+ const getByPath = function(path, options = {}) {
184
+ const state = this;
185
+ return (0, import_utils.getInObjectByPath)(state, path);
186
+ };
147
187
  const reset = function(options = {}) {
148
188
  const state = this;
149
189
  const value = (0, import_utils.deepClone)(state.parse());
package/methods.js CHANGED
@@ -7,7 +7,12 @@ import {
7
7
  isObject,
8
8
  isString,
9
9
  removeFromArray,
10
- removeFromObject
10
+ removeFromObject,
11
+ overwriteDeep,
12
+ createNestedObject,
13
+ getInObjectByPath,
14
+ removeNestedKeyByPath,
15
+ setInObjectByPath
11
16
  } from '@domql/utils'
12
17
 
13
18
  import { IGNORE_STATE_PARAMS } from './ignore'
@@ -123,6 +128,44 @@ export const set = function (val, options = {}) {
123
128
  .update(value, { replace: true, ...options })
124
129
  }
125
130
 
131
+ export const setByPath = function (path, val, options = {}) {
132
+ const state = this
133
+ const value = deepClone(val)
134
+ setInObjectByPath(state, path, val)
135
+ const update = createNestedObject(path, value)
136
+ if (options.preventUpdate) return update
137
+ return state.update(update, options)
138
+ }
139
+
140
+ export const setPathCollection = function (changes, options = {}) {
141
+ const state = this
142
+ const update = changes.reduce((acc, change) => {
143
+ const result = setByPath(...change, { preventUpdate: true })
144
+ return overwriteDeep(acc, result)
145
+ }, {})
146
+ return state.update(update, options)
147
+ }
148
+
149
+ export const removeByPath = function (path, options = {}) {
150
+ const state = this
151
+ removeNestedKeyByPath(state, path)
152
+ if (options.preventUpdate) return path
153
+ return state.update({}, options)
154
+ }
155
+
156
+ export const removePathCollection = function (changes, options = {}) {
157
+ const state = this
158
+ changes.forEach(item => {
159
+ removeByPath(item, { preventUpdate: true })
160
+ })
161
+ return state.update({}, options)
162
+ }
163
+
164
+ export const getByPath = function (path, options = {}) {
165
+ const state = this
166
+ return getInObjectByPath(state, path)
167
+ }
168
+
126
169
  export const reset = function (options = {}) {
127
170
  const state = this
128
171
  const value = deepClone(state.parse())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.5.178",
3
+ "version": "2.5.179",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
@@ -27,9 +27,9 @@
27
27
  "prepublish": "rimraf -I dist && npm run build && npm run copy:package:cjs"
28
28
  },
29
29
  "dependencies": {
30
- "@domql/event": "^2.5.178",
30
+ "@domql/event": "^2.5.179",
31
31
  "@domql/report": "^2.5.162",
32
- "@domql/utils": "^2.5.178"
32
+ "@domql/utils": "^2.5.179"
33
33
  },
34
- "gitHead": "b274eb76e068d125b38f9e617fcfb98d657eafbd"
34
+ "gitHead": "6dd81dc7848b03bd9bf564dbc82cd95af713ae21"
35
35
  }