domql 1.5.57 → 1.5.59

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "DOM rendering Javascript framework at early stage.",
4
4
  "private": false,
5
5
  "author": "symbo.ls",
6
- "version": "1.5.57",
6
+ "version": "1.5.59",
7
7
  "repository": "https://github.com/domql/domql",
8
8
  "publishConfig": {
9
9
  "registry": "https://registry.npmjs.org"
@@ -1,9 +1,8 @@
1
1
  'use strict'
2
2
 
3
3
  import { isFunction, isObject, isObjectLike } from '../utils'
4
- import { registry } from './mixins'
4
+ import { registry, parseFilters } from './mixins'
5
5
  import root from './root'
6
- import { removeContentElement } from './set'
7
6
 
8
7
  const ENV = process.env.NODE_ENV
9
8
 
@@ -12,7 +11,7 @@ export const lookup = function (key) {
12
11
  const element = this
13
12
  let { parent } = element
14
13
 
15
- while (parent.key !== key){
14
+ while (parent.key !== key) {
16
15
  if (parent[key]) return parent[key]
17
16
  parent = parent.parent
18
17
  if (!parent) return
@@ -74,9 +73,9 @@ export const keys = function () {
74
73
  const element = this
75
74
  const keys = []
76
75
  for (const param in element) {
77
- if (!isObject(registry[param])) {
78
- keys.push(param)
79
- }
76
+ if (registry[param] && !parseFilters.elementKeys.includes(param))
77
+ continue
78
+ keys.push(param)
80
79
  }
81
80
  return keys
82
81
  }
@@ -93,8 +92,7 @@ export const parseDeep = function () {
93
92
  const element = this
94
93
  const obj = parse.call(element)
95
94
  for (const k in obj) {
96
- if (isObjectLike(obj[k]))
97
- obj[k] = parseDeep.call(obj[k])
95
+ if (isObjectLike(obj[k])) { obj[k] = parseDeep.call(obj[k]) }
98
96
  }
99
97
  return obj
100
98
  }
@@ -125,7 +123,7 @@ export const isMethod = function (param) {
125
123
  param === 'setProps' ||
126
124
  param === 'parseDeep' ||
127
125
  param === 'if' ||
128
- param === 'log' ||
126
+ param === 'log' ||
129
127
  param === 'nextElement' ||
130
128
  param === 'previousElement'
131
129
  }
@@ -9,7 +9,6 @@ import style from './style'
9
9
  import text from './text'
10
10
  import state from './state'
11
11
  import registry from './registry'
12
-
13
12
  export {
14
13
  attr,
15
14
  classList,
@@ -19,5 +18,6 @@ export {
19
18
  text,
20
19
  html,
21
20
  state,
22
- registry
21
+ registry,
23
22
  }
23
+ export * from './registry'
@@ -74,3 +74,15 @@ export default {
74
74
  component: {},
75
75
  context: {}
76
76
  }
77
+
78
+ // List of keys for .parse() and .parseDeep() to include in the result.
79
+ // Keys not in the array are excluded.
80
+ export const parseFilters = {
81
+ elementKeys: [
82
+ 'tag', 'text', 'style', 'attr', 'class', 'state', 'class',
83
+ 'data', 'content', 'html',
84
+ // TODO: 'props' ?
85
+ ],
86
+ propsKeys: ['__element'],
87
+ stateKeys: [],
88
+ }
@@ -60,7 +60,7 @@ export const updateState = function (obj, options = {}) {
60
60
  if (element.__state) {
61
61
  if (state.parent && state.parent[element.__state]) {
62
62
  const keyInParentState = state.parent[element.__state]
63
- if (keyInParentState) {
63
+ if (keyInParentState && !options.stopStatePropogation) {
64
64
  return state.parent.update({ [element.__state]: obj }, options)
65
65
  }
66
66
  }
@@ -69,7 +69,7 @@ export const updateState = function (obj, options = {}) {
69
69
  }
70
70
 
71
71
  // TODO: try debounce
72
- if (!options.preventUpdate) element.update({}, options)
72
+ if (!options.preventUpdate || options.preventUpdate === 'recursive') element.update({}, { ...options, preventUpdate: true })
73
73
 
74
74
  if (state.__depends) {
75
75
  for (const el in state.__depends) {
@@ -113,7 +113,7 @@ export default function (element, parent) {
113
113
  if (stateKey) {
114
114
  let parentState = parent.state
115
115
  let parentStateKey
116
- if (stateKey.includes('../')) {
116
+ if (stateKey.includes('..')) {
117
117
  stateKey = stateKey.split('../')[1]
118
118
  parentState = parent.state.parent
119
119
  }
@@ -24,13 +24,13 @@ const UPDATE_DEFAULT_OPTIONS = {
24
24
 
25
25
  const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
26
26
  const element = this
27
- const { define, parent, node, state } = element
27
+ const { define, parent, node } = element
28
28
 
29
29
  const { currentSnapshot, calleeElement } = options
30
30
  if (!calleeElement) {
31
31
  element.__currentSnapshot = snapshot.snapshotId()
32
32
  }
33
- const snapshotOnCallee = element.__currentSnapshot || calleeElement && calleeElement.__currentSnapshot
33
+ const snapshotOnCallee = element.__currentSnapshot || (calleeElement && calleeElement.__currentSnapshot)
34
34
  if (snapshotOnCallee && currentSnapshot < snapshotOnCallee) {
35
35
  // console.log(calleeElement)
36
36
  // console.log(currentSnapshot, snapshotOnCallee, 'cancelling')
@@ -60,7 +60,7 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
60
60
  if (keyInParentState) {
61
61
  element.state = createState(element, parent)
62
62
  }
63
- } else if (!element.__hasRootState) element.state = parent && parent.state || {}
63
+ } else if (!element.__hasRootState) element.state = (parent && parent.state) || {}
64
64
 
65
65
  if (!element.__ifFalsy && !options.preventPropsUpdate) updateProps(params.props, element, parent)
66
66
 
@@ -88,9 +88,10 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
88
88
  const prop = element[param]
89
89
 
90
90
  if (
91
- options.preventDefineUpdate === true || options.preventDefineUpdate === param ||
92
- options.preventContentUpdate && param === 'content' ||
93
- options.preventStateUpdate && param === 'state' ||
91
+ options.preventDefineUpdate === true ||
92
+ options.preventDefineUpdate === param ||
93
+ (options.preventContentUpdate && param === 'content') ||
94
+ (options.preventStateUpdate && param) === 'state' ||
94
95
  isMethod(param) || isObject(registry[param]) || prop === undefined
95
96
  ) continue
96
97
  if (options.preventStateUpdate === 'once') options.preventStateUpdate = false