@domql/state 2.5.26 → 2.5.28

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
@@ -3,7 +3,7 @@
3
3
  import { triggerEventOn } from '@domql/event'
4
4
  import { deepClone, exec, is, isArray, isFunction, isObject, isUndefined } from '@domql/utils'
5
5
  import { IGNORE_STATE_PARAMS } from './ignore'
6
- import { add, apply, clean, destroy, parentUpdate, parse, remove, rootUpdate, set, toggle } from './methods'
6
+ import { add, apply, clean, destroy, parentUpdate, parse, remove, rootUpdate, set, reset, toggle } from './methods'
7
7
  import { updateState } from './updateState'
8
8
  import { checkIfInherits, createInheritedState } from './inherit'
9
9
 
@@ -95,6 +95,7 @@ const applyMethods = (element) => {
95
95
  remove: remove.bind(state),
96
96
  apply: apply.bind(state),
97
97
  set: set.bind(state),
98
+ reset: reset.bind(state),
98
99
  parent: element.parent.state,
99
100
  __element: element,
100
101
  __children: {},
@@ -108,6 +108,7 @@ const applyMethods = (element) => {
108
108
  remove: import_methods.remove.bind(state),
109
109
  apply: import_methods.apply.bind(state),
110
110
  set: import_methods.set.bind(state),
111
+ reset: import_methods.reset.bind(state),
111
112
  parent: element.parent.state,
112
113
  __element: element,
113
114
  __children: {},
@@ -32,6 +32,7 @@ const IGNORE_STATE_PARAMS = [
32
32
  "remove",
33
33
  "apply",
34
34
  "set",
35
+ "reset",
35
36
  "rootUpdate",
36
37
  "parentUpdate",
37
38
  "parent",
@@ -55,7 +55,7 @@ const clean = function(options = {}) {
55
55
  }
56
56
  }
57
57
  if (!options.preventStateUpdate) {
58
- state.update(state, { replace: true, options });
58
+ state.update(state, { replace: true, ...options });
59
59
  }
60
60
  return state;
61
61
  };
@@ -130,13 +130,15 @@ const remove = function(key, options = {}) {
130
130
  (0, import_utils.removeFromObject)(state, key);
131
131
  return state.update(state.parse(), { replace: true, ...options });
132
132
  };
133
- const set = function(value, options = {}) {
133
+ const set = function(val, options = {}) {
134
134
  const state = this;
135
- return state.clean({ preventStateUpdate: true }).update(value, { replace: true, ...options });
135
+ const value = (0, import_utils.deepClone)(val);
136
+ return state.clean({ preventStateUpdate: true, ...options }).update(value, { replace: true, ...options });
136
137
  };
137
138
  const reset = function(options = {}) {
138
139
  const state = this;
139
- return state.set(state.parse(), { replace: true, ...options });
140
+ const value = (0, import_utils.deepClone)(state.parse());
141
+ return state.set(value, { replace: true, ...options });
140
142
  };
141
143
  const apply = function(func, options = {}) {
142
144
  const state = this;
@@ -92,7 +92,8 @@ const hoistStateUpdate = (state, obj, options) => {
92
92
  const changesValue = (0, import_inherit.createChangesByKey)(stateKey, passedValue);
93
93
  const targetParent = findGrandParentState || parent.state;
94
94
  if (options.replace)
95
- targetParent[stateKey] = value;
95
+ (0, import_utils.overwriteDeep)(targetParent, changesValue || value);
96
+ console.log(changesValue);
96
97
  targetParent.update(changesValue, {
97
98
  execStateFunction: false,
98
99
  isHoisted: true,
package/ignore.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
3
  export const IGNORE_STATE_PARAMS = [
4
- 'update', 'parse', 'clean', 'create', 'destroy', 'add', 'toggle', 'remove', 'apply', 'set',
4
+ 'update', 'parse', 'clean', 'create', 'destroy', 'add', 'toggle', 'remove', 'apply', 'set', 'reset',
5
5
  'rootUpdate', 'parentUpdate', 'parent', '__element', '__depends', '__ref', '__children', '__root'
6
6
  ]
package/methods.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { isArray, isFunction, isObject, isString, removeFromArray, removeFromObject } from '@domql/utils'
3
+ import { isArray, deepClone, isFunction, isObject, isString, removeFromArray, removeFromObject } from '@domql/utils'
4
4
 
5
5
  import { IGNORE_STATE_PARAMS } from './ignore'
6
6
 
@@ -27,7 +27,7 @@ export const clean = function (options = {}) {
27
27
  }
28
28
  }
29
29
  if (!options.preventStateUpdate) {
30
- state.update(state, { replace: true, options })
30
+ state.update(state, { replace: true, ...options })
31
31
  }
32
32
  return state
33
33
  }
@@ -107,15 +107,17 @@ export const remove = function (key, options = {}) {
107
107
  return state.update(state.parse(), { replace: true, ...options })
108
108
  }
109
109
 
110
- export const set = function (value, options = {}) {
110
+ export const set = function (val, options = {}) {
111
111
  const state = this
112
- return state.clean({ preventStateUpdate: true })
112
+ const value = deepClone(val)
113
+ return state.clean({ preventStateUpdate: true, ...options })
113
114
  .update(value, { replace: true, ...options })
114
115
  }
115
116
 
116
117
  export const reset = function (options = {}) {
117
118
  const state = this
118
- return state.set(state.parse(), { replace: true, ...options })
119
+ const value = deepClone(state.parse())
120
+ return state.set(value, { replace: true, ...options })
119
121
  }
120
122
 
121
123
  export const apply = function (func, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.5.26",
3
+ "version": "2.5.28",
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": "b17ccc2c09f672ace1ec3b681a82cce26bfce3dd"
34
+ "gitHead": "aaf2a65754d4611a18442f9da3b741cb70faf7d1"
35
35
  }
package/updateState.js CHANGED
@@ -80,7 +80,8 @@ const hoistStateUpdate = (state, obj, options) => {
80
80
  const findGrandParentState = getParentStateInKey(stateKey, parent.state)
81
81
  const changesValue = createChangesByKey(stateKey, passedValue)
82
82
  const targetParent = findGrandParentState || parent.state
83
- if (options.replace) targetParent[stateKey] = value
83
+ if (options.replace) overwriteDeep(targetParent, changesValue || value) // check with createChangesByKey
84
+ console.log(changesValue)
84
85
  targetParent.update(changesValue, {
85
86
  execStateFunction: false,
86
87
  isHoisted: true,