Skip to content

Commit

Permalink
test: use scope dispose more
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Aug 29, 2024
1 parent 2fa78f6 commit 9ef223b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/helpers/useButtonHold/useButtonHold.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MaybeRefOrGetter, onBeforeUnmount, toValue } from 'vue';
import { MaybeRefOrGetter, toValue } from 'vue';
import { tryOnScopeDispose } from '../../utils/common';

export interface ButtonHoldOptions {
onHoldTick: () => void;
Expand Down Expand Up @@ -55,7 +56,7 @@ export function useButtonHold(opts: ButtonHoldOptions) {
onMousedown,
};

onBeforeUnmount(() => {
tryOnScopeDispose(() => {
document.removeEventListener('mouseup', onMouseup);
clearAll();
});
Expand Down
17 changes: 3 additions & 14 deletions packages/core/src/useFormField/useFormField.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import {
computed,
inject,
MaybeRefOrGetter,
nextTick,
onBeforeUnmount,
readonly,
Ref,
shallowRef,
toValue,
watch,
} from 'vue';
import { computed, inject, MaybeRefOrGetter, nextTick, readonly, Ref, shallowRef, toValue, watch } from 'vue';
import { FormContext, FormKey } from '../useForm/useForm';
import { Arrayable, Getter, TypedSchema, ValidationResult } from '../types';
import { useSyncModel } from '../reactivity/useModelSync';
import { cloneDeep, isEqual, normalizeArrayable } from '../utils/common';
import { cloneDeep, isEqual, normalizeArrayable, tryOnScopeDispose } from '../utils/common';
import { FormGroupKey } from '../useFormGroup';

interface FormFieldOptions<TValue = unknown> {
Expand Down Expand Up @@ -130,7 +119,7 @@ export function useFormField<TValue = unknown>(opts?: Partial<FormFieldOptions<T
setTouched(true);
});

onBeforeUnmount(() => {
tryOnScopeDispose(() => {
const path = getPath();
if (!path) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentInternalInstance, nextTick, onBeforeUnmount } from 'vue';
import { isSSR, useUniqId } from './common';
import { isSSR, tryOnScopeDispose, useUniqId } from './common';
import { NOOP } from '../constants';

export function createEventDispatcher<TPayload>(eventName?: string) {
Expand Down Expand Up @@ -32,7 +32,7 @@ export function createEventDispatcher<TPayload>(eventName?: string) {
return removeListener;
}

onBeforeUnmount(() => {
tryOnScopeDispose(() => {
controller.abort();
});

Expand Down

0 comments on commit 9ef223b

Please sign in to comment.