Explorar o código

move lifecycle hooks into config

Evan You %!s(int64=10) %!d(string=hai) anos
pai
achega
1deceda175
Modificáronse 2 ficheiros con 23 adicións e 12 borrados
  1. 18 0
      src/runtime/config.js
  2. 5 12
      src/runtime/util/options.js

+ 18 - 0
src/runtime/config.js

@@ -27,6 +27,24 @@ export default {
     'transition'
   ],
 
+  /**
+   * List of lifecycle hooks.
+   *
+   * @type {Array}
+   */
+
+  _lifecycleHooks: [
+    'init',
+    'created',
+    'beforeMount',
+    'mounted',
+    'ready',
+    'beforeUpdate',
+    'updated',
+    'beforeDestroy',
+    'destroyed'
+  ],
+
   /**
    * Max circular updates allowed in a batcher flush cycle.
    */

+ 5 - 12
src/runtime/util/options.js

@@ -121,18 +121,7 @@ strats.el = function (parentVal, childVal, vm) {
  * Hooks and param attributes are merged as arrays.
  */
 
-strats.init =
-strats.created =
-strats.ready =
-strats.attached =
-strats.detached =
-strats.beforeMount =
-strats.mounted =
-strats.beforeUpdate =
-strats.updated =
-strats.beforeDestroy =
-strats.destroyed =
-strats.activate = function (parentVal, childVal) {
+function mergeHook (parentVal, childVal) {
   return childVal
     ? parentVal
       ? parentVal.concat(childVal)
@@ -142,6 +131,10 @@ strats.activate = function (parentVal, childVal) {
     : parentVal
 }
 
+config._lifecycleHooks.forEach(hook => {
+  strats[hook] = mergeHook
+})
+
 /**
  * Assets
  *