Skip to content

Commit

Permalink
refactor: inline extractAttrs
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Aug 30, 2017
1 parent 4638a89 commit 19360fe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 35 deletions.
26 changes: 8 additions & 18 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,6 @@

}

/**
* Converts attributes into key-value pairs
* @param {Node} node
* @return {Object} Key-Value pairs of Attributes
*/
var extractAttrs = function(node) {
var rawAttrs = node.attributes;
var attrs = {};
for(var i = 0; i < rawAttrs.length; i++) {
attrs[rawAttrs[i].name] = rawAttrs[i].value;
}
return attrs;
}


/**
* Adds An Event Handler to a Type of Listener
* @param {Object} node
Expand Down Expand Up @@ -758,7 +743,12 @@

// Diff props
var props = vnode.props;
diffProps(node, extractAttrs(node), vnode, props);
var rawNodeAttrs = node.attributes;
var nodeAttrs = {};
for(var i = 0; i < rawNodeAttrs.length; i++) {
nodeAttrs[rawNodeAttrs[i].name] = rawNodeAttrs[i].value;
}
diffProps(node, nodeAttrs, vnode, props);

// Add event listeners
var eventListeners = meta.eventListeners;
Expand All @@ -772,7 +762,7 @@
var children = vnode.children;
var length = children.length;

var i = 0;
var i$1 = 0;
var currentChildNode = node.firstChild;
var vchild = length !== 0 ? children[0] : undefined;
var nextSibling = null;
Expand All @@ -791,7 +781,7 @@
}
}

vchild = ++i < length ? children[i] : undefined;
vchild = ++i$1 < length ? children[i$1] : undefined;
currentChildNode = nextSibling;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/moon.min.js

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions src/util/dom.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/**
* Converts attributes into key-value pairs
* @param {Node} node
* @return {Object} Key-Value pairs of Attributes
*/
const extractAttrs = function(node) {
let rawAttrs = node.attributes;
let attrs = {};
for(let i = 0; i < rawAttrs.length; i++) {
attrs[rawAttrs[i].name] = rawAttrs[i].value;
}
return attrs;
}


/**
* Adds An Event Handler to a Type of Listener
* @param {Object} node
Expand Down
7 changes: 6 additions & 1 deletion src/util/vdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,12 @@ const hydrate = function(node, vnode, parent) {

// Diff props
let props = vnode.props;
diffProps(node, extractAttrs(node), vnode, props);
let rawNodeAttrs = node.attributes;
let nodeAttrs = {};
for(let i = 0; i < rawNodeAttrs.length; i++) {
nodeAttrs[rawNodeAttrs[i].name] = rawNodeAttrs[i].value;
}
diffProps(node, nodeAttrs, vnode, props);

// Add event listeners
let eventListeners = meta.eventListeners;
Expand Down

0 comments on commit 19360fe

Please sign in to comment.