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

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
1. General clean up.
2. Replaced for loops with while loops.
  • Loading branch information
Wobbabits committed Nov 5, 2018
1 parent 89c2e3b commit e8d9d41
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/composi-core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/composi-core.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/composi-core.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@composi/core",
"version": "0.9.3",
"version": "0.9.4",
"description": "A JavaScript library for creating websites, PWAs and hybrid apps.",
"main": "src/index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/h.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export function h(type, props, ...children) {

while (tempBox.length > 0) {
if (Array.isArray((node = tempBox.pop()))) {
for (length = node.length; length-- > 0; ) {
let length = node.length
while (length-- > 0) {
tempBox.push(node[length])
}
} else if (node === false || node === true || node == null) {
Expand Down
11 changes: 7 additions & 4 deletions src/union.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
function safeUnion(types, options) {
const prefix = (options && options.prefix) || ''
const prefixSize = prefix.length
const variants = Object.create(null)
let stripPrefix

if (prefixSize) {
stripPrefix = tag =>
tag &&
Expand All @@ -15,7 +17,7 @@ function safeUnion(types, options) {
}

const matcher = (handlers, catchAll) => {
return function _matcher(tag, context) {
return (tag, context) => {
const tagType = stripPrefix(tag)
const match = hasOwnProperty.call(handlers, tagType) && handlers[tagType]
return match ? match(tag.data, context) : catchAll(context)
Expand All @@ -33,11 +35,12 @@ function safeUnion(types, options) {
}
}

const variants = Object.create(null)
for (let i = 0; i < types.length; i++) {
const type = types[i]
let idx = 0
while (idx < types.length) {
const type = types[idx]
const prefixedType = prefix + type
variants[type] = data => ({ type: prefixedType, data })
idx++
}

return { variants, methods }
Expand Down
18 changes: 12 additions & 6 deletions src/vdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ function createKeyMap(children, startCount, end) {
let key
let vnode

for (; startCount <= end; startCount++) {
while (startCount <= end) {
if ((key = (vnode = children[startCount]).key) != null) {
out[key] = vnode
}
startCount++
}

return out
Expand Down Expand Up @@ -136,9 +137,11 @@ function createElement(vnode, lifecycle, isSVG) {
props['onmount'](element)
})
}

for (let i = 0, length = vnode.children.length; i < length; i++) {
element.appendChild(createElement(vnode.children[i], lifecycle, isSVG))
let idx = 0
const length = vnode.children.length
while (idx < length) {
element.appendChild(createElement(vnode.children[idx], lifecycle, isSVG))
idx++
}

for (let prop in props) {
Expand All @@ -154,8 +157,11 @@ function createElement(vnode, lifecycle, isSVG) {
* @return {Element}
*/
function removeChildren(node) {
for (let i = 0, length = node.children.length; i < length; i++) {
removeChildren(node.children[i])
let idx = 0
const length = node.children.length
while (idx < length) {
removeChildren(node.children[idx])
idx++
}

return node.element
Expand Down

0 comments on commit e8d9d41

Please sign in to comment.