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

use more descriptive function names in stack traces

Evan You 11 лет назад
Родитель
Сommit
1efe5dd9b0
6 измененных файлов с 38 добавлено и 46 удалено
  1. 7 7
      src/batcher.js
  2. 8 10
      src/directive.js
  3. 4 6
      src/observer/dep.js
  4. 6 8
      src/observer/index.js
  5. 3 3
      src/util/env.js
  6. 10 12
      src/watcher.js

+ 7 - 7
src/batcher.js

@@ -18,7 +18,7 @@ var internalQueueDepleted = false
  * Reset the batcher's state.
  */
 
-function reset () {
+function resetBatcherState () {
   queue = []
   userQueue = []
   has = {}
@@ -30,11 +30,11 @@ function reset () {
  * Flush both queues and run the watchers.
  */
 
-function flush () {
-  run(queue)
+function flushBatcherQueue () {
+  runBatcherQueue(queue)
   internalQueueDepleted = true
-  run(userQueue)
-  reset()
+  runBatcherQueue(userQueue)
+  resetBatcherState()
 }
 
 /**
@@ -43,7 +43,7 @@ function flush () {
  * @param {Array} queue
  */
 
-function run (queue) {
+function runBatcherQueue (queue) {
   // do not cache length because more watchers might be pushed
   // as we run existing watchers
   for (var i = 0; i < queue.length; i++) {
@@ -92,7 +92,7 @@ exports.push = function (watcher) {
     // queue the flush
     if (!waiting) {
       waiting = true
-      _.nextTick(flush)
+      _.nextTick(flushBatcherQueue)
     }
   }
 }

+ 8 - 10
src/directive.js

@@ -42,8 +42,6 @@ function Directive (name, el, vm, descriptor, def, host) {
   this._bind(def)
 }
 
-var p = Directive.prototype
-
 /**
  * Initialize the directive, mixin definition properties,
  * setup the watcher, call definition bind() and update()
@@ -52,7 +50,7 @@ var p = Directive.prototype
  * @param {Object} def
  */
 
-p._bind = function (def) {
+Directive.prototype._bind = function (def) {
   if (
     (this.name !== 'cloak' || this.vm._isCompiled) &&
     this.el && this.el.removeAttribute
@@ -113,7 +111,7 @@ p._bind = function (def) {
  * e.g. v-component="{{currentView}}"
  */
 
-p._checkDynamicLiteral = function () {
+Directive.prototype._checkDynamicLiteral = function () {
   var expression = this.expression
   if (expression && this.isLiteral) {
     var tokens = textParser.parse(expression)
@@ -137,7 +135,7 @@ p._checkDynamicLiteral = function () {
  * @return {Boolean}
  */
 
-p._checkStatement = function () {
+Directive.prototype._checkStatement = function () {
   var expression = this.expression
   if (
     expression && this.acceptStatement &&
@@ -163,7 +161,7 @@ p._checkStatement = function () {
  * @return {String}
  */
 
-p._checkParam = function (name) {
+Directive.prototype._checkParam = function (name) {
   var param = this.el.getAttribute(name)
   if (param !== null) {
     this.el.removeAttribute(name)
@@ -181,7 +179,7 @@ p._checkParam = function (name) {
  * @public
  */
 
-p.set = function (value) {
+Directive.prototype.set = function (value) {
   /* istanbul ignore else */
   if (this.twoWay) {
     this._withLock(function () {
@@ -202,7 +200,7 @@ p.set = function (value) {
  * @param {Function} fn
  */
 
-p._withLock = function (fn) {
+Directive.prototype._withLock = function (fn) {
   var self = this
   self._locked = true
   fn.call(self)
@@ -220,7 +218,7 @@ p._withLock = function (fn) {
  * @param {Function} handler
  */
 
-p.on = function (event, handler) {
+Directive.prototype.on = function (event, handler) {
   _.on(this.el, event, handler)
   ;(this._listeners || (this._listeners = []))
     .push([event, handler])
@@ -230,7 +228,7 @@ p.on = function (event, handler) {
  * Teardown the watcher and call unbind.
  */
 
-p._teardown = function () {
+Directive.prototype._teardown = function () {
   if (this._bound) {
     this._bound = false
     if (this.unbind) {

+ 4 - 6
src/observer/dep.js

@@ -16,15 +16,13 @@ function Dep () {
 // watcher being evaluated at any time.
 Dep.target = null
 
-var p = Dep.prototype
-
 /**
  * Add a directive subscriber.
  *
  * @param {Directive} sub
  */
 
-p.addSub = function (sub) {
+Dep.prototype.addSub = function (sub) {
   this.subs.push(sub)
 }
 
@@ -34,7 +32,7 @@ p.addSub = function (sub) {
  * @param {Directive} sub
  */
 
-p.removeSub = function (sub) {
+Dep.prototype.removeSub = function (sub) {
   this.subs.$remove(sub)
 }
 
@@ -42,7 +40,7 @@ p.removeSub = function (sub) {
  * Add self as a dependency to the target watcher.
  */
 
-p.depend = function () {
+Dep.prototype.depend = function () {
   Dep.target.addDep(this)
 }
 
@@ -50,7 +48,7 @@ p.depend = function () {
  * Notify all subscribers of a new value.
  */
 
-p.notify = function () {
+Dep.prototype.notify = function () {
   // stablize the subscriber list first
   var subs = _.toArray(this.subs)
   for (var i = 0, l = subs.length; i < l; i++) {

+ 6 - 8
src/observer/index.js

@@ -66,8 +66,6 @@ Observer.create = function (value, vm) {
 
 // Instance methods
 
-var p = Observer.prototype
-
 /**
  * Walk through each property and convert them into
  * getter/setters. This method should only be called when
@@ -77,7 +75,7 @@ var p = Observer.prototype
  * @param {Object} obj
  */
 
-p.walk = function (obj) {
+Observer.prototype.walk = function (obj) {
   var keys = Object.keys(obj)
   var i = keys.length
   var key, prefix
@@ -98,7 +96,7 @@ p.walk = function (obj) {
  * @return {Dep|undefined}
  */
 
-p.observe = function (val) {
+Observer.prototype.observe = function (val) {
   return Observer.create(val)
 }
 
@@ -108,7 +106,7 @@ p.observe = function (val) {
  * @param {Array} items
  */
 
-p.observeArray = function (items) {
+Observer.prototype.observeArray = function (items) {
   var i = items.length
   while (i--) {
     this.observe(items[i])
@@ -123,7 +121,7 @@ p.observeArray = function (items) {
  * @param {*} val
  */
 
-p.convert = function (key, val) {
+Observer.prototype.convert = function (key, val) {
   var ob = this
   var childOb = ob.observe(val)
   var dep = new Dep()
@@ -163,7 +161,7 @@ p.convert = function (key, val) {
  * @param {Vue} vm
  */
 
-p.addVm = function (vm) {
+Observer.prototype.addVm = function (vm) {
   (this.vms || (this.vms = [])).push(vm)
 }
 
@@ -174,7 +172,7 @@ p.addVm = function (vm) {
  * @param {Vue} vm
  */
 
-p.removeVm = function (vm) {
+Observer.prototype.removeVm = function (vm) {
   this.vms.$remove(vm)
 }
 

+ 3 - 3
src/util/env.js

@@ -50,7 +50,7 @@ exports.nextTick = (function () {
   var callbacks = []
   var pending = false
   var timerFunc
-  function handle () {
+  function nextTickHandler () {
     pending = false
     var copies = callbacks.slice(0)
     callbacks = []
@@ -61,7 +61,7 @@ exports.nextTick = (function () {
   /* istanbul ignore if */
   if (typeof MutationObserver !== 'undefined') {
     var counter = 1
-    var observer = new MutationObserver(handle)
+    var observer = new MutationObserver(nextTickHandler)
     var textNode = document.createTextNode(counter)
     observer.observe(textNode, {
       characterData: true
@@ -80,6 +80,6 @@ exports.nextTick = (function () {
     callbacks.push(func)
     if (pending) return
     pending = true
-    timerFunc(handle, 0)
+    timerFunc(nextTickHandler, 0)
   }
 })()

+ 10 - 12
src/watcher.js

@@ -57,15 +57,13 @@ function Watcher (vm, expOrFn, cb, options) {
   this.queued = this.shallow = false
 }
 
-var p = Watcher.prototype
-
 /**
  * Add a dependency to this directive.
  *
  * @param {Dep} dep
  */
 
-p.addDep = function (dep) {
+Watcher.prototype.addDep = function (dep) {
   var newDeps = this.newDeps
   var old = this.deps
   if (_.indexOf(newDeps, dep) < 0) {
@@ -83,7 +81,7 @@ p.addDep = function (dep) {
  * Evaluate the getter, and re-collect dependencies.
  */
 
-p.get = function () {
+Watcher.prototype.get = function () {
   this.beforeGet()
   var vm = this.vm
   var value
@@ -125,7 +123,7 @@ p.get = function () {
  * @param {*} value
  */
 
-p.set = function (value) {
+Watcher.prototype.set = function (value) {
   var vm = this.vm
   if (this.filters) {
     value = vm._applyFilters(
@@ -150,7 +148,7 @@ p.set = function (value) {
  * Prepare for dependency collection.
  */
 
-p.beforeGet = function () {
+Watcher.prototype.beforeGet = function () {
   Dep.target = this
   this.newDeps = []
 }
@@ -159,7 +157,7 @@ p.beforeGet = function () {
  * Clean up for dependency collection.
  */
 
-p.afterGet = function () {
+Watcher.prototype.afterGet = function () {
   Dep.target = null
   var i = this.deps.length
   while (i--) {
@@ -179,7 +177,7 @@ p.afterGet = function () {
  * @param {Boolean} shallow
  */
 
-p.update = function (shallow) {
+Watcher.prototype.update = function (shallow) {
   if (this.lazy) {
     this.dirty = true
   } else if (this.sync || !config.async) {
@@ -207,7 +205,7 @@ p.update = function (shallow) {
  * Will be called by the batcher.
  */
 
-p.run = function () {
+Watcher.prototype.run = function () {
   if (this.active) {
     var value = this.get()
     if (
@@ -250,7 +248,7 @@ p.run = function () {
  * This only gets called for lazy watchers.
  */
 
-p.evaluate = function () {
+Watcher.prototype.evaluate = function () {
   // avoid overwriting another watcher that is being
   // collected.
   var current = Dep.target
@@ -263,7 +261,7 @@ p.evaluate = function () {
  * Depend on all deps collected by this watcher.
  */
 
-p.depend = function () {
+Watcher.prototype.depend = function () {
   var i = this.deps.length
   while (i--) {
     this.deps[i].depend()
@@ -274,7 +272,7 @@ p.depend = function () {
  * Remove self from all dependencies' subcriber list.
  */
 
-p.teardown = function () {
+Watcher.prototype.teardown = function () {
   if (this.active) {
     // remove self from vm's watcher list
     // we can skip this if the vm if being destroyed