domql 1.5.98 → 1.5.99

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
@@ -2,7 +2,7 @@
2
2
  "name": "domql",
3
3
  "description": "DOM rendering Javascript framework at early stage.",
4
4
  "author": "symbo.ls",
5
- "version": "1.5.98",
5
+ "version": "1.5.99",
6
6
  "repository": "https://github.com/domql/domql",
7
7
  "publishConfig": {
8
8
  "registry": "https://registry.npmjs.org"
@@ -30,7 +30,9 @@ const create = (element, parent, key, options = OPTIONS.create || {}) => {
30
30
 
31
31
  // if ELEMENT is not given
32
32
  if (element === undefined) {
33
- if (ENV === 'test' || ENV === 'development') { console.warn(key, 'element is undefined in', parent && parent.path) }
33
+ if (ENV === 'test' || ENV === 'development') {
34
+ console.warn(key, 'element is undefined in', parent && parent.__ref && parent.__ref.path)
35
+ }
34
36
  element = {}
35
37
  }
36
38
  if (element === null) return
@@ -189,6 +191,7 @@ const checkIf = (element, parent) => {
189
191
 
190
192
  const addCaching = (element, parent) => {
191
193
  const { __ref } = element
194
+ let { __ref: __parentRef } = parent
192
195
 
193
196
  // enable TRANSFORM in data
194
197
  if (!element.transform) element.transform = {}
@@ -214,12 +217,13 @@ const addCaching = (element, parent) => {
214
217
 
215
218
  // Add _root element property
216
219
  const hasRoot = parent && parent.key === ':root'
217
- if (!element.__root) element.__root = hasRoot ? element : parent.__root
220
+ if (!__ref.__root) __ref.__root = hasRoot ? element : parent.__ref.__root
218
221
 
219
222
  // set the PATH array
220
223
  if (ENV === 'test' || ENV === 'development') {
221
- if (!parent.path) parent.path = []
222
- element.path = parent.path.concat(element.key)
224
+ if (!__parentRef) __parentRef = parent.__ref = {}
225
+ if (!__parentRef.__path) __parentRef.__path = []
226
+ __ref.__path = __parentRef.__path.concat(element.key)
223
227
  }
224
228
  }
225
229
 
@@ -98,11 +98,12 @@ export const parseDeep = function () {
98
98
 
99
99
  export const log = function (...args) {
100
100
  const element = this
101
+ const { __ref } = element
101
102
  console.group(element.key)
102
103
  if (args.length) {
103
104
  args.forEach(v => console.log(`%c${v}:\n`, 'font-weight: bold', element[v]))
104
105
  } else {
105
- console.log(element.path)
106
+ console.log(__ref.path)
106
107
  const keys = element.keys()
107
108
  keys.forEach(v => console.log(`%c${v}:\n`, 'font-weight: bold', element[v]))
108
109
  }
@@ -26,7 +26,6 @@ export default {
26
26
  transform: {},
27
27
  __ref: {},
28
28
  __hash: {},
29
- __root: {},
30
29
  __text: {},
31
30
  nextElement: {},
32
31
  previousElement: {},
@@ -35,7 +35,7 @@ export const cleanState = function () {
35
35
  export const projectSystemUpdate = function (obj, options = {}) {
36
36
  const state = this
37
37
  if (!state) return
38
- const rootState = (state.__element.__root || state.__element).state
38
+ const rootState = (state.__element.__ref.__root || state.__element).state
39
39
  rootState.update({ PROJECT_SYSTEM: obj }, options)
40
40
  return state
41
41
  }
@@ -43,7 +43,7 @@ export const projectSystemUpdate = function (obj, options = {}) {
43
43
  export const projectStateUpdate = function (obj, options = {}) {
44
44
  const state = this
45
45
  if (!state) return
46
- const rootState = (state.__element.__root || state.__element).state
46
+ const rootState = (state.__element.__ref.__root || state.__element).state
47
47
  rootState.update({ PROJECT_STATE: obj }, options)
48
48
  return state
49
49
  }
@@ -100,7 +100,7 @@ export const updateState = function (obj, options = {}) {
100
100
  export const createState = function (element, parent, opts) {
101
101
  const skip = (opts && opts.skip) ? opts.skip : false
102
102
 
103
- let { state, __root, __ref: __elementRef } = element
103
+ let { state, __ref: __elementRef } = element
104
104
 
105
105
  if (isFunction(state)) state = exec(state, element)
106
106
 
@@ -179,7 +179,7 @@ export const createState = function (element, parent, opts) {
179
179
  state.create = createState
180
180
  state.parent = element.parent.state
181
181
  state.__element = element
182
- state.__root = __root ? __root.state : state
182
+ state.__root = __elementRef.__root ? __elementRef.__root.state : state
183
183
 
184
184
  // editor stuff
185
185
  state.projectSystemUpdate = projectSystemUpdate
@@ -53,7 +53,8 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
53
53
  if (ifPassed) __ref.__if = true
54
54
  if (itWasFalse && ifPassed) {
55
55
  delete element.__hash
56
- if (!__ref.__hasRootState || __ref.__state) delete element.state
56
+ if (!__ref.__hasRootState) delete element.state
57
+ if (__ref.__state) element.state = __ref.__state
57
58
  const created = create(element, element.parent, element.key)
58
59
  if (!options.preventUpdate && element.on && isFunction(element.on.update)) {
59
60
  on.update(element.on.update, created, created.state)
@@ -50,7 +50,7 @@ export const flattenExtend = (extend, stack) => {
50
50
  export const deepCloneExtend = obj => {
51
51
  const o = {}
52
52
  for (const prop in obj) {
53
- if (['parent', 'node', '__element', '__root', '__key'].indexOf(prop) > -1) continue
53
+ if (['parent', 'node', '__element'].indexOf(prop) > -1) continue
54
54
  const objProp = obj[prop]
55
55
  if (isObject(objProp)) {
56
56
  o[prop] = deepCloneExtend(objProp)
@@ -63,7 +63,7 @@ export const deepCloneExtend = obj => {
63
63
 
64
64
  export const deepMergeExtend = (element, extend) => {
65
65
  for (const e in extend) {
66
- if (['parent', 'node', '__element', '__root', '__key'].indexOf(e) > -1) continue
66
+ if (['parent', 'node', '__element'].indexOf(e) > -1) continue
67
67
  const elementProp = element[e]
68
68
  const extendProp = extend[e]
69
69
  if (elementProp === undefined) {
@@ -121,7 +121,7 @@ export const clone = obj => {
121
121
  /**
122
122
  * Deep cloning of object
123
123
  */
124
- export const deepClone = (obj, excluding = ['parent', 'node', '__element', 'state', '__root', '__cached', 'context', 'extend', '__ref']) => {
124
+ export const deepClone = (obj, excluding = ['parent', 'node', '__element', 'state', 'context', 'extend', '__ref']) => {
125
125
  const o = isArray(obj) ? [] : {}
126
126
  for (const prop in obj) {
127
127
  if (excluding.indexOf(prop) > -1) continue
@@ -181,7 +181,7 @@ export const overwrite = (element, params, options) => {
181
181
  return changes
182
182
  }
183
183
 
184
- export const overwriteShallow = (obj, params, excluding = ['node', '__root', '__ref']) => {
184
+ export const overwriteShallow = (obj, params, excluding = ['node', '__ref']) => {
185
185
  for (const e in params) {
186
186
  if (excluding.indexOf(e) > -1) continue
187
187
  obj[e] = params[e]
@@ -192,7 +192,7 @@ export const overwriteShallow = (obj, params, excluding = ['node', '__root', '__
192
192
  /**
193
193
  * Overwrites DEEPly object properties with another
194
194
  */
195
- export const overwriteDeep = (obj, params, excluding = ['node', '__root', '__ref']) => {
195
+ export const overwriteDeep = (obj, params, excluding = ['node', '__ref']) => {
196
196
  for (const e in params) {
197
197
  if (excluding.indexOf(e) > -1) continue
198
198
  const objProp = obj[e]
@@ -217,7 +217,7 @@ export const mergeIfExisted = (a, b) => {
217
217
  /**
218
218
  * Merges array extends
219
219
  */
220
- export const mergeArray = (arr, excluding = ['parent', 'node', '__element', 'state', '__root', '__cached', 'context', '__ref']) => {
220
+ export const mergeArray = (arr, excluding = ['parent', 'node', '__element', 'state', 'context', '__ref']) => {
221
221
  return arr.reduce((a, c) => deepMerge(a, deepClone(c, excluding)), {})
222
222
  }
223
223