浏览代码

clean up: class and style no longer need args

Evan You 10 年之前
父节点
当前提交
7e405f087b
共有 5 个文件被更改,包括 17 次插入43 次删除
  1. 0 1
      src/compiler/compile.js
  2. 0 2
      src/directive.js
  3. 7 16
      src/directives/internal/class.js
  4. 7 15
      src/directives/internal/el.js
  5. 3 9
      src/directives/internal/style.js

+ 0 - 1
src/compiler/compile.js

@@ -461,7 +461,6 @@ function checkElementDirectives (el, options) {
  */
 
 function checkComponent (el, options) {
-  // TODO handle literal/dynamic
   var component = _.checkComponent(el, options)
   if (component) {
     var descriptor = {

+ 0 - 2
src/directive.js

@@ -23,8 +23,6 @@ var expParser = require('./parsers/expression')
  * @constructor
  */
 
-// TODO: 1.0.0 cleanup the arguments
-
 function Directive (descriptor, vm, el, host, scope, frag) {
   this.vm = vm
   this.el = el

+ 7 - 16
src/directives/internal/class.js

@@ -5,23 +5,14 @@ var removeClass = _.removeClass
 module.exports = {
 
   update: function (value) {
-    if (this.arg) {
-      // single toggle
-      if (value) {
-        addClass(this.el, this.arg)
-      } else {
-        removeClass(this.el, this.arg)
-      }
+    if (value && typeof value === 'string') {
+      this.handleObject(stringToObject(value))
+    } else if (_.isPlainObject(value)) {
+      this.handleObject(value)
+    } else if (_.isArray(value)) {
+      this.handleArray(value)
     } else {
-      if (value && typeof value === 'string') {
-        this.handleObject(stringToObject(value))
-      } else if (_.isPlainObject(value)) {
-        this.handleObject(value)
-      } else if (_.isArray(value)) {
-        this.handleArray(value)
-      } else {
-        this.cleanup()
-      }
+      this.cleanup()
     }
   },
 

+ 7 - 15
src/directives/internal/el.js

@@ -4,20 +4,9 @@ module.exports = {
 
   priority: 1500,
 
-  bind: function () {
-    var scope = this._scope || this.vm
-    var refs = scope.$$
-    var id = this.id = this.arg // bind-el ?
-      ? scope.$eval(this.expression)
-      : this.expression
-
-    if (process.env.NODE_ENV !== 'production' && this.arg) {
-      _.log(
-        'You are using bind- syntax on "el", which is a special ' +
-        'attribute. It will be evaluated only once.'
-      )
-    }
-
+  update: function (id) {
+    this.id = id
+    var refs = (this._scope || this.vm).$$
     if (refs.hasOwnProperty(id)) {
       refs[id] = this.el
     } else {
@@ -26,6 +15,9 @@ module.exports = {
   },
 
   unbind: function () {
-    (this._scope || this.vm).$$[this.id] = null
+    var refs = (this._scope || this.vm).$$
+    if (refs[this.id] !== this.el) {
+      refs[this.id] = null
+    }
   }
 }

+ 3 - 9
src/directives/internal/style.js

@@ -8,17 +8,11 @@ var propCache = {}
 
 module.exports = {
 
-  deep: true,
-
   update: function (value) {
-    if (this.arg) {
-      this.setProp(this.arg, value)
+    if (typeof value === 'object') {
+      this.objectHandler(value)
     } else {
-      if (typeof value === 'object') {
-        this.objectHandler(value)
-      } else {
-        this.el.style.cssText = value
-      }
+      this.el.style.cssText = value
     }
   },