Jinjiang 10 лет назад
Родитель
Сommit
2e8dfe5d9a
4 измененных файлов с 36 добавлено и 32 удалено
  1. 1 0
      flow/component.js
  2. 1 2
      src/core/global-api/extend.js
  3. 3 2
      src/core/instance/index.js
  4. 31 28
      src/core/instance/init.js

+ 1 - 0
flow/component.js

@@ -58,6 +58,7 @@ declare interface Component {
 
   // private methods
   // lifecycle
+  _init: Function;
   _mount: () => Component;
   _update: (vnode: VNode) => void;
   _updateFromParent: (

+ 1 - 2
src/core/global-api/extend.js

@@ -1,7 +1,6 @@
 /* @flow */
 
 import config from '../config'
-import { init } from '../instance/init'
 import { warn, mergeOptions } from '../util/index'
 
 export function initExtend (Vue: GlobalAPI) {
@@ -34,7 +33,7 @@ export function initExtend (Vue: GlobalAPI) {
       }
     }
     const Sub = function VueComponent (options) {
-      init(this, options)
+      this._init(options)
     }
     Sub.prototype = Object.create(Super.prototype)
     Sub.prototype.constructor = Sub

+ 3 - 2
src/core/instance/index.js

@@ -1,13 +1,14 @@
-import { init } from './init'
+import { initMixin } from './init'
 import { stateMixin } from './state'
 import { renderMixin } from './render'
 import { eventsMixin } from './events'
 import { lifecycleMixin } from './lifecycle'
 
 function Vue (options) {
-  init(this, options)
+  this._init(options)
 }
 
+initMixin(Vue)
 stateMixin(Vue)
 eventsMixin(Vue)
 lifecycleMixin(Vue)

+ 31 - 28
src/core/instance/init.js

@@ -9,35 +9,38 @@ import { mergeOptions } from '../util/index'
 
 let uid = 0
 
-export function init (vm: Component, options?: Object) {
-  // a uid
-  vm._uid = uid++
-  // a flag to avoid this being observed
-  vm._isVue = true
-  // merge options
-  if (options && options._isComponent) {
-    // optimize internal component instantiation
-    // since dynamic options merging is pretty slow, and none of the
-    // internal component options needs special treatment.
-    initInternalComponent(vm, options)
-  } else {
-    vm.$options = mergeOptions(
-      vm.constructor.options,
-      options || {},
-      vm
-    )
+export function initMixin (Vue: Class<Component>) {
+  Vue.prototype._init = function (options?: Object) {
+    const vm = this
+    // a uid
+    vm._uid = uid++
+    // a flag to avoid this being observed
+    vm._isVue = true
+    // merge options
+    if (options && options._isComponent) {
+      // optimize internal component instantiation
+      // since dynamic options merging is pretty slow, and none of the
+      // internal component options needs special treatment.
+      initInternalComponent(vm, options)
+    } else {
+      vm.$options = mergeOptions(
+        vm.constructor.options,
+        options || {},
+        vm
+      )
+    }
+    if (process.env.NODE_ENV !== 'production') {
+      initProxy(vm)
+    } else {
+      vm._renderProxy = vm
+    }
+    initLifecycle(vm)
+    initEvents(vm)
+    callHook(vm, 'init')
+    initState(vm)
+    callHook(vm, 'created')
+    initRender(vm)
   }
-  if (process.env.NODE_ENV !== 'production') {
-    initProxy(vm)
-  } else {
-    vm._renderProxy = vm
-  }
-  initLifecycle(vm)
-  initEvents(vm)
-  callHook(vm, 'init')
-  initState(vm)
-  callHook(vm, 'created')
-  initRender(vm)
 }
 
 function initInternalComponent (vm: Component, options: InternalComponentOptions) {