Skip to content

Commit

Permalink
shave off a few bytes with forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 7, 2014
1 parent d75ee62 commit e37b151
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
20 changes: 7 additions & 13 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ function Compiler (vm, options) {
compiler.compile(el, true)

// bind deferred directives (child components)
for (var i = 0, l = compiler.deferred.length; i < l; i++) {
compiler.bindDirective(compiler.deferred[i])
}
compiler.deferred.forEach(compiler.bindDirective, compiler)

// extract dependencies for computed properties
compiler.parseDeps()
Expand Down Expand Up @@ -288,7 +286,7 @@ CompilerProto.compile = function (node, root) {
}

// v-with has 2nd highest priority
} else if (!root && ((withKey = utils.attr(node, 'with')) || componentCtor)) {
} else if (root !== true && ((withKey = utils.attr(node, 'with')) || componentCtor)) {

directive = Directive.parse('with', withKey || '', compiler, node)
if (directive) {
Expand Down Expand Up @@ -369,10 +367,7 @@ CompilerProto.compileNode = function (node) {
}
// recursively compile childNodes
if (node.childNodes.length) {
var nodes = slice.call(node.childNodes)
for (i = 0, j = nodes.length; i < j; i++) {
this.compile(nodes[i])
}
slice.call(node.childNodes).forEach(this.compile, this)
}
}

Expand All @@ -387,7 +382,7 @@ CompilerProto.compileTextNode = function (node) {

for (var i = 0, l = tokens.length; i < l; i++) {
token = tokens[i]
directive = null
directive = partialNodes = null
if (token.key) { // a binding
if (token.key.charAt(0) === '>') { // a partial
partialId = token.key.slice(1).trim()
Expand All @@ -413,6 +408,8 @@ CompilerProto.compileTextNode = function (node) {

// insert node
node.parentNode.insertBefore(el, node)

// bind directive
if (directive) {
this.bindDirective(directive)
}
Expand All @@ -421,10 +418,7 @@ CompilerProto.compileTextNode = function (node) {
// will change from the fragment to the correct parentNode.
// This could affect directives that need access to its element's parentNode.
if (partialNodes) {
for (var j = 0, k = partialNodes.length; j < k; j++) {
this.compile(partialNodes[j])
}
partialNodes = null
partialNodes.forEach(this.compile, this)
}

}
Expand Down
3 changes: 1 addition & 2 deletions src/deps-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ module.exports = {
parse: function (bindings) {
utils.log('\nparsing dependencies...')
Observer.shouldGet = true
var i = bindings.length
while (i--) { catchDeps(bindings[i]) }
bindings.forEach(catchDeps)
Observer.shouldGet = false
utils.log('\ndone.')
}
Expand Down
3 changes: 1 addition & 2 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ function Directive (definition, expression, rawKey, compiler, node) {
var filterExps = this.expression.slice(rawKey.length).match(FILTERS_RE)
if (filterExps) {
this.filters = []
var i = 0, l = filterExps.length, filter
for (; i < l; i++) {
for (var i = 0, l = filterExps.length, filter; i < l; i++) {
filter = parseFilter(filterExps[i], this.compiler)
if (filter) this.filters.push(filter)
}
Expand Down
9 changes: 2 additions & 7 deletions src/directives/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ var mutationHandlers = {
},

unshift: function (m) {
var i, l = m.args.length
for (i = 0; i < l; i++) {
this.buildItem(m.args[i], i)
}
m.args.forEach(this.buildItem, this)
},

shift: function () {
Expand Down Expand Up @@ -144,9 +141,7 @@ module.exports = {

// create child-vms and append to DOM
if (collection.length) {
for (var i = 0, l = collection.length; i < l; i++) {
this.buildItem(collection[i], i)
}
collection.forEach(this.buildItem, this)
if (!init) this.changed()
}
},
Expand Down

0 comments on commit e37b151

Please sign in to comment.