فهرست منبع

return this in api methods

Evan You 11 سال پیش
والد
کامیت
e162d67532
3فایلهای تغییر یافته به همراه17 افزوده شده و 3 حذف شده
  1. 5 0
      src/api/dom.js
  2. 11 3
      src/api/events.js
  3. 1 0
      src/api/lifecycle.js

+ 5 - 0
src/api/dom.js

@@ -16,6 +16,7 @@ exports.$appendTo = function (target, cb, withTransition) {
     ? append
     : transition.append
   insert(this, target, op, targetIsDetached, cb)
+  return this
 }
 
 /**
@@ -33,6 +34,7 @@ exports.$prependTo = function (target, cb, withTransition) {
   } else {
     this.$appendTo(target, cb, withTransition)
   }
+  return this
 }
 
 /**
@@ -50,6 +52,7 @@ exports.$before = function (target, cb, withTransition) {
     ? before
     : transition.before
   insert(this, target, op, targetIsDetached, cb)
+  return this
 }
 
 /**
@@ -67,6 +70,7 @@ exports.$after = function (target, cb, withTransition) {
   } else {
     this.$appendTo(target.parentNode, cb, withTransition)
   }
+  return this
 }
 
 /**
@@ -101,6 +105,7 @@ exports.$remove = function (cb, withTransition) {
       : transition.remove
     op(this.$el, this, realCb)
   }
+  return this
 }
 
 /**

+ 11 - 3
src/api/events.js

@@ -11,6 +11,7 @@ exports.$on = function (event, fn) {
   (this._events[event] || (this._events[event] = []))
     .push(fn)
   modifyListenerCount(this, event, 1)
+  return this
 }
 
 /**
@@ -29,6 +30,7 @@ exports.$once = function (event, fn) {
   }
   on.fn = fn
   this.$on(event, on)
+  return this
 }
 
 /**
@@ -52,15 +54,17 @@ exports.$off = function (event, fn) {
       }
     }
     this._events = {}
-    return
+    return this
   }
   // specific event
   cbs = this._events[event]
-  if (!cbs) return
+  if (!cbs) {
+    return this
+  }
   if (arguments.length === 1) {
     modifyListenerCount(this, event, -cbs.length)
     this._events[event] = null
-    return
+    return this
   }
   // specific handler
   var cb
@@ -73,6 +77,7 @@ exports.$off = function (event, fn) {
       break
     }
   }
+  return this
 }
 
 /**
@@ -102,6 +107,7 @@ exports.$emit = function (event) {
       }
     }
   }
+  return this
 }
 
 /**
@@ -125,6 +131,7 @@ exports.$broadcast = function (event) {
       }
     }
   }
+  return this
 }
 
 /**
@@ -142,6 +149,7 @@ exports.$dispatch = function () {
       ? null
       : parent.$parent
   }
+  return this
 }
 
 /**

+ 1 - 0
src/api/lifecycle.js

@@ -36,6 +36,7 @@ exports.$mount = function (el) {
     this._initDOMHooks()
     this.$once('hook:attached', ready)
   }
+  return this
 }
 
 /**