-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: there are differences in APIs between 2 and 3
- Loading branch information
Showing
5 changed files
with
24 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import type { ComponentInternalInstance } from 'vue-demi' | ||
import { getCurrentInstance, onBeforeUnmount } from 'vue-demi' | ||
import type { Fn } from '../utils' | ||
import { onBeforeUnmount } from 'vue-demi' | ||
import { type Fn, getLifeCycleTarget } from '../utils' | ||
|
||
/** | ||
* Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing | ||
* | ||
* @param fn | ||
* @param target | ||
*/ | ||
export function tryOnBeforeUnmount(fn: Fn, target?: ComponentInternalInstance | null) { | ||
const instance = target || getCurrentInstance() | ||
export function tryOnBeforeUnmount(fn: Fn, target?: any) { | ||
const instance = getLifeCycleTarget(target) | ||
if (instance) | ||
onBeforeUnmount(fn, instance) | ||
} |
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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
// eslint-disable-next-line no-restricted-imports | ||
import { getCurrentInstance, onUnmounted } from 'vue-demi' | ||
import type { ComponentInternalInstance } from 'vue-demi' | ||
import type { Fn } from '../utils' | ||
import { onUnmounted } from 'vue-demi' | ||
import { type Fn, getLifeCycleTarget } from '../utils' | ||
|
||
/** | ||
* Call onUnmounted() if it's inside a component lifecycle, if not, do nothing | ||
* | ||
* @param fn | ||
* @param target | ||
*/ | ||
export function tryOnUnmounted(fn: Fn, target?: ComponentInternalInstance | null) { | ||
const instance = target || getCurrentInstance() | ||
export function tryOnUnmounted(fn: Fn, target?: any) { | ||
const instance = getLifeCycleTarget(target) | ||
if (instance) | ||
onUnmounted(fn, instance) | ||
} |
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