Evan You 10 лет назад
Родитель
Сommit
386a4d6161

+ 3 - 1
src/directive.js

@@ -65,6 +65,7 @@ Directive.prototype._bind = function (def) {
   ) {
     this.el.removeAttribute(config.prefix + this.name)
     // 1.0.0: remove bind/on
+    // TODO simplify this
     if (name === 'attr') {
       this.el.removeAttribute('bind-' + this.arg)
     } else if (name === 'class' || name === 'style') {
@@ -130,6 +131,7 @@ Directive.prototype._bind = function (def) {
  * e.g. v-component="{{currentView}}"
  */
 
+// TODO: we shouldn't need this in 1.0.0.
 Directive.prototype._checkDynamicLiteral = function () {
   var expression = this.expression
   if (expression && this.isLiteral) {
@@ -180,7 +182,7 @@ Directive.prototype._checkStatement = function () {
  * @return {String}
  */
 
-Directive.prototype._checkParam = function (name) {
+Directive.prototype.param = function (name) {
   var param = this.el.getAttribute(name)
   if (param !== null) {
     this.el.removeAttribute(name)

+ 5 - 5
src/directives/component.js

@@ -23,9 +23,9 @@ module.exports = {
       // hiding (v-if) or switching (dynamic literal) it,
       // we simply remove it from the DOM and save it in a
       // cache object, with its constructor id as the key.
-      this.keepAlive = this._checkParam('keep-alive') != null
+      this.keepAlive = this.param('keep-alive') != null
       // wait for event before insertion
-      this.waitForEvent = this._checkParam('wait-for')
+      this.waitForEvent = this.param('wait-for')
 
       if (process.env.NODE_ENV !== 'production') {
         if (this.waitForEvent) {
@@ -34,12 +34,12 @@ module.exports = {
       }
 
       // check ref
-      this.refID = this._checkParam(config.prefix + 'ref')
+      this.refID = this.param(config.prefix + 'ref')
       if (this.keepAlive) {
         this.cache = {}
       }
       // check inline-template
-      if (this._checkParam('inline-template') !== null) {
+      if (this.param('inline-template') !== null) {
         // extract inline template as a DocumentFragment
         this.template = _.extractContent(this.el, true)
       }
@@ -57,7 +57,7 @@ module.exports = {
         // create a ref anchor
         this.anchor = _.createAnchor('v-component')
         _.replace(this.el, this.anchor)
-        this.transMode = this._checkParam('transition-mode')
+        this.transMode = this.param('transition-mode')
       }
     } else {
       process.env.NODE_ENV !== 'production' && _.warn(

+ 6 - 6
src/directives/for.js

@@ -48,21 +48,21 @@ module.exports = {
     _.before(this.start, this.end)
 
     // check for trackby param
-    this.idKey = this._checkParam('track-by')
+    this.idKey = this.param('track-by')
 
     // TODO: only check ref in 1.0.0
     // check v-ref
-    var ref = this._checkParam(config.prefix + 'ref')
+    var ref = this.param(config.prefix + 'ref')
     /* istanbul ignore if */
     if (process.env.NODE_ENV !== 'production') {
       if (this.refID) _.deprecation.V_REF()
     }
-    this.ref = ref || this._checkParam('ref')
+    this.ref = ref || this.param('ref')
 
     // check for transition stagger
-    var stagger = +this._checkParam('stagger')
-    this.enterStagger = +this._checkParam('enter-stagger') || stagger
-    this.leaveStagger = +this._checkParam('leave-stagger') || stagger
+    var stagger = +this.param('stagger')
+    this.enterStagger = +this.param('enter-stagger') || stagger
+    this.leaveStagger = +this.param('leave-stagger') || stagger
 
     // cache
     this.cache = Object.create(null)

+ 2 - 2
src/directives/model/checkbox.js

@@ -5,8 +5,8 @@ module.exports = {
   bind: function () {
     var self = this
     var el = this.el
-    var trueExp = this._checkParam('true-exp')
-    var falseExp = this._checkParam('false-exp')
+    var trueExp = this.param('true-exp')
+    var falseExp = this.param('false-exp')
     var scope = this._scope || this.vm
 
     this._matchValue = function (value) {

+ 2 - 2
src/directives/model/radio.js

@@ -5,8 +5,8 @@ module.exports = {
   bind: function () {
     var self = this
     var el = this.el
-    var number = this._checkParam('number') != null
-    var expression = this._checkParam('exp')
+    var number = this.param('number') != null
+    var expression = this.param('exp')
     var scope = this._scope || this.vm
 
     this.getValue = function () {

+ 2 - 2
src/directives/model/select.js

@@ -16,11 +16,11 @@ module.exports = {
     }
 
     // check options param
-    var optionsParam = this._checkParam('options')
+    var optionsParam = this.param('options')
     if (optionsParam) {
       initOptions.call(this, optionsParam)
     }
-    this.number = this._checkParam('number') != null
+    this.number = this.param('number') != null
     this.multiple = el.hasAttribute('multiple')
 
     // attach listener

+ 3 - 3
src/directives/model/text.js

@@ -9,11 +9,11 @@ module.exports = {
 
     // check params
     // - lazy: update model on "change" instead of "input"
-    var lazy = this._checkParam('lazy') != null
+    var lazy = this.param('lazy') != null
     // - number: cast value into number when updating model.
-    var number = this._checkParam('number') != null
+    var number = this.param('number') != null
     // - debounce: debounce the input listener
-    var debounce = parseInt(this._checkParam('debounce'), 10)
+    var debounce = parseInt(this.param('debounce'), 10)
 
     // handle composition events.
     //   http://blog.evanyou.me/2014/01/03/composition-event/

+ 8 - 8
src/directives/repeat.js

@@ -61,21 +61,21 @@ module.exports = {
       : this.el
 
     // check for trackby param
-    this.idKey = this._checkParam('track-by')
+    this.idKey = this.param('track-by')
     // check for transition stagger
-    var stagger = +this._checkParam('stagger')
-    this.enterStagger = +this._checkParam('enter-stagger') || stagger
-    this.leaveStagger = +this._checkParam('leave-stagger') || stagger
+    var stagger = +this.param('stagger')
+    this.enterStagger = +this.param('enter-stagger') || stagger
+    this.leaveStagger = +this.param('leave-stagger') || stagger
 
     // check for v-ref/v-el
-    this.refID = this._checkParam(config.prefix + 'ref')
-    this.elID = this._checkParam(config.prefix + 'el')
+    this.refID = this.param(config.prefix + 'ref')
+    this.elID = this.param(config.prefix + 'el')
 
     if (process.env.NODE_ENV !== 'production') {
       if (this.refID) _.deprecation.V_REF()
       if (this.elID) _.deprecation.V_EL()
     }
-    this.refID = this.refID || this._checkParam('ref')
+    this.refID = this.refID || this.param('ref')
 
     // check other directives that need to be handled
     // at v-repeat level
@@ -124,7 +124,7 @@ module.exports = {
       this.Component = null
       this.asComponent = true
       // check inline-template
-      if (this._checkParam('inline-template') !== null) {
+      if (this.param('inline-template') !== null) {
         // extract inline template as a DocumentFragment
         this.inlineTemplate = _.extractContent(this.el, true)
       }

+ 2 - 2
src/element-directives/slot.js

@@ -32,8 +32,8 @@ module.exports = {
 
     var context = host._context
     var selector = this.isSlot
-      ? this._checkParam('name')
-      : this._checkParam('select')
+      ? this.param('name')
+      : this.param('select')
 
     if (!selector) {
       // Default content