domql 1.4.0 → 1.4.3

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": "rackai",
6
- "version": "1.4.0",
6
+ "version": "1.4.3",
7
7
  "repository": "https://github.com/rackai/domql",
8
8
  "publishConfig": {
9
9
  "registry": "https://registry.npmjs.org"
@@ -32,6 +32,28 @@ const create = (element, parent, key, options = {}) => {
32
32
  if (options.ignoreChildProto) delete options.ignoreChildProto
33
33
  }
34
34
 
35
+ // if element is proto
36
+ if (element.__hash) {
37
+ element = { proto: element }
38
+ }
39
+
40
+ if (options.components) {
41
+ const { components } = options
42
+ const { proto } = element
43
+ if (isString(proto))
44
+ if (components[proto]) element.proto = components[proto]
45
+ else console.warn(proto, 'is not in library', components, element)
46
+
47
+ // // if KEY is PROTO
48
+ // const k = element.key || key
49
+ // const keyIsProto = isString(k) && k.charAt(0) === k.charAt(0).toUpperCase()
50
+ // if (keyIsProto) component = key
51
+ // let { match, ...rest } = element
52
+ // if proto comes from library as string
53
+ // const fromLibrary = isString(match) ? components[match] : match
54
+ // if (fromLibrary) element = { proto: fromLibrary, ...rest }
55
+ }
56
+
35
57
  // define KEY
36
58
  const assignedKey = element.key || key || createID.next().value
37
59
 
@@ -1,17 +1,25 @@
1
1
  'use strict'
2
2
 
3
- import { deepClone, deepMerge, exec, isArray, isObject } from '../utils'
3
+ import { deepClone, deepMerge, exec, isArray, isObject, isString } from '../utils'
4
4
 
5
5
  const initProps = (element, parent) => {
6
+ const { props } = element
6
7
  const propsStack = []
7
8
 
8
- if (isObject(element.props)) {
9
- propsStack.push(element.props)
10
- } else if (element.props === 'inherit') {
11
- if (parent && parent.props) propsStack.push(parent.props)
12
- } else if (element.props === 'match') {
13
- if (parent && parent.props) propsStack.push(parent.props[element.key])
14
- } else if (element.props) propsStack.push(element.props)
9
+ const hasMatch = isString(props) && props.indexOf('match') > -1
10
+ const matchParent = parent.props && parent.props[element.key]
11
+
12
+ if (isObject(props)) {
13
+ propsStack.push(props)
14
+ } else if (props === 'inherit') {
15
+ if (parent.props) propsStack.push(parent.props)
16
+ } else if (hasMatch) {
17
+ const hasArg = props.split(' ')
18
+ if (hasArg[1] && parent.props[hasArg[1]]) propsStack.push(parent.props[hasArg[1]])
19
+ else if (matchParent) propsStack.push(matchParent)
20
+ } else if (props) propsStack.push(props)
21
+
22
+ if (matchParent && props !== 'match') propsStack.push(matchParent)
15
23
 
16
24
  if (isArray(element.__proto)) {
17
25
  element.__proto.map(proto => {
@@ -19,16 +19,13 @@ export const setHashedProto = (proto, stack) => {
19
19
  const hash = generateHash()
20
20
  proto.__hash = hash
21
21
  protoStackRegistry[hash] = stack
22
- return protoStackRegistry[hash]
22
+ return stack
23
23
  }
24
24
 
25
25
  export const getProtoStackRegistry = (proto, stack) => {
26
- if (proto.__hash) {
26
+ if (proto.__hash)
27
27
  return stack.concat(getHashedProto(proto))
28
- } else {
29
- setHashedProto(proto, stack)
30
- }
31
- return stack // .concat(hashedProto)
28
+ return setHashedProto(proto, stack) // stack .concat(hashedProto)
32
29
  }
33
30
 
34
31
  // stacking