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

fix: update Methods addContextListener to support new signature #462

Merged
merged 4 commits into from
Oct 7, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/api/Methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ export function addIntentListener(intent: string, handler: ContextHandler): List
return throwIfNoGlobal(() => window.fdc3.addIntentListener(intent, handler));
}

export function addContextListener(contextTypeOrHandler: string | ContextHandler, handler?: ContextHandler): Listener {
export function addContextListener(
contextTypeOrHandler: string | null | ContextHandler,
handler?: ContextHandler
): Listener {
//Handle (deprecated) function signature that allowed contextType argument to be omitted
if (typeof contextTypeOrHandler !== 'function') {
mattjamieson marked this conversation as resolved.
Show resolved Hide resolved
return throwIfNoGlobal(() =>
window.fdc3.addContextListener(contextTypeOrHandler as string, handler as ContextHandler)
);
return throwIfNoGlobal(() => window.fdc3.addContextListener(contextTypeOrHandler, handler as ContextHandler));
} else {
return throwIfNoGlobal(() => window.fdc3.addContextListener(contextTypeOrHandler as ContextHandler));
return throwIfNoGlobal(() => window.fdc3.addContextListener(null, contextTypeOrHandler as ContextHandler));
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/Methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('test ES6 module', () => {

expect(window.fdc3.addContextListener).toHaveBeenCalledTimes(2);
expect(window.fdc3.addContextListener).toHaveBeenNthCalledWith(1, type, handler1);
expect(window.fdc3.addContextListener).toHaveBeenNthCalledWith(2, handler2);
expect(window.fdc3.addContextListener).toHaveBeenNthCalledWith(2, null, handler2);
});

test('getSystemChannels should delegate to window.fdc3.getSystemChannels', async () => {
Expand Down