Skip to content

Commit

Permalink
♻️ improve DX: useEvent<T>(data?: T)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harley Alexander committed Oct 28, 2019
1 parent b246447 commit 42bb95a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class PusherChannelMock {
/** Initialize PusherChannelMock with callbacks object. */
callbacks: { [name: string]: Function[] };
name: string;
constructor(name: string) {
constructor(name?: string) {
this.callbacks = {};
this.name = name;
this.name = name || "channel";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/useClientTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useClientTrigger<T>(channel: Channel | PresenceChannel<T>) {
const trigger = useCallback(
(eventName: string, data?: any) => {
invariant(eventName, "Must pass event name to trigger a client event.");
channel && channel.trigger(eventName, { data });
channel && channel.trigger(eventName, data);
},
[channel]
);
Expand Down
4 changes: 2 additions & 2 deletions src/useEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { Channel, PresenceChannel, EventCallback } from "pusher-js";
* @param callback Callback to call on a new event
* @param dependencies Dependencies the callback uses.
*/
export function useEvent(
export function useEvent<T>(
channel: Channel | PresenceChannel<any> | undefined,
eventName: string,
callback: EventCallback,
callback: (data?: T) => void,
dependencies: any[] = []
) {
invariant(eventName, "Must supply eventName and callback to onEvent");
Expand Down

0 comments on commit 42bb95a

Please sign in to comment.