-
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: pause DOM patching while transitioning
Signed-off-by: Fernando Fernández <ferferga@hotmail.com>
- Loading branch information
Showing
3 changed files
with
29 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { getCurrentScope, toRef, watch, type MaybeRefOrGetter } from 'vue'; | ||
|
||
/** | ||
* When the passed argument is truthy, the effect scope of the current component will be paused | ||
* until the argument becomes falsy again. | ||
* | ||
* This is useful for components that need to pause the DOM patching | ||
*/ | ||
export function usePausableEffect(signal: MaybeRefOrGetter<boolean>) { | ||
const scope = getCurrentScope(); | ||
|
||
if (scope) { | ||
watch(toRef(signal), val => val ? scope.pause() : scope.resume(), { immediate: true, flush: 'sync' }); | ||
} | ||
} |