| 2022 | } |
| 2023 | |
| 2024 | function lifecycleMixin (Vue) { |
| 2025 | Vue.prototype._update = function (vnode, hydrating) { |
| 2026 | var vm = this; |
| 2027 | if (vm._isMounted) { |
| 2028 | callHook(vm, 'beforeUpdate'); |
| 2029 | } |
| 2030 | var prevEl = vm.$el; |
| 2031 | var prevVnode = vm._vnode; |
| 2032 | var prevActiveInstance = activeInstance; |
| 2033 | activeInstance = vm; |
| 2034 | vm._vnode = vnode; |
| 2035 | // Vue.prototype.__patch__ is injected in entry points |
| 2036 | // based on the rendering backend used. |
| 2037 | if (!prevVnode) { |
| 2038 | // initial render |
| 2039 | vm.$el = vm.__patch__( |
| 2040 | vm.$el, vnode, hydrating, false /* removeOnly */, |
| 2041 | vm.$options._parentElm, |
| 2042 | vm.$options._refElm |
| 2043 | ); |
| 2044 | } else { |
| 2045 | // updates |
| 2046 | vm.$el = vm.__patch__(prevVnode, vnode); |
| 2047 | } |
| 2048 | activeInstance = prevActiveInstance; |
| 2049 | // update __vue__ reference |
| 2050 | if (prevEl) { |
| 2051 | prevEl.__vue__ = null; |
| 2052 | } |
| 2053 | if (vm.$el) { |
| 2054 | vm.$el.__vue__ = vm; |
| 2055 | } |
| 2056 | // if parent is an HOC, update its $el as well |
| 2057 | if (vm.$vnode && vm.$parent && vm.$vnode === vm.$parent._vnode) { |
| 2058 | vm.$parent.$el = vm.$el; |
| 2059 | } |
| 2060 | // updated hook is called by the scheduler to ensure that children are |
| 2061 | // updated in a parent's updated hook. |
| 2062 | }; |
| 2063 | |
| 2064 | Vue.prototype.$forceUpdate = function () { |
| 2065 | var vm = this; |
| 2066 | if (vm._watcher) { |
| 2067 | vm._watcher.update(); |
| 2068 | } |
| 2069 | }; |
| 2070 | |
| 2071 | Vue.prototype.$destroy = function () { |
| 2072 | var vm = this; |
| 2073 | if (vm._isBeingDestroyed) { |
| 2074 | return |
| 2075 | } |
| 2076 | callHook(vm, 'beforeDestroy'); |
| 2077 | vm._isBeingDestroyed = true; |
| 2078 | // remove self from parent |
| 2079 | var parent = vm.$parent; |
| 2080 | if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) { |
| 2081 | remove(parent.$children, vm); |