Evan You %!s(int64=12) %!d(string=hai) anos
pai
achega
2e5fc62dcb
Modificáronse 5 ficheiros con 79 adicións e 65 borrados
  1. 1 1
      bower.json
  2. 1 1
      component.json
  3. 76 62
      dist/seed.js
  4. 0 0
      dist/seed.min.js
  5. 1 1
      package.json

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
     "name": "seed",
-    "version": "0.1.3",
+    "version": "0.1.4",
     "main": "dist/seed.js",
     "ignore": [
         ".*",

+ 1 - 1
component.json

@@ -1,6 +1,6 @@
 {
     "name": "seed",
-    "version": "0.1.3",
+    "version": "0.1.4",
     "main": "src/main.js",
     "scripts": [
         "src/main.js",

+ 76 - 62
dist/seed.js

@@ -667,11 +667,12 @@ SeedProto._compileNode = function (node, root) {
     } else if (node.nodeType === 1) {
 
         var eachExp = node.getAttribute(eachAttr),
-            ctrlExp = node.getAttribute(ctrlAttr)
+            ctrlExp = node.getAttribute(ctrlAttr),
+            directive
 
         if (eachExp) { // each block
 
-            var directive = DirectiveParser.parse(eachAttr, eachExp)
+            directive = DirectiveParser.parse(eachAttr, eachExp)
             if (directive) {
                 directive.el = node
                 seed._bind(directive)
@@ -688,21 +689,25 @@ SeedProto._compileNode = function (node, root) {
 
             // parse if has attributes
             if (node.attributes && node.attributes.length) {
-                // forEach vs for loop perf comparison: http://jsperf.com/for-vs-foreach-case
-                // takeaway: not worth it to wrtie manual loops.
-                slice.call(node.attributes).forEach(function (attr) {
-                    if (attr.name === ctrlAttr) return
-                    var valid = false
-                    attr.value.split(',').forEach(function (exp) {
-                        var directive = DirectiveParser.parse(attr.name, exp)
+                var attrs = slice.call(node.attributes),
+                    i = attrs.length, attr, j, valid, exps, exp
+                while (i--) {
+                    attr = attrs[i]
+                    if (attr.name === ctrlAttr) continue
+                    valid = false
+                    exps = attr.value.split(',')
+                    j = exps.length
+                    while (j--) {
+                        exp = exps[j]
+                        directive = DirectiveParser.parse(attr.name, exp)
                         if (directive) {
                             valid = true
                             directive.el = node
                             seed._bind(directive)
                         }
-                    })
+                    }
                     if (valid) node.removeAttribute(attr.name)
-                })
+                }
             }
 
             // recursively compile childNodes
@@ -870,15 +875,16 @@ ScopeProto.$watch = function (key, callback) {
     setTimeout(function () {
         var scope   = self.$seed.scope,
             binding = self.$seed._bindings[key],
+            i       = binding.deps.length,
             watcher = self.$watchers[key] = {
                 refresh: function () {
                     callback(scope[key])
                 },
                 deps: binding.deps
             }
-        binding.deps.forEach(function (dep) {
-            dep.subs.push(watcher)
-        })
+        while (i--) {
+            binding.deps[i].subs.push(watcher)
+        }
     }, 0)
 }
 
@@ -890,9 +896,11 @@ ScopeProto.$unwatch = function (key) {
     setTimeout(function () {
         var watcher = self.$watchers[key]
         if (!watcher) return
-        watcher.deps.forEach(function (dep) {
-            dep.subs.splice(dep.subs.indexOf(watcher))
-        })
+        var i = watcher.deps.length, subs
+        while (i--) {
+            subs = watcher.deps[i].subs
+            subs.splice(subs.indexOf(watcher))
+        }
         delete self.$watchers[key]
     }, 0)
 }
@@ -1153,11 +1161,12 @@ DirProto.apply = function (value) {
  *  pipe the value through filters
  */
 DirProto.applyFilters = function (value) {
-    var filtered = value
-    this.filters.forEach(function (filter) {
+    var filtered = value, filter
+    for (var i = 0, l = this.filters.length; i < l; i++) {
+        filter = this.filters[i]
         if (!filter.apply) throw new Error('Unknown filter: ' + filter.name)
         filtered = filter.apply(filtered, filter.args)
-    })
+    }
     return filtered
 }
 
@@ -1606,10 +1615,11 @@ var config = require('../config')
 var mutationHandlers = {
 
     push: function (m) {
-        var self = this
-        m.args.forEach(function (data, i) {
-            self.buildItem(self.ref, data, self.collection.length + i)
-        })
+        var i, l = m.args.length,
+            baseIndex = this.collection.length - l
+        for (i = 0; i < l; i++) {
+            this.buildItem(this.ref, m.args[i], baseIndex + i)
+        }
     },
 
     pop: function (m) {
@@ -1617,50 +1627,52 @@ var mutationHandlers = {
     },
 
     unshift: function (m) {
-        var self = this
-        m.args.forEach(function (data, i) {
-            var ref  = self.collection.length > m.args.length
-                     ? self.collection[m.args.length].$el
-                     : self.ref
-            self.buildItem(ref, data, i)
-        })
-        self.updateIndexes()
+        var i, l = m.args.length, ref
+        for (i = 0; i < l; i++) {
+            ref = this.collection.length > l
+                ? this.collection[l].$el
+                : this.ref
+            this.buildItem(ref, m.args[i], i)
+        }
+        this.updateIndexes()
     },
 
     shift: function (m) {
         m.result.$destroy()
-        var self = this
-        self.updateIndexes()
+        this.updateIndexes()
     },
 
     splice: function (m) {
-        var self    = this,
+        var i, pos, ref,
+            l = m.args.length,
+            k = m.result.length,
             index   = m.args[0],
             removed = m.args[1],
-            added   = m.args.length - 2
-        m.result.forEach(function (scope) {
-            scope.$destroy()
-        })
+            added   = l - 2
+        for (i = 0; i < k; i++) {
+            m.result[i].$destroy()
+        }
         if (added > 0) {
-            m.args.slice(2).forEach(function (data, i) {
-                var pos  = index - removed + added + 1,
-                    ref  = self.collection[pos]
-                         ? self.collection[pos].$el
-                         : self.ref
-                self.buildItem(ref, index + i)
-            })
+            for (i = 2; i < l; i++) {
+                pos  = index - removed + added + 1
+                ref  = this.collection[pos]
+                     ? this.collection[pos].$el
+                     : this.ref
+                this.buildItem(ref, m.args[i], index + i)
+            }
         }
         if (removed !== added) {
-            self.updateIndexes()
+            this.updateIndexes()
         }
     },
 
     sort: function () {
-        var self = this
-        self.collection.forEach(function (scope, i) {
+        var i, l = this.collection.length, scope
+        for (i = 0; i < l; i++) {
+            scope = this.collection[i]
             scope.$index = i
-            self.container.insertBefore(scope.$el, self.ref)
-        })
+            this.container.insertBefore(scope.$el, this.ref)
+        }
     }
 }
 
@@ -1694,9 +1706,9 @@ module.exports = {
         })
 
         // create child-seeds and append to DOM
-        collection.forEach(function (data, i) {
-            self.buildItem(self.ref, data, i)
-        })
+        for (var i = 0, l = collection.length; i < l; i++) {
+            this.buildItem(this.ref, collection[i], i)
+        }
     },
 
     buildItem: function (ref, data, index) {
@@ -1715,17 +1727,19 @@ module.exports = {
     },
 
     updateIndexes: function () {
-        this.collection.forEach(function (scope, i) {
-            scope.$index = i
-        })
+        var i = this.collection.length
+        while (i--) {
+            this.collection[i].$index = i
+        }
     },
 
     unbind: function (reset) {
         if (this.collection && this.collection.length) {
-            var fn = reset ? '_destroy' : '_unbind'
-            this.collection.forEach(function (scope) {
-                scope.$seed[fn]()
-            })
+            var i = this.collection.length,
+                fn = reset ? '_destroy' : '_unbind'
+            while (i--) {
+                this.collection[i].$seed[fn]()
+            }
             this.collection = null
         }
         var ctn = this.container,
@@ -1817,5 +1831,5 @@ require.alias("component-indexof/index.js", "component-emitter/deps/indexof/inde
 require.alias("seed/src/main.js", "seed/index.js");
 
 window.Seed = window.Seed || require('seed')
-Seed.version = '0.1.3'
+Seed.version = '0.1.4'
 })();

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
dist/seed.min.js


+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
     "name": "seed",
-    "version": "0.1.3",
+    "version": "0.1.4",
     "devDependencies": {
         "grunt": "~0.4.1",
         "grunt-contrib-watch": "~0.4.4",

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio