@domql/state 2.5.86 → 2.5.90

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
@@ -6,6 +6,7 @@ import { IGNORE_STATE_PARAMS } from './ignore'
6
6
  import {
7
7
  add,
8
8
  apply,
9
+ applyFunction,
9
10
  clean,
10
11
  destroy,
11
12
  parentUpdate,
@@ -17,7 +18,8 @@ import {
17
18
  toggle,
18
19
  replace,
19
20
  quietUpdate,
20
- quietReplace
21
+ quietReplace,
22
+ applyReplace
21
23
  } from './methods'
22
24
  import { updateState } from './updateState'
23
25
  import { checkIfInherits, createInheritedState } from './inherit'
@@ -109,6 +111,8 @@ const applyMethods = (element) => {
109
111
  toggle: toggle.bind(state),
110
112
  remove: remove.bind(state),
111
113
  apply: apply.bind(state),
114
+ applyReplace: applyReplace.bind(state),
115
+ applyFunction: applyFunction.bind(state),
112
116
  set: set.bind(state),
113
117
  quietUpdate: quietUpdate.bind(state),
114
118
  replace: replace.bind(state),
@@ -107,6 +107,8 @@ const applyMethods = (element) => {
107
107
  toggle: import_methods.toggle.bind(state),
108
108
  remove: import_methods.remove.bind(state),
109
109
  apply: import_methods.apply.bind(state),
110
+ applyReplace: import_methods.applyReplace.bind(state),
111
+ applyFunction: import_methods.applyFunction.bind(state),
110
112
  set: import_methods.set.bind(state),
111
113
  quietUpdate: import_methods.quietUpdate.bind(state),
112
114
  replace: import_methods.replace.bind(state),
@@ -36,6 +36,8 @@ const IGNORE_STATE_PARAMS = [
36
36
  "replace",
37
37
  "quietReplace",
38
38
  "quietUpdate",
39
+ "applyReplace",
40
+ "applyFunction",
39
41
  "rootUpdate",
40
42
  "parentUpdate",
41
43
  "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.__element && state.__children;
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;
117
117
  };
118
118
  const createNestedObjectByKeyPath = (path, value) => {
119
119
  if (!path) {
@@ -20,6 +20,8 @@ var methods_exports = {};
20
20
  __export(methods_exports, {
21
21
  add: () => add,
22
22
  apply: () => apply,
23
+ applyFunction: () => applyFunction,
24
+ applyReplace: () => applyReplace,
23
25
  clean: () => clean,
24
26
  destroy: () => destroy,
25
27
  parentUpdate: () => parentUpdate,
@@ -141,6 +143,20 @@ const reset = function(options = {}) {
141
143
  return state.set(value, { replace: true, ...options });
142
144
  };
143
145
  const apply = function(func, options = {}) {
146
+ const state = this;
147
+ if ((0, import_utils.isFunction)(func)) {
148
+ const value = func(state);
149
+ return state.update(value, { replace: true, ...options });
150
+ }
151
+ };
152
+ const applyReplace = function(func, options = {}) {
153
+ const state = this;
154
+ if ((0, import_utils.isFunction)(func)) {
155
+ const value = func(state);
156
+ return state.replace(value, options);
157
+ }
158
+ };
159
+ const applyFunction = function(func, options = {}) {
144
160
  const state = this;
145
161
  if ((0, import_utils.isFunction)(func)) {
146
162
  func(state);
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',
5
+ 'replace', 'quietReplace', 'quietUpdate', 'applyReplace', 'applyFunction',
6
6
  'rootUpdate', 'parentUpdate', 'parent', '__element', '__depends', '__ref', '__children', 'root'
7
7
  ]
package/inherit.js CHANGED
@@ -102,6 +102,8 @@ export const isState = function (state) {
102
102
  state.quietReplace &&
103
103
  state.add &&
104
104
  state.apply &&
105
+ state.applyReplace &&
106
+ state.applyFunction &&
105
107
  state.__element &&
106
108
  state.__children
107
109
  // return arrayContainsOtherArray(keys, ['update', 'parse', 'clean', 'create', 'parent', 'rootUpdate'])
package/methods.js CHANGED
@@ -122,6 +122,22 @@ export const reset = function (options = {}) {
122
122
  }
123
123
 
124
124
  export const apply = function (func, options = {}) {
125
+ const state = this
126
+ if (isFunction(func)) {
127
+ const value = func(state)
128
+ return state.update(value, { replace: true, ...options })
129
+ }
130
+ }
131
+
132
+ export const applyReplace = function (func, options = {}) {
133
+ const state = this
134
+ if (isFunction(func)) {
135
+ const value = func(state)
136
+ return state.replace(value, options)
137
+ }
138
+ }
139
+
140
+ export const applyFunction = function (func, options = {}) {
125
141
  const state = this
126
142
  if (isFunction(func)) {
127
143
  func(state)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.5.86",
3
+ "version": "2.5.90",
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": "6a593e77a9cdf6889175bf674ef60f90385b58df"
34
+ "gitHead": "01113bfc2fb3bc1f4fc3b694a45cb397ee65ae68"
35
35
  }