@domql/state 2.5.122 → 2.5.133

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/create.js CHANGED
@@ -19,7 +19,9 @@ import {
19
19
  replace,
20
20
  quietUpdate,
21
21
  quietReplace,
22
- applyReplace
22
+ applyReplace,
23
+ keys,
24
+ values
23
25
  } from './methods'
24
26
  import { updateState } from './updateState'
25
27
  import { checkIfInherits, createInheritedState } from './inherit'
@@ -32,7 +34,7 @@ export const createState = function (element, parent, options) {
32
34
  export const applyInitialState = function (element, parent, options) {
33
35
  const objectizeState = checkForTypes(element)
34
36
  if (objectizeState === false) return parent.state || {}
35
- else element.state = deepCloneWithExtend(objectizeState, IGNORE_STATE_PARAMS)
37
+ else element.state = objectizeState
36
38
 
37
39
  const whatInitReturns = triggerEventOn('stateInit', element, options)
38
40
  if (whatInitReturns === false) return element.state
@@ -54,14 +56,22 @@ export const applyInitialState = function (element, parent, options) {
54
56
  }
55
57
 
56
58
  const applyDependentState = (element, state) => {
57
- const { __ref: ref } = state
58
- if (!ref) return
59
- const dependentState = deepCloneWithExtend(ref, IGNORE_STATE_PARAMS)
59
+ const { __ref, ref, __element } = state //
60
+ const origState = exec(__ref || ref || __element?.state, element)
61
+ if (!origState) return
62
+ const dependentState = deepCloneWithExtend(origState, IGNORE_STATE_PARAMS)
60
63
  const newDepends = { [element.key]: dependentState }
61
- ref.__depends = isObject(ref.__depends)
62
- ? { ...ref.__depends, ...newDepends }
64
+
65
+ const __depends = isObject(origState.__depends)
66
+ ? { ...origState.__depends, ...newDepends }
63
67
  : newDepends
64
68
 
69
+ if (Array.isArray(origState)) {
70
+ addProtoToArray(origState, { ...Object.getPrototypeOf(origState), __depends })
71
+ } else {
72
+ Object.setPrototypeOf(origState, { ...Object.getPrototypeOf(origState), __depends })
73
+ }
74
+
65
75
  return dependentState
66
76
  }
67
77
 
@@ -119,6 +129,8 @@ const applyMethods = (element) => {
119
129
  quietReplace: quietReplace.bind(state),
120
130
  reset: reset.bind(state),
121
131
  parent: element.parent.state || state,
132
+ keys: keys.bind(state),
133
+ values: values.bind(state),
122
134
  __element: element,
123
135
  __children: {},
124
136
  root: ref.root ? ref.root.state : state
@@ -37,7 +37,7 @@ const applyInitialState = function(element, parent, options) {
37
37
  if (objectizeState === false)
38
38
  return parent.state || {};
39
39
  else
40
- element.state = (0, import_utils.deepCloneWithExtend)(objectizeState, import_ignore.IGNORE_STATE_PARAMS);
40
+ element.state = objectizeState;
41
41
  const whatInitReturns = (0, import_event.triggerEventOn)("stateInit", element, options);
42
42
  if (whatInitReturns === false)
43
43
  return element.state;
@@ -53,12 +53,18 @@ const applyInitialState = function(element, parent, options) {
53
53
  return element.state;
54
54
  };
55
55
  const applyDependentState = (element, state) => {
56
- const { __ref: ref } = state;
57
- if (!ref)
56
+ const { __ref, ref, __element } = state;
57
+ const origState = (0, import_utils.exec)(__ref || ref || (__element == null ? void 0 : __element.state), element);
58
+ if (!origState)
58
59
  return;
59
- const dependentState = (0, import_utils.deepCloneWithExtend)(ref, import_ignore.IGNORE_STATE_PARAMS);
60
+ const dependentState = (0, import_utils.deepCloneWithExtend)(origState, import_ignore.IGNORE_STATE_PARAMS);
60
61
  const newDepends = { [element.key]: dependentState };
61
- ref.__depends = (0, import_utils.isObject)(ref.__depends) ? { ...ref.__depends, ...newDepends } : newDepends;
62
+ const __depends = (0, import_utils.isObject)(origState.__depends) ? { ...origState.__depends, ...newDepends } : newDepends;
63
+ if (Array.isArray(origState)) {
64
+ addProtoToArray(origState, { ...Object.getPrototypeOf(origState), __depends });
65
+ } else {
66
+ Object.setPrototypeOf(origState, { ...Object.getPrototypeOf(origState), __depends });
67
+ }
62
68
  return dependentState;
63
69
  };
64
70
  const checkForTypes = (element) => {
@@ -115,6 +121,8 @@ const applyMethods = (element) => {
115
121
  quietReplace: import_methods.quietReplace.bind(state),
116
122
  reset: import_methods.reset.bind(state),
117
123
  parent: element.parent.state || state,
124
+ keys: import_methods.keys.bind(state),
125
+ values: import_methods.values.bind(state),
118
126
  __element: element,
119
127
  __children: {},
120
128
  root: ref.root ? ref.root.state : state
@@ -38,6 +38,8 @@ const IGNORE_STATE_PARAMS = [
38
38
  "quietUpdate",
39
39
  "applyReplace",
40
40
  "applyFunction",
41
+ "keys",
42
+ "values",
41
43
  "rootUpdate",
42
44
  "parentUpdate",
43
45
  "parent",
@@ -113,7 +113,7 @@ const checkIfInherits = (element) => {
113
113
  const isState = function(state) {
114
114
  if (!(0, import_utils.isObjectLike)(state))
115
115
  return false;
116
- return state.update && state.parse && state.clean && state.create && state.parent && state.destroy && state.rootUpdate && state.parentUpdate && state.toggle && state.replace && state.quietUpdate && state.quietReplace && state.add && state.apply && state.applyReplace && state.applyFunction && state.__element && state.__children;
116
+ return state.update && state.parse && state.clean && state.create && state.parent && state.destroy && state.rootUpdate && state.parentUpdate && state.keys && state.values && state.toggle && state.replace && state.quietUpdate && state.quietReplace && state.add && state.apply && state.applyReplace && state.applyFunction && state.__element && state.__children;
117
117
  };
118
118
  const createNestedObjectByKeyPath = (path, value) => {
119
119
  if (!path) {
@@ -24,6 +24,7 @@ __export(methods_exports, {
24
24
  applyReplace: () => applyReplace,
25
25
  clean: () => clean,
26
26
  destroy: () => destroy,
27
+ keys: () => keys,
27
28
  parentUpdate: () => parentUpdate,
28
29
  parse: () => parse,
29
30
  quietReplace: () => quietReplace,
@@ -33,7 +34,8 @@ __export(methods_exports, {
33
34
  reset: () => reset,
34
35
  rootUpdate: () => rootUpdate,
35
36
  set: () => set,
36
- toggle: () => toggle
37
+ toggle: () => toggle,
38
+ values: () => values
37
39
  });
38
40
  module.exports = __toCommonJS(methods_exports);
39
41
  var import_utils = require("@domql/utils");
@@ -178,3 +180,11 @@ const quietReplace = function(obj, options = {}) {
178
180
  const state = this;
179
181
  return state.replace(obj, { preventUpdate: true, ...options });
180
182
  };
183
+ const keys = function(obj, options = {}) {
184
+ const state = this;
185
+ return Object.keys(state);
186
+ };
187
+ const values = function(obj, options = {}) {
188
+ const state = this;
189
+ return Object.values(state);
190
+ };
package/ignore.js CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  export const IGNORE_STATE_PARAMS = [
4
4
  'update', 'parse', 'clean', 'create', 'destroy', 'add', 'toggle', 'remove', 'apply', 'set', 'reset',
5
- 'replace', 'quietReplace', 'quietUpdate', 'applyReplace', 'applyFunction',
5
+ 'replace', 'quietReplace', 'quietUpdate', 'applyReplace', 'applyFunction', 'keys', 'values',
6
6
  'rootUpdate', 'parentUpdate', 'parent', '__element', '__depends', '__ref', '__children', 'root'
7
7
  ]
package/inherit.js CHANGED
@@ -96,6 +96,8 @@ export const isState = function (state) {
96
96
  state.destroy &&
97
97
  state.rootUpdate &&
98
98
  state.parentUpdate &&
99
+ state.keys &&
100
+ state.values &&
99
101
  state.toggle &&
100
102
  state.replace &&
101
103
  state.quietUpdate &&
package/methods.js CHANGED
@@ -164,3 +164,13 @@ export const quietReplace = function (obj, options = {}) {
164
164
  const state = this
165
165
  return state.replace(obj, { preventUpdate: true, ...options })
166
166
  }
167
+
168
+ export const keys = function (obj, options = {}) {
169
+ const state = this
170
+ return Object.keys(state)
171
+ }
172
+
173
+ export const values = function (obj, options = {}) {
174
+ const state = this
175
+ return Object.values(state)
176
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.5.122",
3
+ "version": "2.5.133",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "dist/esm/index.js",
@@ -31,5 +31,5 @@
31
31
  "@domql/report": "latest",
32
32
  "@domql/utils": "latest"
33
33
  },
34
- "gitHead": "2f048372ece4d808cfaca8e43491611dafe3ad5f"
34
+ "gitHead": "3c861b5f3e4974ecc985ec24fc8666d0fec6a7fb"
35
35
  }