@domql/state 2.3.129 → 2.3.132

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.
@@ -29,10 +29,10 @@ __export(inherit_exports, {
29
29
  module.exports = __toCommonJS(inherit_exports);
30
30
  var import_utils = require("@domql/utils");
31
31
  var import_ignore = require("./ignore");
32
- const getParentStateInKey = (stateKey2, parentState) => {
33
- if (!stateKey2.includes("../"))
32
+ const getParentStateInKey = (stateKey, parentState) => {
33
+ if (!stateKey.includes("../"))
34
34
  return;
35
- const arr = stateKey2.split("../");
35
+ const arr = stateKey.split("../");
36
36
  const arrLength = arr.length - 1;
37
37
  for (let i = 0; i < arrLength; i++) {
38
38
  if (!parentState.parent)
@@ -41,37 +41,37 @@ const getParentStateInKey = (stateKey2, parentState) => {
41
41
  }
42
42
  return parentState;
43
43
  };
44
- const getChildStateInKey = (stateKey2, parentState, options) => {
45
- const arr = stateKey2.split("/");
44
+ const getChildStateInKey = (stateKey, parentState, options) => {
45
+ const arr = stateKey.split("/");
46
46
  const arrLength = arr.length - 1;
47
47
  for (let i = 0; i < arrLength; i++) {
48
48
  const childKey = arr[i];
49
49
  const grandChildKey = arr[i + 1];
50
50
  const childInParent = parentState[childKey];
51
51
  if (childInParent && childInParent[grandChildKey]) {
52
- stateKey2 = grandChildKey;
52
+ stateKey = grandChildKey;
53
53
  parentState = childInParent;
54
54
  } else
55
55
  return;
56
56
  }
57
57
  if (options.returnParent)
58
58
  return parentState;
59
- return parentState[stateKey2];
59
+ return parentState[stateKey];
60
60
  };
61
61
  const findInheritedState = (element, parent, options = {}) => {
62
62
  const ref = element.__ref;
63
- let stateKey2 = ref.__state;
63
+ let stateKey = ref.__state;
64
64
  if (!checkIfInherits(element))
65
65
  return;
66
66
  let parentState = parent.state;
67
- const findGrandParentState = getParentStateInKey(stateKey2, parent.state);
67
+ const findGrandParentState = getParentStateInKey(stateKey, parent.state);
68
68
  if (findGrandParentState) {
69
69
  parentState = findGrandParentState;
70
- stateKey2 = stateKey2.replaceAll("../", "");
70
+ stateKey = stateKey.replaceAll("../", "");
71
71
  }
72
72
  if (!parentState)
73
73
  return;
74
- return getChildStateInKey(stateKey2, parentState, options);
74
+ return getChildStateInKey(stateKey, parentState, options);
75
75
  };
76
76
  const createInheritedState = (element, parent) => {
77
77
  const ref = element.__ref;
@@ -84,12 +84,12 @@ const createInheritedState = (element, parent) => {
84
84
  ref.__stateType = "string";
85
85
  return { value: inheritedState };
86
86
  }
87
- console.warn(stateKey, "is not present. Replacing with", {});
87
+ console.warn(ref.__state, "is not present. Replacing with", {});
88
88
  };
89
89
  const checkIfInherits = (element) => {
90
90
  const ref = element.__ref;
91
- const stateKey2 = ref.__state;
92
- if (!stateKey2 || (0, import_utils.isNot)(stateKey2)("number", "string"))
91
+ const stateKey = ref.__state;
92
+ if (!stateKey || (0, import_utils.isNot)(stateKey)("number", "string"))
93
93
  return false;
94
94
  return true;
95
95
  };
@@ -104,7 +104,7 @@ const createChangesByKey = (path, value) => {
104
104
  return value || {};
105
105
  }
106
106
  const keys = path.split("/");
107
- let obj = {};
107
+ const obj = {};
108
108
  let ref = obj;
109
109
  keys.forEach((key, index) => {
110
110
  ref[key] = index === keys.length - 1 ? value || {} : {};
@@ -93,7 +93,7 @@ const rootUpdate = function(obj, options = {}) {
93
93
  if (!state)
94
94
  return;
95
95
  const rootState = state.__element.__ref.__root.state;
96
- return rootState.update(obj, options);
96
+ return rootState.update(obj, { isHoisted: false, options });
97
97
  };
98
98
  const add = function(value, options = {}) {
99
99
  const state = this;
@@ -125,6 +125,6 @@ const apply = function(func, options = {}) {
125
125
  const state = this;
126
126
  if ((0, import_utils.isFunction)(func)) {
127
127
  func(state);
128
- return state.update(state, { overwrite: "replace", ...options });
128
+ return state.update(state, { replace: true, ...options });
129
129
  }
130
130
  };
@@ -30,8 +30,9 @@ const STATE_UPDATE_OPTIONS = {
30
30
  overwrite: true,
31
31
  preventHoistElementUpdate: false,
32
32
  updateByState: true,
33
- execStateFunction: false,
34
- stateFunctionOverwrite: "replace"
33
+ execStateFunction: true,
34
+ isHoisted: true,
35
+ stateFunctionOverwrite: true
35
36
  };
36
37
  const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
37
38
  const state = this;
package/inherit.js CHANGED
@@ -58,7 +58,7 @@ export const createInheritedState = (element, parent) => {
58
58
  return { value: inheritedState }
59
59
  }
60
60
 
61
- console.warn(stateKey, 'is not present. Replacing with', {})
61
+ console.warn(ref.__state, 'is not present. Replacing with', {})
62
62
  }
63
63
 
64
64
  export const checkIfInherits = (element) => {
@@ -76,14 +76,14 @@ export const isState = function (state) {
76
76
 
77
77
  export const createChangesByKey = (path, value) => {
78
78
  if (!path) {
79
- return value || {};
79
+ return value || {}
80
80
  }
81
- const keys = path.split('/');
82
- let obj = {};
83
- let ref = obj;
81
+ const keys = path.split('/')
82
+ const obj = {}
83
+ let ref = obj
84
84
  keys.forEach((key, index) => {
85
- ref[key] = index === keys.length - 1 ? value || {} : {};
86
- ref = ref[key];
87
- });
88
- return obj;
85
+ ref[key] = index === keys.length - 1 ? value || {} : {}
86
+ ref = ref[key]
87
+ })
88
+ return obj
89
89
  }
package/methods.js CHANGED
@@ -72,7 +72,7 @@ export const rootUpdate = function (obj, options = {}) {
72
72
  const state = this
73
73
  if (!state) return
74
74
  const rootState = (state.__element.__ref.__root).state
75
- return rootState.update(obj, options)
75
+ return rootState.update(obj, { isHoisted: false, options })
76
76
  }
77
77
 
78
78
  export const add = function (value, options = {}) {
@@ -108,6 +108,6 @@ export const apply = function (func, options = {}) {
108
108
  const state = this
109
109
  if (isFunction(func)) {
110
110
  func(state)
111
- return state.update(state, { overwrite: 'replace', ...options })
111
+ return state.update(state, { replace: true, ...options })
112
112
  }
113
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.3.129",
3
+ "version": "2.3.132",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
@@ -26,5 +26,5 @@
26
26
  "@domql/report": "latest",
27
27
  "@domql/utils": "latest"
28
28
  },
29
- "gitHead": "0e8a2af0c841d2a7f189fdf9968983d2a8566432"
29
+ "gitHead": "2df037bb2c72a090715d27e3368c39c605dac733"
30
30
  }
package/updateState.js CHANGED
@@ -10,8 +10,9 @@ const STATE_UPDATE_OPTIONS = {
10
10
  overwrite: true,
11
11
  preventHoistElementUpdate: false,
12
12
  updateByState: true,
13
- execStateFunction: false,
14
- stateFunctionOverwrite: 'replace'
13
+ execStateFunction: true,
14
+ isHoisted: true,
15
+ stateFunctionOverwrite: true
15
16
  }
16
17
 
17
18
  export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {