-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
110 additions
and
134 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"runed": minor | ||
--- | ||
|
||
feat: `useMounted` |
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 was deleted.
Oops, something went wrong.
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,5 +1,6 @@ | ||
export * from "./box/index.js"; | ||
export * from "./useActiveElement/index.js"; | ||
export * from "./useDebounce/index.js"; | ||
export * from "./useElementSize/index.js"; | ||
export * from "./useEventListener/index.js"; | ||
export * from "./box/index.js"; | ||
export * from "./useMounted/index.js"; |
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 @@ | ||
export * from "./useMounted.svelte.js"; |
16 changes: 16 additions & 0 deletions
16
packages/runed/src/lib/functions/useMounted/useMounted.svelte.ts
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,16 @@ | ||
import { untrack } from "svelte"; | ||
import { type ReadableBox, box } from "../box/box.svelte.js"; | ||
|
||
/** | ||
* Returns a box with the mounted state of the component | ||
* that invokes this function. | ||
*/ | ||
export function useMounted(): ReadableBox<boolean> { | ||
const isMounted = box(false); | ||
|
||
$effect(() => { | ||
untrack(() => (isMounted.value = true)); | ||
}); | ||
|
||
return box.readonly(isMounted); | ||
} |
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,52 @@ | ||
--- | ||
title: useMounted | ||
description: A function that returns the mounted state of the component it's called in. | ||
--- | ||
|
||
<script> | ||
import { UseMountedDemo } from '$lib/components/demos'; | ||
</script> | ||
|
||
## Demo | ||
|
||
<UseMountedDemo /> | ||
|
||
## Usage | ||
|
||
```svelte | ||
<script lang="ts"> | ||
import { useMounted } from "runed"; | ||
const isMounted = useMounted(); | ||
</script> | ||
``` | ||
|
||
Which is a shorthand for one of the following: | ||
|
||
```svelte | ||
<script lang="ts"> | ||
import { box } from "runed"; | ||
import { onMount } from "svelte"; | ||
const isMounted = box(false); | ||
onMount(() => { | ||
isMounted.value = true; | ||
}); | ||
</script> | ||
``` | ||
|
||
or | ||
|
||
```svelte | ||
<script lang="ts"> | ||
import { box } from "runed"; | ||
import { untrack } from "svelte"; | ||
const isMounted = box(false); | ||
$effect(() => { | ||
untrack(() => (isMounted.value = true)); | ||
}); | ||
</script> | ||
``` |
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,7 @@ | ||
<script lang="ts"> | ||
import { useMounted } from "runed"; | ||
const isMounted = useMounted(); | ||
</script> | ||
|
||
<p>{isMounted.value ? "mounted" : "not mounted"}</p> |
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