@domql/state 2.5.15 → 2.5.16

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
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { triggerEventOn } from '@domql/event'
4
- import { deepClone, exec, is, isArray, isFunction, isObject } from '@domql/utils'
4
+ import { deepClone, exec, is, isArray, isFunction, isObject, isUndefined } from '@domql/utils'
5
5
  import { IGNORE_STATE_PARAMS } from './ignore'
6
6
  import { add, apply, clean, destroy, parentUpdate, parse, remove, rootUpdate, set, toggle } from './methods'
7
7
  import { updateState } from './updateState'
@@ -22,7 +22,7 @@ export const applyInitialState = function (element, parent, options) {
22
22
 
23
23
  if (checkIfInherits(element)) {
24
24
  const inheritedState = createInheritedState(element, parent)
25
- element.state = inheritedState || {}
25
+ element.state = isUndefined(inheritedState) ? {} : inheritedState
26
26
  }
27
27
 
28
28
  const dependentState = applyDependentState(element, element.state)
@@ -62,7 +62,7 @@ const checkForTypes = (element) => {
62
62
  } else if (state) {
63
63
  ref.__hasRootState = true
64
64
  return state
65
- } else {
65
+ } else {
66
66
  return false
67
67
  }
68
68
  }
@@ -43,7 +43,7 @@ const applyInitialState = function(element, parent, options) {
43
43
  return element.state;
44
44
  if ((0, import_inherit.checkIfInherits)(element)) {
45
45
  const inheritedState = (0, import_inherit.createInheritedState)(element, parent);
46
- element.state = inheritedState || {};
46
+ element.state = (0, import_utils.isUndefined)(inheritedState) ? {} : inheritedState;
47
47
  }
48
48
  const dependentState = applyDependentState(element, element.state);
49
49
  if (dependentState)
@@ -79,12 +79,12 @@ const findInheritedState = (element, parent, options = {}) => {
79
79
  const createInheritedState = (element, parent) => {
80
80
  const ref = element.__ref;
81
81
  const inheritedState = findInheritedState(element, parent);
82
- if (!inheritedState)
82
+ if ((0, import_utils.isUndefined)(inheritedState))
83
83
  return element.state;
84
84
  if ((0, import_utils.is)(inheritedState)("object", "array")) {
85
85
  return (0, import_utils.deepClone)(inheritedState, import_ignore.IGNORE_STATE_PARAMS);
86
- } else if ((0, import_utils.is)(inheritedState)("string", "number")) {
87
- ref.__stateType = "string";
86
+ } else if ((0, import_utils.is)(inheritedState)("string", "number", "boolean")) {
87
+ ref.__stateType = typeof inheritedState;
88
88
  return { value: inheritedState };
89
89
  }
90
90
  console.warn(ref.__state, "is not present. Replacing with", {});
@@ -92,9 +92,9 @@ const createInheritedState = (element, parent) => {
92
92
  const checkIfInherits = (element) => {
93
93
  const ref = element.__ref;
94
94
  const stateKey = ref.__state;
95
- if (!stateKey || (0, import_utils.isNot)(stateKey)("number", "string"))
96
- return false;
97
- return true;
95
+ if (stateKey && (0, import_utils.is)(stateKey)("number", "string", "boolean"))
96
+ return true;
97
+ return false;
98
98
  };
99
99
  const isState = function(state) {
100
100
  if (!(0, import_utils.isObjectLike)(state))
@@ -78,6 +78,7 @@ const hoistStateUpdate = (state, obj, options) => {
78
78
  const element = state.__element;
79
79
  const { parent, __ref: ref } = element;
80
80
  const stateKey = ref.__state;
81
+ const stateType = ref.__stateType;
81
82
  if (!stateKey)
82
83
  return;
83
84
  const asksForInherit = (0, import_inherit.checkIfInherits)(element);
@@ -85,7 +86,7 @@ const hoistStateUpdate = (state, obj, options) => {
85
86
  const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation;
86
87
  if (!shouldPropagateState)
87
88
  return;
88
- const isStringState = ref.__stateType === "string";
89
+ const isStringState = stateType === "string" || stateType === "number" || stateType === "boolean";
89
90
  const value = isStringState ? state.value : state.parse();
90
91
  const passedValue = isStringState ? state.value : obj;
91
92
  const findGrandParentState = (0, import_inherit.getParentStateInKey)(stateKey, parent.state);
package/inherit.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { deepClone, is, isNot, isObjectLike } from '@domql/utils'
3
+ import { deepClone, is, isObjectLike, isUndefined } from '@domql/utils'
4
4
  import { IGNORE_STATE_PARAMS } from './ignore'
5
5
 
6
6
  export const getParentStateInKey = (stateKey, parentState) => {
@@ -53,12 +53,12 @@ export const findInheritedState = (element, parent, options = {}) => {
53
53
  export const createInheritedState = (element, parent) => {
54
54
  const ref = element.__ref
55
55
  const inheritedState = findInheritedState(element, parent)
56
- if (!inheritedState) return element.state
56
+ if (isUndefined(inheritedState)) return element.state
57
57
 
58
58
  if (is(inheritedState)('object', 'array')) {
59
59
  return deepClone(inheritedState, IGNORE_STATE_PARAMS)
60
- } else if (is(inheritedState)('string', 'number')) {
61
- ref.__stateType = 'string'
60
+ } else if (is(inheritedState)('string', 'number', 'boolean')) {
61
+ ref.__stateType = typeof inheritedState
62
62
  return { value: inheritedState }
63
63
  }
64
64
 
@@ -69,8 +69,8 @@ export const checkIfInherits = (element) => {
69
69
  const ref = element.__ref
70
70
  const stateKey = ref.__state
71
71
 
72
- if (!stateKey || isNot(stateKey)('number', 'string')) return false
73
- return true
72
+ if (stateKey && is(stateKey)('number', 'string', 'boolean')) return true
73
+ return false
74
74
  }
75
75
 
76
76
  export const isState = function (state) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/state",
3
- "version": "2.5.15",
3
+ "version": "2.5.16",
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": "2d858d6237f30594a8bbe97c6aca8bc6dc925f85"
34
+ "gitHead": "2987c1965a4cab0258feb592d273d519260f5461"
35
35
  }
package/updateState.js CHANGED
@@ -66,6 +66,7 @@ const hoistStateUpdate = (state, obj, options) => {
66
66
  const element = state.__element
67
67
  const { parent, __ref: ref } = element
68
68
  const stateKey = ref.__state
69
+ const stateType = ref.__stateType
69
70
  if (!stateKey) return
70
71
 
71
72
  const asksForInherit = checkIfInherits(element)
@@ -73,7 +74,7 @@ const hoistStateUpdate = (state, obj, options) => {
73
74
  const shouldPropagateState = asksForInherit && inheritedState && !options.stopStatePropagation
74
75
  if (!shouldPropagateState) return
75
76
 
76
- const isStringState = (ref.__stateType === 'string')
77
+ const isStringState = (stateType === 'string' || stateType === 'number' || stateType === 'boolean')
77
78
  const value = isStringState ? state.value : state.parse()
78
79
  const passedValue = isStringState ? state.value : obj
79
80