فهرست منبع

100% coverage for utils

Evan You 12 سال پیش
والد
کامیت
4ac355b1d1
4فایلهای تغییر یافته به همراه25 افزوده شده و 24 حذف شده
  1. 4 4
      src/directive.js
  2. 4 0
      src/instance/element.js
  3. 12 13
      src/util/env.js
  4. 5 7
      src/util/lang.js

+ 4 - 4
src/directive.js

@@ -147,10 +147,10 @@ p._initFilters = function () {
  */
 
 p._initDeps = function (paths) {
-  var self = this
-  paths.forEach(function (path) {
-    self._addDep(path)
-  })
+  var i = paths.length
+  while (i--) {
+    this._addDep(paths[i])
+  }
   this._deps = this._newDeps
 }
 

+ 4 - 0
src/instance/element.js

@@ -12,7 +12,11 @@ var templateParser = require('../parse/template')
 
 exports._initElement = function (el) {
   if (typeof el === 'string') {
+    var selector = el
     el = document.querySelector(el)
+    if (!el) {
+      _.warn('Cannot find element: ' + selector)
+    }
   }
   // If the passed in `el` is a DocumentFragment, the instance is
   // considered a "block instance" which manages not a single element,

+ 12 - 13
src/util/env.js

@@ -38,20 +38,19 @@ exports.isIE9 =
 
 var testElement = inBrowser
   ? document.createElement('div')
-  : null
+  : undefined
 
 exports.transitionEndEvent = (function () {
-  if (!inBrowser) {
-    return null
-  }
-  var map = {
-    'webkitTransition' : 'webkitTransitionEnd',
-    'transition'       : 'transitionend',
-    'mozTransition'    : 'transitionend'
-  }
-  for (var prop in map) {
-    if (testElement.style[prop] !== undefined) {
-      return map[prop]
+  if (inBrowser) {
+    var map = {
+      'webkitTransition' : 'webkitTransitionEnd',
+      'transition'       : 'transitionend',
+      'mozTransition'    : 'transitionend'
+    }
+    for (var prop in map) {
+      if (testElement.style[prop] !== undefined) {
+        return map[prop]
+      }
     }
   }
 })()
@@ -60,4 +59,4 @@ exports.animationEndEvent = inBrowser
   ? testElement.style.animation !== undefined
     ? 'animationend'
     : 'webkitAnimationEnd'
-  : null
+  : undefined

+ 5 - 7
src/util/lang.js

@@ -123,10 +123,8 @@ exports.define = function (obj, key, val, enumerable) {
  * @param {Object} proto
  */
 
-if ('__proto__' in {}) {
-  exports.augment = function (target, proto) {
-    target.__proto__ = proto
-  }
-} else {
-  exports.augment = exports.deepMixin
-}
+exports.augment = '__proto__' in {}
+  ? function (target, proto) {
+      target.__proto__ = proto
+    }
+  : exports.deepMixin