@domql/state 2.3.130 → 2.3.137

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 || {} : {};
@@ -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
  };
@@ -37,6 +37,7 @@ const STATE_UPDATE_OPTIONS = {
37
37
  const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
38
38
  const state = this;
39
39
  const element = state.__element;
40
+ console.log(options);
40
41
  if (!options.updateByState)
41
42
  (0, import_utils.merge)(options, STATE_UPDATE_OPTIONS);
42
43
  if (!state.__element)
@@ -101,7 +102,7 @@ const hoistStateUpdate = (state, obj, options) => {
101
102
  preventUpdate: options.preventHoistElementUpdate,
102
103
  overwrite: !options.replace
103
104
  });
104
- const hasNotUpdated = !options.preventUpdate || !options.preventHoistElementUpdate;
105
+ const hasNotUpdated = options.preventUpdate !== true || !options.preventHoistElementUpdate;
105
106
  if (!options.preventStateUpdateListener && hasNotUpdated) {
106
107
  (0, import_event.triggerEventOnUpdate)("stateUpdated", obj, element, options);
107
108
  }
@@ -117,7 +118,8 @@ const updateDependentState = (state, obj, options) => {
117
118
  };
118
119
  const applyElementUpdate = (state, obj, options) => {
119
120
  const element = state.__element;
120
- if (!options.preventUpdate) {
121
+ console.log("update", element.key);
122
+ if (options.preventUpdate !== true) {
121
123
  element.update({}, {
122
124
  ...options,
123
125
  updateByState: true
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
@@ -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.130",
3
+ "version": "2.3.137",
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": "6160195e1279dda74af7a092e863e4bbf397e81e"
29
+ "gitHead": "07ca3db13100667ebe3915db37a18b6e694a3ce3"
30
30
  }
package/updateState.js CHANGED
@@ -18,6 +18,7 @@ const STATE_UPDATE_OPTIONS = {
18
18
  export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {
19
19
  const state = this
20
20
  const element = state.__element
21
+ console.log(options)
21
22
 
22
23
  if (!options.updateByState) merge(options, STATE_UPDATE_OPTIONS)
23
24
 
@@ -32,7 +33,6 @@ export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {
32
33
  }
33
34
 
34
35
  applyOverwrite(state, obj, options)
35
-
36
36
  const updateIsHoisted = hoistStateUpdate(state, obj, options)
37
37
  if (updateIsHoisted) return state
38
38
 
@@ -90,7 +90,7 @@ const hoistStateUpdate = (state, obj, options) => {
90
90
  preventUpdate: options.preventHoistElementUpdate,
91
91
  overwrite: !options.replace
92
92
  })
93
- const hasNotUpdated = !options.preventUpdate || !options.preventHoistElementUpdate
93
+ const hasNotUpdated = options.preventUpdate !== true || !options.preventHoistElementUpdate
94
94
  if (!options.preventStateUpdateListener && hasNotUpdated) {
95
95
  triggerEventOnUpdate('stateUpdated', obj, element, options)
96
96
  }
@@ -107,7 +107,8 @@ const updateDependentState = (state, obj, options) => {
107
107
 
108
108
  const applyElementUpdate = (state, obj, options) => {
109
109
  const element = state.__element
110
- if (!options.preventUpdate) {
110
+ console.log('update', element.key)
111
+ if (options.preventUpdate !== true) {
111
112
  element.update({}, {
112
113
  ...options,
113
114
  updateByState: true