1234567891011121314151617181920212223242526272829 |
- // Utilities
- import { effectScope, onScopeDispose, watch } from 'vue';
- // Types
- export function useToggleScope(source, fn) {
- let scope;
- function start() {
- scope = effectScope();
- scope.run(() => fn.length ? fn(() => {
- scope?.stop();
- start();
- }) : fn());
- }
- watch(source, active => {
- if (active && !scope) {
- start();
- } else if (!active) {
- scope?.stop();
- scope = undefined;
- }
- }, {
- immediate: true
- });
- onScopeDispose(() => {
- scope?.stop();
- });
- }
- //# sourceMappingURL=toggleScope.mjs.map
|