Skip to content

Commit

Permalink
fix(lifecycle): deactivated should not run on unmounted lifecycle (vu…
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusBorg authored and pikax committed Apr 19, 2020
1 parent 497b7e5 commit a026751
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions src/apis/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ function createLifeCycle(lifeCyclehook: string) {
};
}

function createLifeCycles(lifeCyclehooks: string[], name: string) {
return (callback: Function) => {
const currentVue = getCurrentVue();
const vm = ensureCurrentVMInFn(name);
lifeCyclehooks.forEach(lifeCyclehook =>
injectHookOption(currentVue, vm, lifeCyclehook, callback)
);
};
}

function injectHookOption(Vue: VueConstructor, vm: ComponentInstance, hook: string, val: Function) {
const options = vm.$options as any;
const mergeFn = Vue.config.optionMergeStrategies[hook];
Expand All @@ -33,8 +23,7 @@ export const onMounted = createLifeCycle('mounted');
export const onBeforeUpdate = createLifeCycle('beforeUpdate');
export const onUpdated = createLifeCycle('updated');
export const onBeforeUnmount = createLifeCycle('beforeDestroy');
// only one event will be fired between destroyed and deactivated when an unmount occurs
export const onUnmounted = createLifeCycles(['destroyed', 'deactivated'], genName('unmounted'));
export const onUnmounted = createLifeCycle('destroyed');
export const onErrorCaptured = createLifeCycle('errorCaptured');
export const onActivated = createLifeCycle('activated');
export const onDeactivated = createLifeCycle('deactivated');
Expand Down

0 comments on commit a026751

Please sign in to comment.