Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit e8d9d41

Browse files
committed
Code cleanup.
1. General clean up. 2. Replaced for loops with while loops.
1 parent 89c2e3b commit e8d9d41

File tree

8 files changed

+25
-15
lines changed

8 files changed

+25
-15
lines changed

dist/composi-core.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/composi-core.js.gz

10 Bytes
Binary file not shown.

dist/composi-core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@composi/core",
3-
"version": "0.9.3",
3+
"version": "0.9.4",
44
"description": "A JavaScript library for creating websites, PWAs and hybrid apps.",
55
"main": "src/index.js",
66
"scripts": {

src/h.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export function h(type, props, ...children) {
2727

2828
while (tempBox.length > 0) {
2929
if (Array.isArray((node = tempBox.pop()))) {
30-
for (length = node.length; length-- > 0; ) {
30+
let length = node.length
31+
while (length-- > 0) {
3132
tempBox.push(node[length])
3233
}
3334
} else if (node === false || node === true || node == null) {

src/union.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
33
function safeUnion(types, options) {
44
const prefix = (options && options.prefix) || ''
55
const prefixSize = prefix.length
6+
const variants = Object.create(null)
67
let stripPrefix
8+
79
if (prefixSize) {
810
stripPrefix = tag =>
911
tag &&
@@ -15,7 +17,7 @@ function safeUnion(types, options) {
1517
}
1618

1719
const matcher = (handlers, catchAll) => {
18-
return function _matcher(tag, context) {
20+
return (tag, context) => {
1921
const tagType = stripPrefix(tag)
2022
const match = hasOwnProperty.call(handlers, tagType) && handlers[tagType]
2123
return match ? match(tag.data, context) : catchAll(context)
@@ -33,11 +35,12 @@ function safeUnion(types, options) {
3335
}
3436
}
3537

36-
const variants = Object.create(null)
37-
for (let i = 0; i < types.length; i++) {
38-
const type = types[i]
38+
let idx = 0
39+
while (idx < types.length) {
40+
const type = types[idx]
3941
const prefixedType = prefix + type
4042
variants[type] = data => ({ type: prefixedType, data })
43+
idx++
4144
}
4245

4346
return { variants, methods }

src/vdom.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ function createKeyMap(children, startCount, end) {
3333
let key
3434
let vnode
3535

36-
for (; startCount <= end; startCount++) {
36+
while (startCount <= end) {
3737
if ((key = (vnode = children[startCount]).key) != null) {
3838
out[key] = vnode
3939
}
40+
startCount++
4041
}
4142

4243
return out
@@ -136,9 +137,11 @@ function createElement(vnode, lifecycle, isSVG) {
136137
props['onmount'](element)
137138
})
138139
}
139-
140-
for (let i = 0, length = vnode.children.length; i < length; i++) {
141-
element.appendChild(createElement(vnode.children[i], lifecycle, isSVG))
140+
let idx = 0
141+
const length = vnode.children.length
142+
while (idx < length) {
143+
element.appendChild(createElement(vnode.children[idx], lifecycle, isSVG))
144+
idx++
142145
}
143146

144147
for (let prop in props) {
@@ -154,8 +157,11 @@ function createElement(vnode, lifecycle, isSVG) {
154157
* @return {Element}
155158
*/
156159
function removeChildren(node) {
157-
for (let i = 0, length = node.children.length; i < length; i++) {
158-
removeChildren(node.children[i])
160+
let idx = 0
161+
const length = node.children.length
162+
while (idx < length) {
163+
removeChildren(node.children[idx])
164+
idx++
159165
}
160166

161167
return node.element

0 commit comments

Comments
 (0)