forked from vitest-dev/vitest
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tryOnBeforeUnmount): new function (vitest-dev#709)
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
category: Component | ||
--- | ||
|
||
# tryOnUnmounted | ||
|
||
Safe `onBeforeUnmount`. Call `onBeforeUnmount()` if it's inside a component lifecycle, if not, do nothing | ||
|
||
## Usage | ||
|
||
```js | ||
import { tryOnBeforeUnmount } from '@vueuse/core' | ||
|
||
tryOnBeforeUnmount(() => { | ||
|
||
}) | ||
``` | ||
|
||
|
||
<!--FOOTER_STARTS--> | ||
## Type Declarations | ||
|
||
```typescript | ||
/** | ||
* Call onUnmounted() if it's inside a component lifecycle, if not, do nothing | ||
* | ||
* @param fn | ||
*/ | ||
export declare function tryOnBeforeUnmount(fn: Fn): void | ||
``` | ||
|
||
## Source | ||
|
||
[Source](https://github.com/vueuse/vueuse/blob/main/packages/shared/tryOnBeforeUnmount/index.ts) • [Docs](https://github.com/vueuse/vueuse/blob/main/packages/shared/tryOnBeforeUnmount/index.md) | ||
|
||
|
||
<!--FOOTER_ENDS--> |
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,12 @@ | ||
import { getCurrentInstance, onBeforeUnmount } from 'vue-demi' | ||
import { Fn } from '../utils' | ||
|
||
/** | ||
* Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing | ||
* | ||
* @param fn | ||
*/ | ||
export function tryOnBeforeUnmount(fn: Fn) { | ||
if (getCurrentInstance()) | ||
onBeforeUnmount(fn) | ||
} |