domql 1.4.8 → 1.4.11

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.8",
6
+ "version": "1.4.11",
7
7
  "repository": "https://github.com/rackai/domql",
8
8
  "publishConfig": {
9
9
  "registry": "https://registry.npmjs.org"
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import DOM from '../../src'
4
- import { isObjectLike, exec } from '../../src/utils'
4
+ import { isObjectLike, exec, isObject } from '../../src/utils'
5
5
  import { classList } from '../../src/element/mixins'
6
6
  import createEmotion from '@emotion/css/create-instance'
7
7
  const ENV = process.env.NODE_ENV
@@ -34,7 +34,7 @@ const classf = (params, element, node) => {
34
34
  for (const key in params) {
35
35
  const prop = exec(params[key], element)
36
36
  if (!prop) continue
37
- if (ENV === 'test' || ENV === 'development') prop.label = key || element.key
37
+ if ((ENV === 'test' || ENV === 'development') && isObject(prop)) prop.label = key || element.key
38
38
  const CSSed = css(prop)
39
39
  classObjHelper[key] = CSSed
40
40
  }
@@ -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 } from '../utils'
15
- import { remove, lookup, log, keys, parse, parseDeep } from './methods'
15
+ import { remove, lookup, setProps, log, keys, parse, parseDeep } from './methods'
16
16
  import cacheNode from './cache'
17
17
  import { registry } from './mixins'
18
18
  // import { overwrite, clone, fillTheRest } from '../utils'
@@ -44,13 +44,9 @@ const create = (element, parent, key, options = {}) => {
44
44
  const assignedKey = element.key || key || createID.next().value
45
45
 
46
46
  // if PARENT is not given
47
- // if (parent === null) parent = root
48
- // if (parent === undefined) parent = root
49
47
  if (!parent) parent = root
50
48
  if (isNode(parent)) parent = root[`${key}_parent`] = { node: parent }
51
49
 
52
- // if (assignedKey === 'all') debugger
53
-
54
50
  // if element is STRING
55
51
  if (isString(element) || isNumber(element)) {
56
52
  element = {
@@ -61,6 +57,7 @@ const create = (element, parent, key, options = {}) => {
61
57
  }
62
58
 
63
59
  // create PROTOtypal inheritance
60
+
64
61
  applyPrototype(element, parent, options)
65
62
 
66
63
  if (Object.keys(options).length) {
@@ -71,9 +68,6 @@ const create = (element, parent, key, options = {}) => {
71
68
  // enable STATE
72
69
  element.state = createState(element, parent)
73
70
 
74
- // console.groupCollapsed('Create:', assignedKey)
75
- // console.log(element)
76
-
77
71
  // create and assign a KEY
78
72
  element.key = assignedKey
79
73
 
@@ -87,16 +81,14 @@ const create = (element, parent, key, options = {}) => {
87
81
  }
88
82
  }
89
83
 
90
- // set the PATH
84
+ // set the PATH array
91
85
  if (ENV === 'test' || ENV === 'development') {
92
86
  if (!parent.path) parent.path = []
93
87
  element.path = parent.path.concat(assignedKey)
94
88
  }
95
89
 
96
- // if it already HAS A NODE
97
- if (element.node) { // TODO: check on if
98
- // console.log('hasNode!')
99
- // console.groupEnd('Create:')
90
+ // if it already HAS a NODE
91
+ if (element.node && !element.__ifFalsy) { // TODO: check on if
100
92
  return assignNode(element, parent, assignedKey)
101
93
  }
102
94
 
@@ -104,6 +96,7 @@ const create = (element, parent, key, options = {}) => {
104
96
  element.set = set
105
97
  element.update = update
106
98
  element.remove = remove
99
+ element.setProps = setProps
107
100
  element.lookup = lookup
108
101
  element.parse = parse
109
102
  element.parseDeep = parseDeep
@@ -139,15 +132,6 @@ const create = (element, parent, key, options = {}) => {
139
132
  // generate a CLASS name
140
133
  assignClass(element)
141
134
 
142
- // console.log('cache.props:')
143
- // console.log(cache.props)
144
- // console.log('applied props:')
145
- // console.log(element.props)
146
- // console.log('element:')
147
- // console.log(element)
148
- // console.groupEnd('Create:')
149
-
150
-
151
135
  // console.group('create')
152
136
  // console.log(element.path)
153
137
  // console.log(element)
@@ -6,7 +6,7 @@ const initProps = (element, parent) => {
6
6
  const { props } = element
7
7
  const propsStack = []
8
8
 
9
- const hasMatch = isString(props) && props.indexOf('match') > -1
9
+ const isMatch = isString(props) && props.indexOf('match') > -1
10
10
  const matchParent = parent.props && parent.props[element.key]
11
11
 
12
12
  const objectizeStringProperty = propValue => {
@@ -18,10 +18,12 @@ const initProps = (element, parent) => {
18
18
  propsStack.push(props)
19
19
  } else if (props === 'inherit') {
20
20
  if (parent.props) propsStack.push(parent.props)
21
- } else if (hasMatch) {
21
+ } else if (isMatch) {
22
22
  const hasArg = props.split(' ')
23
23
  let matchParentValue
24
+ //console.log('hasArg', hasArg)
24
25
  if (hasArg[1] && parent.props[hasArg[1]]) {
26
+ console.log('hasArg[1]', hasArg[1])
25
27
  const secondArgasParentMatchProp = parent.props[hasArg[1]]
26
28
  propsStack.push(
27
29
  objectizeStringProperty(secondArgasParentMatchProp)
@@ -12,7 +12,7 @@ import update from './update'
12
12
  import parse from './parse'
13
13
  import set from './set'
14
14
 
15
- import { lookup, remove, get, log, keys } from './methods'
15
+ import { lookup, remove, get, setProps, log, keys } from './methods'
16
16
 
17
17
  export {
18
18
  nodes,
@@ -27,6 +27,7 @@ export {
27
27
  update,
28
28
  parse,
29
29
  lookup,
30
+ setProps,
30
31
  set,
31
32
  get,
32
33
  log,
@@ -33,6 +33,13 @@ export const set = function () {
33
33
  export const update = function () {
34
34
  }
35
35
 
36
+ export const setProps = function (param, options) {
37
+ const element = this
38
+ if (!param || !element.props) return
39
+ element.update({ props: param }, options)
40
+ return element.props
41
+ }
42
+
36
43
  export const defineSetter = (element, key, get, set) =>
37
44
  Object.defineProperty(element, key, { get, set })
38
45
 
@@ -90,6 +97,7 @@ export const isMethod = function (param) {
90
97
  param === 'lookup' ||
91
98
  param === 'keys' ||
92
99
  param === 'parse' ||
100
+ param === 'setProps' ||
93
101
  param === 'parseDeep' ||
94
102
  param === 'if' ||
95
103
  param === 'log'
@@ -45,6 +45,7 @@ export default {
45
45
  node: {},
46
46
  set: {},
47
47
  update: {},
48
+ setProps: {},
48
49
  remove: {},
49
50
  lookup: {},
50
51
  keys: {},
@@ -12,26 +12,10 @@ export const applyPrototype = (element, parent, options = {}) => {
12
12
  if (isFunction(element)) element = exec(element, parent)
13
13
 
14
14
  const { proto } = element
15
-
16
- // merge if proto is array
17
- // const proto = mergeAndCloneIfArray(element.proto, v => {
18
- // if (v.props) cache.props.push(v.props)
19
- // console.log('v.propsIN_PROTO:')
20
- // console.log(v.props)
21
- // })
22
-
23
- // console.log(proto)
24
15
  const protoStack = getProtoStack(proto)
25
16
 
26
17
  if (ENV !== 'test' || ENV !== 'development') delete element.proto
27
18
 
28
- // console.log(parent.childProto)
29
-
30
- // console.log(element)
31
- // console.log(proto)
32
- // console.log(protoStack)
33
- // debugger
34
-
35
19
  let childProtoStack = []
36
20
  if (parent) {
37
21
  // Assign parent attr to the element
@@ -41,18 +25,9 @@ export const applyPrototype = (element, parent, options = {}) => {
41
25
  }
42
26
  }
43
27
 
44
- // console.log(proto, parent && parent.childProto)
45
- // console.log(protoStack, childProtoStack)
46
-
47
28
  const protoLength = protoStack.length
48
29
  const childProtoLength = childProtoStack.length
49
30
 
50
- // console.group('proto')
51
- // console.log(protoLength)
52
- // console.log(childProtoLength)
53
- // console.log(element)
54
- // console.groupEnd('proto')
55
-
56
31
  let stack = []
57
32
  if (protoLength && childProtoLength) {
58
33
  stack = jointStacks(protoStack, childProtoStack)
@@ -73,11 +48,8 @@ export const applyPrototype = (element, parent, options = {}) => {
73
48
  const component = exec(element.component || mergedProto.component, element)
74
49
  if (component && options.components && options.components[component]) {
75
50
  const componentProto = cloneAndMergeArrayProto(getProtoStack(options.components[component]))
76
- mergedProto = deepMergeProto(mergedProto, componentProto)
51
+ mergedProto = deepMergeProto(componentProto, mergedProto)
77
52
  }
78
53
 
79
- // console.log(mergedProto)
80
54
  return deepMergeProto(element, mergedProto)
81
-
82
- // final merging with prototype
83
55
  }
@@ -77,7 +77,7 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
77
77
  // else console.log(element.path, '\n\n', stackChanges)
78
78
 
79
79
  // console.log(element.key, element.__ifFalsy)
80
- if (element.__ifFalsy || options.preventRecursive) return element
80
+ if (element.__ifFalsy) return element
81
81
  if (!node) {
82
82
  return
83
83
  // return createNode(element, options)
@@ -101,12 +101,12 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
101
101
  const hasDefined = define && define[param]
102
102
  const ourParam = registry[param]
103
103
 
104
- // // console.log(prop)
104
+ if (options.preventContentUpdate && param === 'content') console.log(param)
105
105
 
106
106
  if (ourParam) {
107
107
  if (isFunction(ourParam)) ourParam(prop, element, node)
108
108
  } else if (prop && isObject(prop) && !hasDefined) {
109
- if (!options.preventChildrenUpdate) update.call(prop, params[prop], UPDATE_DEFAULT_OPTIONS)
109
+ if (!options.preventRecursive) update.call(prop, params[prop], UPDATE_DEFAULT_OPTIONS)
110
110
  }
111
111
  }
112
112