Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4: mark useEventHook param as not optional #1027

Merged
merged 1 commit into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vue-apollo-composable/src/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export interface UseMutationReturn<TResult, TVariables> {
loading: Ref<boolean>
error: Ref<Error>
called: Ref<boolean>
onDone: (fn: (param?: FetchResult<TResult, Record<string, any>, Record<string, any>>) => void) => {
onDone: (fn: (param: FetchResult<TResult, Record<string, any>, Record<string, any>>) => void) => {
off: () => void
};
onError: (fn: (param?: Error) => void) => {
onError: (fn: (param: Error) => void) => {
off: () => void
};
};
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-apollo-composable/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ export interface UseQueryReturn<TResult, TVariables> {
refetch: (variables?: TVariables) => Promise<ApolloQueryResult<TResult>>
fetchMore: <K extends keyof TVariables>(options: FetchMoreQueryOptions<TVariables, K> & FetchMoreOptions<TResult, TVariables>) => Promise<ApolloQueryResult<TResult>>
subscribeToMore: <TSubscriptionVariables = OperationVariables, TSubscriptionData = TResult>(options: SubscribeToMoreOptions<TResult, TSubscriptionVariables, TSubscriptionData> | Ref<SubscribeToMoreOptions<TResult, TSubscriptionVariables, TSubscriptionData>> | ReactiveFunction<SubscribeToMoreOptions<TResult, TSubscriptionVariables, TSubscriptionData>>) => void
onResult: (fn: (param?: ApolloQueryResult<TResult>) => void) => {
onResult: (fn: (param: ApolloQueryResult<TResult>) => void) => {
off: () => void
}
onError: (fn: (param?: Error) => void) => {
onError: (fn: (param: Error) => void) => {
off: () => void
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-apollo-composable/src/useSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export interface UseSubscriptionReturn<TResult, TVariables> {
variables: Ref<TVariables>
options: UseSubscriptionOptions<TResult, TVariables> | Ref<UseSubscriptionOptions<TResult, TVariables>>
subscription: Ref<Observable<FetchResult<TResult, Record<string, any>, Record<string, any>>>>
onResult: (fn: (param?: FetchResult<TResult, Record<string, any>, Record<string, any>>) => void) => {
onResult: (fn: (param: FetchResult<TResult, Record<string, any>, Record<string, any>>) => void) => {
off: () => void
}
onError: (fn: (param?: Error) => void) => {
onError: (fn: (param: Error) => void) => {
off: () => void
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/vue-apollo-composable/src/util/useEventHook.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
export function useEventHook<TParam = any> () {
const fns: ((param?: TParam) => void)[] = []
const fns: ((param: TParam) => void)[] = []

function on (fn: (param?: TParam) => void) {
function on (fn: (param: TParam) => void) {
fns.push(fn)
return {
off: () => off(fn),
}
}

function off (fn: (param?: TParam) => void) {
function off (fn: (param: TParam) => void) {
const index = fns.indexOf(fn)
if (index !== -1) {
fns.splice(index, 1)
}
}

function trigger (param?: TParam) {
function trigger (param: TParam) {
for (const fn of fns) {
fn(param)
}
Expand Down