@domql/state 2.5.190 → 2.5.197

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.
@@ -154,15 +154,20 @@ const setByPath = function(path, val, options = {}) {
154
154
  const value = (0, import_utils.deepClone)(val);
155
155
  (0, import_utils.setInObjectByPath)(state, path, val);
156
156
  const update = (0, import_utils.createNestedObject)(path, value);
157
- if (options.preventUpdate)
157
+ if (options.preventStateUpdate)
158
158
  return update;
159
159
  return state.update(update, options);
160
160
  };
161
161
  const setPathCollection = function(changes, options = {}) {
162
162
  const state = this;
163
163
  const update = changes.reduce((acc, change) => {
164
- const result = setByPath(...change.slice(1), { preventUpdate: true });
165
- return (0, import_utils.overwriteDeep)(acc, result);
164
+ if (change[0] === "update") {
165
+ const result = setByPath.call(state, change[1], change[2], { preventStateUpdate: true });
166
+ return (0, import_utils.overwriteDeep)(acc, result);
167
+ } else if (change[0] === "remove") {
168
+ removeByPath.call(state, change[1], options);
169
+ }
170
+ return acc;
166
171
  }, {});
167
172
  return state.update(update, options);
168
173
  };
@@ -33,7 +33,7 @@ const STATE_UPDATE_OPTIONS = {
33
33
  isHoisted: true,
34
34
  execStateFunction: true
35
35
  };
36
- const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
36
+ const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
37
37
  const state = this;
38
38
  const element = state.__element;
39
39
  if (options.onEach)
@@ -47,7 +47,7 @@ const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
47
47
  } else if (options.preventInheritAtCurrentState)
48
48
  return;
49
49
  if (!options.preventBeforeStateUpdateListener) {
50
- const beforeStateUpdateReturns = (0, import_event.triggerEventOnUpdate)("beforeStateUpdate", obj, element, options);
50
+ const beforeStateUpdateReturns = await (0, import_event.triggerEventOnUpdate)("beforeStateUpdate", obj, element, options);
51
51
  if (beforeStateUpdateReturns === false)
52
52
  return element;
53
53
  }
@@ -58,7 +58,7 @@ const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
58
58
  updateDependentState(state, obj, options);
59
59
  applyElementUpdate(state, obj, options);
60
60
  if (!options.preventStateUpdateListener) {
61
- (0, import_event.triggerEventOnUpdate)("stateUpdate", obj, element, options);
61
+ await (0, import_event.triggerEventOnUpdate)("stateUpdate", obj, element, options);
62
62
  }
63
63
  return state;
64
64
  };
@@ -138,15 +138,20 @@ const setByPath = function(path, val, options = {}) {
138
138
  const value = deepClone(val);
139
139
  setInObjectByPath(state, path, val);
140
140
  const update = createNestedObject(path, value);
141
- if (options.preventUpdate)
141
+ if (options.preventStateUpdate)
142
142
  return update;
143
143
  return state.update(update, options);
144
144
  };
145
145
  const setPathCollection = function(changes, options = {}) {
146
146
  const state = this;
147
147
  const update = changes.reduce((acc, change) => {
148
- const result = setByPath(...change.slice(1), { preventUpdate: true });
149
- return overwriteDeep(acc, result);
148
+ if (change[0] === "update") {
149
+ const result = setByPath.call(state, change[1], change[2], { preventStateUpdate: true });
150
+ return overwriteDeep(acc, result);
151
+ } else if (change[0] === "remove") {
152
+ removeByPath.call(state, change[1], options);
153
+ }
154
+ return acc;
150
155
  }, {});
151
156
  return state.update(update, options);
152
157
  };
@@ -29,7 +29,7 @@ const STATE_UPDATE_OPTIONS = {
29
29
  isHoisted: true,
30
30
  execStateFunction: true
31
31
  };
