-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added implementation of $destroy to Vue object and called it in compo…
…nentWillUnmount of ReactVueComponent Fixes #163
- Loading branch information
Rishabh Karnad
committed
Aug 20, 2019
1 parent
5f1eb34
commit 7a1144c
Showing
6 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Vue from 'core/index' | ||
|
||
import { lifeCycleMixin } from './lifeCycle'; | ||
import { renderMixin } from './render'; | ||
|
||
lifeCycleMixin(Vue) | ||
renderMixin(Vue) | ||
|
||
export default Vue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// @flow | ||
|
||
import { remove } from 'core/util/index' | ||
|
||
export function lifeCycleMixin (Vue: Class<Component>) { | ||
Vue.prototype.$destroy = function (fn: Function) { | ||
const vm: Component = this | ||
if (vm._isBeingDestroyed) { | ||
return | ||
} | ||
// callHook(vm, 'beforeDestroy') | ||
vm._isBeingDestroyed = true | ||
// remove self from parent | ||
const parent = vm.$parent | ||
if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) { | ||
remove(parent.$children, vm) | ||
} | ||
// teardown watchers | ||
if (vm._watcher) { | ||
vm._watcher.teardown() | ||
} | ||
let i = vm._watchers.length | ||
while (i--) { | ||
vm._watchers[i].teardown() | ||
} | ||
// remove reference from data ob | ||
// frozen object may not have observer. | ||
if (vm._data.__ob__) { | ||
vm._data.__ob__.vmCount-- | ||
} | ||
// call the last hook... | ||
vm._isDestroyed = true | ||
// invoke destroy hooks on current rendered tree | ||
// vm.__patch__(vm._vnode, null) | ||
// fire destroyed hook | ||
// callHook(vm, 'destroyed') | ||
// turn off all instance listeners. | ||
vm.$off() | ||
// remove __vue__ reference | ||
if (vm.$el) { | ||
vm.$el.__vue__ = null | ||
} | ||
// remove reference to DOM nodes (prevents leak) | ||
vm.$options._parentElm = vm.$options._refElm = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @flow | ||
|
||
import { nextTick } from 'core/util/index' | ||
|
||
export function renderMixin (Vue: Class<Component>) { | ||
Vue.prototype.$nextTick = function (fn: Function) { | ||
return nextTick(fn, this) | ||
} | ||
} |