Просмотр исходного кода

remove object handling in attr binding

Evan You 10 лет назад
Родитель
Сommit
88aba5ffd8
2 измененных файлов с 1 добавлено и 48 удалено
  1. 1 29
      src/directives/internal/attr.js
  2. 0 19
      test/unit/specs/directives/internal/attr_spec.js

+ 1 - 29
src/directives/internal/attr.js

@@ -23,35 +23,7 @@ module.exports = {
   priority: 850,
 
   update: function (value) {
-    if (this.arg) {
-      this.setAttr(this.arg, value)
-    } else if (typeof value === 'object') {
-      // TODO no longer need to support object in 1.0.0
-      this.objectHandler(value)
-    }
-  },
-
-  objectHandler: function (value) {
-    // cache object attrs so that only changed attrs
-    // are actually updated.
-    var cache = this.cache || (this.cache = {})
-    var attr, val
-    for (attr in cache) {
-      if (!(attr in value)) {
-        this.setAttr(attr, null)
-        delete cache[attr]
-      }
-    }
-    for (attr in value) {
-      val = value[attr]
-      if (val !== cache[attr]) {
-        cache[attr] = val
-        this.setAttr(attr, val)
-      }
-    }
-  },
-
-  setAttr: function (attr, value) {
+    var attr = this.arg
     if (inputProps[attr] && attr in this.el) {
       if (!this.valueRemoved) {
         this.el.removeAttribute(attr)

+ 0 - 19
test/unit/specs/directives/internal/attr_spec.js

@@ -51,24 +51,5 @@ if (_.inBrowser) {
       dir.update(null)
       expect(el.hasAttributeNS(xlinkNS, 'special')).toBe(false)
     })
-
-    it('object and xlink', function () {
-      var xlinkNS = 'http://www.w3.org/1999/xlink'
-      var obj1 = {special: 'ok', test: 'again'}
-      var obj2 = {'xlink:href': '#', test: 'ok', empty: null}
-      dir.update(obj2)
-      expect(el.getAttributeNS(xlinkNS, 'href')).toBe('#')
-      expect(el.getAttribute('test')).toBe('ok')
-      expect(el.hasAttribute('empty')).toBe(false)
-      dir.update(obj1)
-      expect(el.hasAttributeNS(xlinkNS, 'href')).toBe(false)
-      expect(el.getAttribute('special')).toBe('ok')
-      expect(el.getAttribute('test')).toBe('again')
-      obj1.test = null
-      dir.update(obj1)
-      expect(el.hasAttribute('test')).toBe(false)
-      dir.update(obj2)
-      expect(el.getAttributeNS(xlinkNS, 'href')).toBe('#')
-    })
   })
 }