32
- const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
32
+ const updateState = async function(obj, options = STATE_UPDATE_OPTIONS) {
33
33
  const state = this;
34
34
  const element = state.__element;
35
35
  if (options.onEach)
@@ -43,7 +43,7 @@ const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
43
43
  } else if (options.preventInheritAtCurrentState)
44
44
  return;
45
45
  if (!options.preventBeforeStateUpdateListener) {
46
- const beforeStateUpdateReturns = triggerEventOnUpdate("beforeStateUpdate", obj, element, options);
46
+ const beforeStateUpdateReturns = await triggerEventOnUpdate("beforeStateUpdate", obj, element, options);
47
47
  if (beforeStateUpdateReturns === false)
48
48
  return element;
49
49
  }
@@ -54,7 +54,7 @@ const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
54
54
  updateDependentState(state, obj, options);
55
55
  applyElementUpdate(state, obj, options);
56
56
  if (!options.preventStateUpdateListener) {
57
- triggerEventOnUpdate("stateUpdate", obj, element, options);
57
+ await triggerEventOnUpdate("stateUpdate", obj, element, options);
58
58
  }
59
59
  return state;
60
60
  };
package/methods.js CHANGED
@@ -133,15 +133,20 @@ export const setByPath = function (path, val, options = {}) {
133
133
  const value = deepClone(val)
134
134
  setInObjectByPath(state, path, val)
135
135
  const update = createNestedObject(path, value)
136
- if (options.preventUpdate) return update
136
+ if (options.preventStateUpdate) return update
137
137
  return state.update(update, options)
138
138
  }
139
139
 
140
140
  export const setPathCollection = function (changes, options = {}) {
141
141
  const state = this
142
142
  const update = changes.reduce((acc, change) => {
143
- const result = setByPath(...change.slice(1), { preventUpdate: true })
144
- return overwriteDeep(acc, result)
143
+ if (change[0] === 'update') {
144
+ const result = setByPath.call(state, change[1], change[2], { preventStateUpdate: true })
145
+ return overwriteDeep(acc, result)
146
+ } else if (change[0] === 'remove') {
147
+ removeByPath.call(state, change[1], options)
148
+ }
149
+ return acc
145
150
  }, {})
146
151
  return state.update(update, options)
147
152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.5.190",
3
+ "version": "2.5.197",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -32,5 +32,5 @@
32
32
  "@domql/report": "^2.5.186",
33
33
  "@domql/utils": "^2.5.187"
34
34
  },
35
- "gitHead": "c4e06a81317c6d43c070d9ad93bbaeba24b3bb3b"
35
+ "gitHead": "15e733d1bd4581ad936ba6614d8936deee098306"
36
36
  }
package/updateState.js CHANGED
@@ -14,7 +14,7 @@ const STATE_UPDATE_OPTIONS = {
14
14
  execStateFunction: true
15
15
  }
16
16
 
17
- export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {
17
+ export const updateState = async function (obj, options = STATE_UPDATE_OPTIONS) {
18
18
  const state = this
19
19
  const element = state.__element
20
20
 
@@ -28,7 +28,7 @@ export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {
28
28
  } else if (options.preventInheritAtCurrentState) return
29
29
 
30
30
  if (!options.preventBeforeStateUpdateListener) {
31
- const beforeStateUpdateReturns = triggerEventOnUpdate('beforeStateUpdate', obj, element, options)
31
+ const beforeStateUpdateReturns = await triggerEventOnUpdate('beforeStateUpdate', obj, element, options)
32
32
  if (beforeStateUpdateReturns === false) return element
33
33
  }
34
34
 
@@ -41,7 +41,7 @@ export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {
41
41
  applyElementUpdate(state, obj, options)
42
42
 
43
43
  if (!options.preventStateUpdateListener) {
44
- triggerEventOnUpdate('stateUpdate', obj, element, options)
44
+ await triggerEventOnUpdate('stateUpdate', obj, element, options)
45
45
  }
46
46
 
47
47
  return state