Evan You 10 лет назад
Родитель
Сommit
f8e25469ed
3 измененных файлов с 36 добавлено и 7 удалено
  1. 6 0
      src/core/config.js
  2. 11 7
      src/core/observer/scheduler.js
  3. 19 0
      src/entries/web-runtime.js

+ 6 - 0
src/core/config.js

@@ -6,6 +6,7 @@ export type Config = {
   // user
   optionMergeStrategies: { [key: string]: Function },
   silent: boolean,
+  devtools: boolean,
   errorHandler: ?Function,
   ignoredElements: ?Array<string>,
   keyCodes: { [key: string]: number },
@@ -32,6 +33,11 @@ const config: Config = {
    */
   silent: false,
 
+  /**
+   * Whether to enable devtools
+   */
+  devtools: process.env.NODE_ENV !== 'production',
+
   /**
    * Error handler for watcher errors
    */

+ 11 - 7
src/core/observer/scheduler.js

@@ -4,15 +4,14 @@ import type Watcher from './watcher'
 import config from '../config'
 import {
   warn,
-  nextTick
+  nextTick,
+  devtools
 } from '../util/index'
 
-// we have two separate queues: one for directive updates
-// and one for user watcher registered via $watch().
-// we want to guarantee directive updates to be called
-// before user watchers so that when user watchers are
-// triggered, the DOM would have already been in updated
-// state.
+// We have two separate queues: one for internal component re-render updates
+// and one for user watcher registered via $watch(). We want to guarantee
+// re-render updates to be called before user watchers so that when user
+// watchers are triggered, the DOM would already be in updated state.
 
 const queue: Array<Watcher> = []
 const userQueue: Array<Watcher> = []
@@ -44,6 +43,11 @@ function flushSchedulerQueue () {
   if (queue.length) {
     return flushSchedulerQueue()
   }
+  // devtool hook
+  /* istanbul ignore if */
+  if (devtools && config.devtools) {
+    devtools.emit('flush')
+  }
   resetSchedulerState()
 }
 

+ 19 - 0
src/entries/web-runtime.js

@@ -3,6 +3,7 @@
 import Vue from 'core/index'
 import config from 'core/config'
 import { extend, noop } from 'shared/util'
+import { devtools, inBrowser } from 'core/util/index'
 import { patch } from 'web/runtime/patch'
 import platformDirectives from 'web/runtime/directives/index'
 import platformComponents from 'web/runtime/components/index'
@@ -28,4 +29,22 @@ Vue.prototype.$mount = function (
   return this._mount(el && query(el), hydrating)
 }
 
+// devtools global hook
+/* istanbul ignore next */
+setTimeout(() => {
+  if (config.devtools) {
+    if (devtools) {
+      devtools.emit('init', Vue)
+    } else if (
+      process.env.NODE_ENV !== 'production' &&
+      inBrowser && /Chrome\/\d+/.test(window.navigator.userAgent)
+    ) {
+      console.log(
+        'Download the Vue Devtools for a better development experience:\n' +
+        'https://github.com/vuejs/vue-devtools'
+      )
+    }
+  }
+}, 0)
+
 export default Vue