Skip to content

Commit

Permalink
fix: useEventHook param is not optional (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtbo committed Oct 17, 2020
1 parent cfbb9da commit 1d2f4f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/vue-apollo-composable/src/useMutation.ts
Expand Up @@ -25,10 +25,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
Expand Up @@ -60,10 +60,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
Expand Up @@ -45,10 +45,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
@@ -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

0 comments on commit 1d2f4f3

Please sign in to comment.