@domql/state 2.3.123 → 2.3.125

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/createState.js CHANGED
@@ -3,7 +3,7 @@
3
3
  import { triggerEventOn } from '@domql/event'
4
4
  import { deepClone, exec, is, isFunction, isObject } from '@domql/utils'
5
5
  import { IGNORE_STATE_PARAMS } from './ignore'
6
- import { add, apply, clean, destroy, parse, remove, rootUpdate, toggle } from './methods'
6
+ import { add, apply, clean, destroy, parse, remove, rootUpdate, set, toggle } from './methods'
7
7
  import { updateState } from './updateState'
8
8
  import { checkIfInherits, createInheritedState } from './inherit'
9
9
 
@@ -84,6 +84,7 @@ const applyMethods = (element) => {
84
84
  state.remove = remove
85
85
  state.apply = apply
86
86
  state.parent = element.parent.state
87
+ state.set = set
87
88
  state.__element = element
88
89
  state.__children = {}
89
90
  state.__root = ref.__root ? ref.__root.state : state
@@ -93,6 +93,7 @@ const applyMethods = (element) => {
93
93
  state.remove = import_methods.remove;
94
94
  state.apply = import_methods.apply;
95
95
  state.parent = element.parent.state;
96
+ state.set = import_methods.set;
96
97
  state.__element = element;
97
98
  state.__children = {};
98
99
  state.__root = ref.__root ? ref.__root.state : state;
@@ -31,6 +31,7 @@ const IGNORE_STATE_PARAMS = [
31
31
  "toggle",
32
32
  "remove",
33
33
  "apply",
34
+ "set",
34
35
  "rootUpdate",
35
36
  "parent",
36
37
  "__element",
@@ -25,6 +25,7 @@ __export(methods_exports, {
25
25
  parse: () => parse,
26
26
  remove: () => remove,
27
27
  rootUpdate: () => rootUpdate,
28
+ set: () => set,
28
29
  toggle: () => toggle
29
30
  });
30
31
  module.exports = __toCommonJS(methods_exports);
@@ -51,7 +52,9 @@ const clean = function(options = {}) {
51
52
  delete state[param];
52
53
  }
53
54
  }
54
- state.update(state, { skipOverwrite: true, options });
55
+ if (!options.preventStateUpdate) {
56
+ state.update(state, { replace: true, skipOverwrite: true, options });
57
+ }
55
58
  return state;
56
59
  };
57
60
  const destroy = function() {
@@ -77,6 +80,7 @@ const rootUpdate = function(obj, options = {}) {
77
80
  const state = this;
78
81
  if (!state)
79
82
  return;
83
+ console.log(options);
80
84
  const rootState = state.__element.__ref.__root.state;
81
85
  return rootState.update(obj, options);
82
86
  };
@@ -96,12 +100,18 @@ const toggle = function(key, options = {}) {
96
100
  };
97
101
  const remove = function(key, options = {}) {
98
102
  const state = this;
103
+ console.log(state);
99
104
  if ((0, import_utils.isArray)(state))
100
105
  (0, import_utils.removeFromArray)(state, key);
101
106
  if ((0, import_utils.isObject)(state))
102
107
  (0, import_utils.removeFromObject)(state, key);
103
108
  return state.update(state.parse(), { replace: true, ...options });
104
109
  };
110
+ const set = function(value, options = {}) {
111
+ const state = this;
112
+ state.clean({ preventStateUpdate: true });
113
+ return state.update(value, { replace: true, ...options });
114
+ };
105
115
  const apply = function(func, options = {}) {
106
116
  const state = this;
107
117
  if ((0, import_utils.isFunction)(func)) {
@@ -27,20 +27,27 @@ var import_ignore = require("./ignore");
27
27
  var import_utils = require("@domql/utils");
28
28
  var import_inherit = require("./inherit");
29
29
  const STATE_UPDATE_OPTIONS = {
30
- preventHoistElementUpdate: true
30
+ preventHoistElementUpdate: false,
31
+ updateByState: true
31
32
  };
32
33
  const updateState = function(obj, options = STATE_UPDATE_OPTIONS) {
33
34
  const state = this;
34
35
  const element = state.__element;
35
36
  if (!state.__element)
36
37
  (0, import_report.report)("ElementOnStateIsNotDefined");
38
+ if (options.preventInheritAtCurrentState === true) {
39
+ options.preventInheritAtCurrentState = state;
40
+ } else if (options.preventInheritAtCurrentState)
41
+ return;
37
42
  if (!options.preventInitStateUpdateListener) {
38
43
  const initStateUpdateReturns = (0, import_event.triggerEventOn)("initStateUpdated", element, obj);
39
44
  if (initStateUpdateReturns === false)
40
45
  return element;
41
46
  }
42
47
  applyOverwrite(state, obj, options);
43
- hoistStateUpdate(state, obj, options);
48
+ const updateIsHousted = hoistStateUpdate(state, obj, options);
49
+ if (updateIsHousted)
50
+ return state;
44
51
  updateDependentState(state, obj, options);
45
52
  applyElementUpdate(state, obj, options);
46
53
  if (!options.preventStateUpdateListener) {
@@ -83,6 +90,7 @@ const hoistStateUpdate = (state, obj, options) => {
83
90
  preventUpdate: options.preventHoistElementUpdate,
84
91
  skipOverwrite: options.replace
85
92
  });
93
+ return true;
86
94
  };
87
95
  const updateDependentState = (state, obj, options) => {
88
96
  if (!state.__depends)
@@ -97,13 +105,11 @@ const applyElementUpdate = (state, obj, options) => {
97
105
  if (!options.preventUpdate) {
98
106
  element.update({}, {
99
107
  ...options,
100
- updateByState: true,
101
- preventUpdateTriggerStateUpdate: true
108
+ updateByState: true
102
109
  });
103
110
  } else if (options.preventUpdate === "recursive") {
104
111
  element.update({}, {
105
112
  ...options,
106
- preventUpdateTriggerStateUpdate: true,
107
113
  updateByState: true,
108
114
  preventUpdate: true
109
115
  });
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',
4
+ 'update', 'parse', 'clean', 'create', 'destroy', 'add', 'toggle', 'remove', 'apply', 'set',
5
5
  'rootUpdate', 'parent', '__element', '__depends', '__ref', '__children', '__root'
6
6
  ]
package/methods.js CHANGED
@@ -26,7 +26,9 @@ export const clean = function (options = {}) {
26
26
  delete state[param]
27
27
  }
28
28
  }
29
- state.update(state, { skipOverwrite: true, options })
29
+ if (!options.preventStateUpdate) {
30
+ state.update(state, { replace: true, skipOverwrite: true, options })
31
+ }
30
32
  return state
31
33
  }
32
34
 
@@ -56,6 +58,7 @@ export const destroy = function () {
56
58
  export const rootUpdate = function (obj, options = {}) {
57
59
  const state = this
58
60
  if (!state) return
61
+ console.log(options)
59
62
  const rootState = (state.__element.__ref.__root).state
60
63
  return rootState.update(obj, options)
61
64
  }
@@ -65,8 +68,7 @@ export const add = function (value, options = {}) {
65
68
  if (isArray(state)) {
66
69
  state.push(value)
67
70
  state.update(state.parse(), { replace: true, ...options })
68
- }
69
- else if (isObject(state)) {
71
+ } else if (isObject(state)) {
70
72
  const key = Object.keys(state).length
71
73
  state.update({ [key]: value }, options)
72
74
  }
@@ -79,11 +81,18 @@ export const toggle = function (key, options = {}) {
79
81
 
80
82
  export const remove = function (key, options = {}) {
81
83
  const state = this
84
+ console.log(state)
82
85
  if (isArray(state)) removeFromArray(state, key)
83
86
  if (isObject(state)) removeFromObject(state, key)
84
87
  return state.update(state.parse(), { replace: true, ...options })
85
88
  }
86
89
 
90
+ export const set = function (value, options = {}) {
91
+ const state = this
92
+ state.clean({ preventStateUpdate: true })
93
+ return state.update(value, { replace: true, ...options })
94
+ }
95
+
87
96
  export const apply = function (func, options = {}) {
88
97
  const state = this
89
98
  if (isFunction(func)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.3.123",
3
+ "version": "2.3.125",
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": "feb0d24eb5924f0f9ebea660a93afffc7d6a2059"
29
+ "gitHead": "c62e01157f488334d07a8bbd67f892d617d48f06"
30
30
  }
package/updateState.js CHANGED
@@ -7,7 +7,8 @@ import { deepMerge, overwriteDeep, overwriteShallow } from '@domql/utils'
7
7
  import { checkIfInherits, createChangesByKey, findInheritedState, getParentStateInKey } from './inherit'
8
8
 
9
9
  const STATE_UPDATE_OPTIONS = {
10
- preventHoistElementUpdate: true
10
+ preventHoistElementUpdate: false,
11
+ updateByState: true
11
12
  }
12
13
 
13
14
  export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {
@@ -15,6 +16,9 @@ export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {
15
16
  const element = state.__element
16
17
 
17
18
  if (!state.__element) report('ElementOnStateIsNotDefined')
19
+ if (options.preventInheritAtCurrentState === true) {
20
+ options.preventInheritAtCurrentState = state
21
+ } else if (options.preventInheritAtCurrentState) return
18
22
 
19
23
  if (!options.preventInitStateUpdateListener) {
20
24
  const initStateUpdateReturns = triggerEventOn('initStateUpdated', element, obj)
@@ -23,7 +27,8 @@ export const updateState = function (obj, options = STATE_UPDATE_OPTIONS) {
23
27
 
24
28
  applyOverwrite(state, obj, options)
25
29
 
26
- hoistStateUpdate(state, obj, options)
30
+ const updateIsHousted = hoistStateUpdate(state, obj, options)
31
+ if (updateIsHousted) return state
27
32
 
28
33
  updateDependentState(state, obj, options)
29
34
 
@@ -44,6 +49,11 @@ const applyOverwrite = (state, obj, options) => {
44
49
  return
45
50
  }
46
51
 
52
+ // if (skipOverwrite === 'skipOverwrite') {
53
+ // deepMerge(state, obj, IGNORE_STATE_PARAMS)
54
+ // return
55
+ // }
56
+
47
57
  if (!skipOverwrite) {
48
58
  const overwriteFunc = shallow ? overwriteShallow : overwriteDeep
49
59
  overwriteFunc(state, obj, IGNORE_STATE_PARAMS)
@@ -74,6 +84,7 @@ const hoistStateUpdate = (state, obj, options) => {
74
84
  preventUpdate: options.preventHoistElementUpdate,
75
85
  skipOverwrite: options.replace
76
86
  })
87
+ return true
77
88
  }
78
89
 
79
90
  const updateDependentState = (state, obj, options) => {
@@ -89,13 +100,11 @@ const applyElementUpdate = (state, obj, options) => {
89
100
  if (!options.preventUpdate) {
90
101
  element.update({}, {
91
102
  ...options,
92
- updateByState: true,
93
- preventUpdateTriggerStateUpdate: true
103
+ updateByState: true
94
104
  })
95
105
  } else if (options.preventUpdate === 'recursive') {
96
106
  element.update({}, {
97
107
  ...options,
98
- preventUpdateTriggerStateUpdate: true,
99
108
  updateByState: true,
100
109
  preventUpdate: true
101
110
  })