domql 1.5.17 → 1.5.18
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 +1 -1
- package/src/element/create.js +38 -39
- package/src/element/methods.js +20 -0
- package/src/element/mixins/registry.js +1 -0
- package/src/element/mixins/state.js +3 -1
- package/src/element/props.js +5 -3
- package/src/element/state.js +37 -5
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": "rackai",
|
|
6
|
-
"version": "1.5.
|
|
6
|
+
"version": "1.5.18",
|
|
7
7
|
"repository": "https://github.com/rackai/domql",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"registry": "https://registry.npmjs.org"
|
package/src/element/create.js
CHANGED
|
@@ -12,7 +12,7 @@ import update from './update'
|
|
|
12
12
|
import * as on from '../event/on'
|
|
13
13
|
import { assignClass } from './mixins/classList'
|
|
14
14
|
import { isFunction, isNumber, isString, createID, isNode, exec } from '../utils'
|
|
15
|
-
import { remove, lookup, setProps, log, keys, parse, parseDeep } from './methods'
|
|
15
|
+
import { remove, lookup, setProps, log, keys, parse, parseDeep, spotByPath } from './methods'
|
|
16
16
|
import cacheNode from './cache'
|
|
17
17
|
import { registry } from './mixins'
|
|
18
18
|
// import { overwrite, clone, fillTheRest } from '../utils'
|
|
@@ -83,21 +83,30 @@ const create = (element, parent, key, options = {}) => {
|
|
|
83
83
|
if (options.ignoreChildExtend) delete options.ignoreChildExtend
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
// enable STATE
|
|
87
|
-
element.state = createState(element, parent)
|
|
88
|
-
|
|
89
86
|
// create and assign a KEY
|
|
90
87
|
element.key = assignedKey
|
|
91
88
|
|
|
92
|
-
//
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
89
|
+
// enable TRANSFORM in data
|
|
90
|
+
if (!element.transform) element.transform = {}
|
|
91
|
+
|
|
92
|
+
// enable CACHING
|
|
93
|
+
if (!element.__cached) element.__cached = {}
|
|
94
|
+
|
|
95
|
+
// enable EXEC
|
|
96
|
+
if (!element.__exec) element.__exec = {}
|
|
97
|
+
|
|
98
|
+
// enable CLASS CACHING
|
|
99
|
+
if (!element.__class) element.__class = {}
|
|
100
|
+
|
|
101
|
+
// enable CHANGES storing
|
|
102
|
+
if (!element.__changes) element.__changes = []
|
|
103
|
+
|
|
104
|
+
// enable CHANGES storing
|
|
105
|
+
if (!element.__children) element.__children = []
|
|
106
|
+
|
|
107
|
+
// Add _root element property
|
|
108
|
+
const hasRoot = parent.parent && parent.parent.key === ':root'
|
|
109
|
+
if (!element.__root) element.__root = hasRoot ? parent : parent.__root
|
|
101
110
|
|
|
102
111
|
// set the PATH array
|
|
103
112
|
if (ENV === 'test' || ENV === 'development') {
|
|
@@ -105,11 +114,6 @@ const create = (element, parent, key, options = {}) => {
|
|
|
105
114
|
element.path = parent.path.concat(assignedKey)
|
|
106
115
|
}
|
|
107
116
|
|
|
108
|
-
// if it already HAS a NODE
|
|
109
|
-
if (element.node && !element.__ifFalsy) { // TODO: check on if
|
|
110
|
-
return assignNode(element, parent, assignedKey)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
117
|
// assign METHODS
|
|
114
118
|
element.set = set
|
|
115
119
|
element.update = update
|
|
@@ -117,6 +121,7 @@ const create = (element, parent, key, options = {}) => {
|
|
|
117
121
|
element.removeContent = removeContentElement
|
|
118
122
|
element.setProps = setProps
|
|
119
123
|
element.lookup = lookup
|
|
124
|
+
element.spotByPath = spotByPath
|
|
120
125
|
element.parse = parse
|
|
121
126
|
element.parseDeep = parseDeep
|
|
122
127
|
element.keys = keys
|
|
@@ -124,29 +129,23 @@ const create = (element, parent, key, options = {}) => {
|
|
|
124
129
|
element.log = log
|
|
125
130
|
}
|
|
126
131
|
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
// enable TRANSFORM in data
|
|
130
|
-
if (!element.transform) element.transform = {}
|
|
131
|
-
|
|
132
|
-
// enable CACHING
|
|
133
|
-
if (!element.__cached) element.__cached = {}
|
|
134
|
-
|
|
135
|
-
// enable EXEC
|
|
136
|
-
if (!element.__exec) element.__exec = {}
|
|
137
|
-
|
|
138
|
-
// enable CLASS CACHING
|
|
139
|
-
if (!element.__class) element.__class = {}
|
|
140
|
-
|
|
141
|
-
// enable CHANGES storing
|
|
142
|
-
if (!element.__changes) element.__changes = []
|
|
132
|
+
// enable STATE
|
|
133
|
+
element.state = createState(element, parent)
|
|
143
134
|
|
|
144
|
-
//
|
|
145
|
-
if (
|
|
135
|
+
// don't render IF in condition
|
|
136
|
+
if (isFunction(element.if)) {
|
|
137
|
+
// TODO: move as fragment
|
|
138
|
+
if (!element.if(element, element.state)) {
|
|
139
|
+
const ifFragment = cacheNode({ tag: 'fragment' })
|
|
140
|
+
element.__ifFragment = appendNode(ifFragment, parent.node)
|
|
141
|
+
element.__ifFalsy = true
|
|
142
|
+
}
|
|
143
|
+
}
|
|
146
144
|
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
// if it already HAS a NODE
|
|
146
|
+
if (element.node && !element.__ifFalsy) { // TODO: check on if
|
|
147
|
+
return assignNode(element, parent, assignedKey)
|
|
148
|
+
}
|
|
150
149
|
|
|
151
150
|
// apply props settings
|
|
152
151
|
if (!element.__ifFalsy) createProps(element, parent)
|
package/src/element/methods.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { isFunction, isObject, isObjectLike } from '../utils'
|
|
4
4
|
import { registry } from './mixins'
|
|
5
|
+
import root from './root'
|
|
5
6
|
import { removeContentElement } from './set'
|
|
6
7
|
|
|
7
8
|
const ENV = process.env.NODE_ENV
|
|
@@ -20,6 +21,24 @@ export const lookup = function (key) {
|
|
|
20
21
|
return parent
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
// TODO: update these files
|
|
25
|
+
export const spotByPath = function (path) {
|
|
26
|
+
const element = this
|
|
27
|
+
const arr = [].concat(path)
|
|
28
|
+
let active = root[arr[0]]
|
|
29
|
+
|
|
30
|
+
if (!arr || !arr.length) return console.log(arr, 'on', element.key, 'is undefined')
|
|
31
|
+
|
|
32
|
+
while (active.key === arr[0]) {
|
|
33
|
+
arr.shift()
|
|
34
|
+
if (!arr.length) break
|
|
35
|
+
active = active[arr[0]]
|
|
36
|
+
if (!active) return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return active
|
|
40
|
+
}
|
|
41
|
+
|
|
23
42
|
export const remove = function (params) {
|
|
24
43
|
const element = this
|
|
25
44
|
if (isFunction(element.node.remove)) element.node.remove()
|
|
@@ -104,6 +123,7 @@ export const isMethod = function (param) {
|
|
|
104
123
|
param === 'remove' ||
|
|
105
124
|
param === 'removeContent' ||
|
|
106
125
|
param === 'lookup' ||
|
|
126
|
+
param === 'spotByPath' ||
|
|
107
127
|
param === 'keys' ||
|
|
108
128
|
param === 'parse' ||
|
|
109
129
|
param === 'setProps' ||
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { exec, isObject } from '../../utils'
|
|
4
|
+
import { IGNORE_STATE_PARAMS } from '../state'
|
|
4
5
|
|
|
5
6
|
export default (params, element, node) => {
|
|
6
7
|
const state = exec(params, element)
|
|
7
8
|
|
|
8
9
|
if (isObject(state)) {
|
|
9
10
|
for (const param in state) {
|
|
10
|
-
|
|
11
|
+
IGNORE_STATE_PARAMS
|
|
12
|
+
if (IGNORE_STATE_PARAMS.includes(param)) continue
|
|
11
13
|
element.state[param] = exec(state[param], element)
|
|
12
14
|
}
|
|
13
15
|
}
|
package/src/element/props.js
CHANGED
|
@@ -15,12 +15,14 @@ const initProps = (element, parent) => {
|
|
|
15
15
|
return propValue
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
if (isObject(props)) {
|
|
19
|
+
propsStack.push(props)
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
if (matchParent && props !== 'match') propsStack.push(matchParent)
|
|
19
23
|
if (matchParentChild) propsStack.push(matchParentChild)
|
|
20
24
|
|
|
21
|
-
if (
|
|
22
|
-
propsStack.push(props)
|
|
23
|
-
} else if (props === 'inherit') {
|
|
25
|
+
if (props === 'inherit') {
|
|
24
26
|
if (parent.props) propsStack.push(parent.props)
|
|
25
27
|
} else if (isMatch) {
|
|
26
28
|
const hasArg = props.split(' ')
|
package/src/element/state.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import { on } from '../event'
|
|
4
|
-
import { deepClone, exec, isFunction, overwriteDeep } from '../utils'
|
|
4
|
+
import { deepClone, exec, isFunction, isObject, overwriteDeep } from '../utils'
|
|
5
|
+
|
|
6
|
+
export const IGNORE_STATE_PARAMS = ['update', 'parse', 'clean', 'parent', '__element', '__depends', '__ref']
|
|
5
7
|
|
|
6
8
|
export const parseState = function () {
|
|
7
9
|
const state = this
|
|
8
10
|
const parseState = {}
|
|
9
11
|
for (const param in state) {
|
|
10
|
-
if (param
|
|
12
|
+
if (!IGNORE_STATE_PARAMS.includes(param)) {
|
|
11
13
|
parseState[param] = state[param]
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
return parseState
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
export const cleanState = function () {
|
|
20
|
+
const state = this
|
|
21
|
+
for (const param in state) {
|
|
22
|
+
if (!IGNORE_STATE_PARAMS.includes(param)) {
|
|
23
|
+
delete state[param]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return state
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
export const updateState = function (obj, options = {}) {
|
|
18
30
|
const state = this
|
|
19
31
|
const element = state.__element
|
|
@@ -23,10 +35,18 @@ export const updateState = function (obj, options = {}) {
|
|
|
23
35
|
on.initStateUpdated(element.on.initStateUpdated, element, state)
|
|
24
36
|
}
|
|
25
37
|
|
|
26
|
-
overwriteDeep(state, obj,
|
|
38
|
+
overwriteDeep(state, obj, IGNORE_STATE_PARAMS)
|
|
27
39
|
|
|
28
40
|
if (!options.preventUpdate) element.update({}, options)
|
|
29
41
|
|
|
42
|
+
if (state.__depends) {
|
|
43
|
+
for (const el in state.__depends) {
|
|
44
|
+
// const findElement = element.spotByPath(state.__depends[el])
|
|
45
|
+
const findElement = state.__depends[el]
|
|
46
|
+
findElement.clean().update(state.parse(), options)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
30
50
|
// run `on.stateUpdated`
|
|
31
51
|
if (element.on && isFunction(element.on.stateUpdated)) {
|
|
32
52
|
on.stateUpdated(element.on.stateUpdated, element, state)
|
|
@@ -35,15 +55,27 @@ export const updateState = function (obj, options = {}) {
|
|
|
35
55
|
|
|
36
56
|
export default function (element, parent) {
|
|
37
57
|
let { state } = element
|
|
38
|
-
|
|
58
|
+
|
|
39
59
|
if (!state) {
|
|
40
60
|
if (parent && parent.state) return parent.state
|
|
41
61
|
return {}
|
|
42
62
|
}
|
|
63
|
+
|
|
43
64
|
if (isFunction(state)) state = exec(state, element)
|
|
44
65
|
|
|
45
|
-
|
|
66
|
+
const { __ref } = state
|
|
67
|
+
if (__ref) {
|
|
68
|
+
state = deepClone(__ref, IGNORE_STATE_PARAMS)
|
|
69
|
+
if (isObject(__ref.__depends)) {
|
|
70
|
+
__ref.__depends[element.key] = state
|
|
71
|
+
} else __ref.__depends = { [element.key] : state }
|
|
72
|
+
} else {
|
|
73
|
+
state = deepClone(state, IGNORE_STATE_PARAMS)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
element.state = state
|
|
46
77
|
state.__element = element
|
|
78
|
+
state.clean = cleanState
|
|
47
79
|
state.parse = parseState
|
|
48
80
|
state.update = updateState
|
|
49
81
|
state.parent = element.parent.state
|