domql 1.2.12 → 1.3.2

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/README.md CHANGED
@@ -7,51 +7,17 @@ DOM rendering Javascript framework.
7
7
  - No transpilations, simple ES6 code
8
8
  - One-time import and subtrees
9
9
 
10
- You can start with [starter-kit](https://github.com/rackai/starter-kit) as a boilerplate, or jump into the live editor [playground](https://domql.com/playground/).
10
+ You can start with [starter-kit](https://github.com/rackai/starter-kit) as a boilerplate, or jump into the [playground](https://domql.com/playground/).
11
11
 
12
12
  [![npm version](https://badge.fury.io/js/%40rackai%2Fdomql.svg)](https://badge.fury.io/js/%40rackai%2Fdomql)
13
13
  [![Build Status](https://travis-ci.org/rackai/domql.svg?branch=master)](https://travis-ci.org/rackai/domql)
14
14
  [![Coverage Status](https://coveralls.io/repos/github/rackai/domql/badge.svg?branch=main)](https://coveralls.io/github/rackai/domql?branch=main)
15
15
 
16
- TODO:
17
- - [x] error reporting
18
- - [x] virtual DOM tree
19
- - [x] create
20
- - [x] create using prototype class
21
- - [x] support multiple level prototypes
22
- - [x] DOM caching
23
- - [x] state
24
- - [x] binding
25
- - [x] with other component
26
- - [x] with state
27
- - [x] update
28
- - [x] set (recreate)
29
- - [x] only iterate with diff
30
- - [x] events
31
- - [x] event handling
32
- - [ ] bubbling and propogation
33
- - [ ] run changes inside animationFrame
34
-
35
- ### Getting started
36
-
37
- To install all dependencies and run dev server, run:
38
-
39
- ```shell
40
- yarn && yarn start
41
- ```
42
-
43
- ### Examples
44
-
45
- Initialization:
46
-
47
16
  ```javascript
48
17
  import DOM from '@rackai/domql'
49
18
 
50
19
  DOM.create({ text: 'Rendered' })
51
20
  ```
52
-
53
- Attributes:
54
-
55
21
  ```javascript
56
22
  var link = {
57
23
  tag: 'a',
@@ -70,8 +36,6 @@ var img = {
70
36
  }
71
37
  }
72
38
  ```
73
-
74
- Reusing:
75
39
  ```javascript
76
40
  var Link = {
77
41
  tag: 'a'
@@ -96,8 +60,6 @@ var header = {
96
60
  menu
97
61
  }
98
62
  ```
99
-
100
- Array Support:
101
63
  ```javascript
102
64
  var navItems = ['Home', 'About', 'FAQ', 'Contact']
103
65
 
@@ -106,8 +68,6 @@ var menu = {
106
68
  ...navItems
107
69
  }
108
70
  ```
109
-
110
- Update:
111
71
  ```javascript
112
72
  var val = {
113
73
  text: 0
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.2.12",
6
+ "version": "1.3.2",
7
7
  "repository": "https://github.com/rackai/domql",
8
8
  "publishConfig": {
9
9
  "registry": "https://registry.npmjs.org"
@@ -46,12 +46,12 @@ const create = (element, parent, key, options = {}) => {
46
46
  }
47
47
  }
48
48
 
49
- // enable STATE
50
- element.state = createState(element, parent)
51
-
52
49
  // create PROTOtypal inheritance
53
50
  applyPrototype(element, parent, options)
54
51
 
52
+ // enable STATE
53
+ element.state = createState(element, parent)
54
+
55
55
  // console.groupCollapsed('Create:', assignedKey)
56
56
  // console.log(element)
57
57
 
@@ -71,6 +71,11 @@ const create = (element, parent, key, options = {}) => {
71
71
  return assignNode(element, parent, assignedKey)
72
72
  }
73
73
 
74
+ // run `on.init`
75
+ if (element.on && isFunction(element.on.init)) {
76
+ on.init(element.on.init, element, element.state)
77
+ }
78
+
74
79
  // generate a CLASS name
75
80
  assignClass(element)
76
81
 
@@ -86,11 +91,6 @@ const create = (element, parent, key, options = {}) => {
86
91
  element.log = log
87
92
  }
88
93
 
89
- // run `on.init`
90
- if (element.on && isFunction(element.on.init)) {
91
- on.init(element.on.init, element, element.state)
92
- }
93
-
94
94
  // enable TRANSFORM in data
95
95
  if (!element.transform) element.transform = {}
96
96
 
@@ -4,7 +4,10 @@ import { deepClone, deepMerge, exec, isArray } from '../utils'
4
4
 
5
5
  const initProps = (element, parent) => {
6
6
  const propsStack = []
7
- if (element.props) propsStack.push(element.props)
7
+
8
+ if (element.props === 'inherit') {
9
+ if (parent && parent.props) propsStack.push(parent.props[element.key])
10
+ } else if (element.props) propsStack.push(element.props)
8
11
 
9
12
  if (isArray(element.__proto)) {
10
13
  element.__proto.map(proto => {
@@ -34,7 +34,11 @@ export const updateState = function (obj, options = {}) {
34
34
 
35
35
  export default function (element, parent) {
36
36
  let { state } = element
37
- if (!state) return (parent && parent.state) || {}
37
+ // if (!state) return (parent && parent.state) || {}
38
+ if (!state) {
39
+ if (parent && parent.state) return parent.state
40
+ return {}
41
+ }
38
42
  if (isFunction(state)) state = exec(state, element)
39
43
 
40
44
  state = deepClone(state, ['update', 'parse', '__element'])
@@ -9,6 +9,7 @@ import { merge } from '../utils/object'
9
9
  import { appendNode } from './assign'
10
10
  import { createNode } from '.'
11
11
  import { updateProps } from './createProps'
12
+ import createState from './createState'
12
13
 
13
14
  const UPDATE_DEFAULT_OPTIONS = {
14
15
  stackChanges: false,
@@ -20,17 +21,6 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
20
21
  const element = this
21
22
  const { define, parent, node } = element
22
23
 
23
- // console.groupCollapsed('Update:', element.path)
24
- // console.log('params:')
25
- // console.log(params)
26
- // console.log('props:')
27
- // console.log(element.props)
28
- // console.log('element:')
29
- // console.log(element)
30
- // console.log('PARAMS.PROPS:')
31
- // console.log(params.props)
32
- // console.groupEnd('Update:')
33
- // if params is string
34
24
  if (isString(params) || isNumber(params)) {
35
25
  params = { text: params }
36
26
  }
@@ -39,14 +29,10 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
39
29
  on.initUpdate(element.on.initUpdate, element, element.state)
40
30
  }
41
31
 
42
- // console.log(element, parent)
43
32
  updateProps(params.props, element, parent)
44
- // // console.log(element.path)
45
- // // console.log(element)
46
33
 
47
- // console.groupCollapsed('UPDATE:')
48
- // console.log(element)
49
- // console.groupEnd('UPDATE:')
34
+ // const state = params.state || element.state
35
+ // element.state = createState({ state }, parent)
50
36
 
51
37
  const overwriteChanges = overwrite(element, params, UPDATE_DEFAULT_OPTIONS)
52
38
  const execChanges = throughUpdatedExec(element, UPDATE_DEFAULT_OPTIONS)
@@ -70,9 +56,6 @@ const update = function (params = {}, options = UPDATE_DEFAULT_OPTIONS) {
70
56
  }
71
57
  }
72
58
 
73
- // console.log(node)
74
- // console.groupEnd('Update:')
75
-
76
59
  if (!node || options.preventRecursive) return
77
60
 
78
61
  for (const param in element) {
@@ -77,7 +77,7 @@ export const deepMerge = (element, proto) => {
77
77
  const elementProp = element[e]
78
78
  const protoProp = proto[e]
79
79
  // const cachedProps = cache.props
80
- if (e === 'parent' || e === 'props') continue
80
+ if (e === 'parent' || e === 'props' || e === 'state') continue
81
81
  if (elementProp === undefined) {
82
82
  element[e] = protoProp
83
83
  } else if (isObjectLike(elementProp) && isObject(protoProp)) {
@@ -122,7 +122,7 @@ export const overwrite = (element, params, options) => {
122
122
  const changes = {}
123
123
 
124
124
  for (const e in params) {
125
- if (e === 'props') continue
125
+ if (e === 'props' || e === 'state') continue
126
126
 
127
127
  const elementProp = element[e]
128
128
  const paramsProp = params[e]
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- import { isArray, isFunction, isObject } from './object'
3
+ import { exec, isArray, isFunction, isObject } from './object'
4
4
 
5
5
  export const generateHash = () => Math.random().toString(36).substring(2)
6
6