Skip to content

Commit 47d7067

Browse files
authored
Merge pull request #462 from whitedogio/fix/435
fix: update Methods addContextListener to support new signature
2 parents 2b22f9e + f35f906 commit 47d7067

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/api/Methods.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ export function addIntentListener(intent: string, handler: ContextHandler): List
6767
return throwIfNoGlobal(() => window.fdc3.addIntentListener(intent, handler));
6868
}
6969

70-
export function addContextListener(contextTypeOrHandler: string | ContextHandler, handler?: ContextHandler): Listener {
70+
export function addContextListener(
71+
contextTypeOrHandler: string | null | ContextHandler,
72+
handler?: ContextHandler
73+
): Listener {
74+
//Handle (deprecated) function signature that allowed contextType argument to be omitted
7175
if (typeof contextTypeOrHandler !== 'function') {
72-
return throwIfNoGlobal(() =>
73-
window.fdc3.addContextListener(contextTypeOrHandler as string, handler as ContextHandler)
74-
);
76+
return throwIfNoGlobal(() => window.fdc3.addContextListener(contextTypeOrHandler, handler as ContextHandler));
7577
} else {
76-
return throwIfNoGlobal(() => window.fdc3.addContextListener(contextTypeOrHandler as ContextHandler));
78+
return throwIfNoGlobal(() => window.fdc3.addContextListener(null, contextTypeOrHandler as ContextHandler));
7779
}
7880
}
7981

test/Methods.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ describe('test ES6 module', () => {
184184

185185
expect(window.fdc3.addContextListener).toHaveBeenCalledTimes(2);
186186
expect(window.fdc3.addContextListener).toHaveBeenNthCalledWith(1, type, handler1);
187-
expect(window.fdc3.addContextListener).toHaveBeenNthCalledWith(2, handler2);
187+
expect(window.fdc3.addContextListener).toHaveBeenNthCalledWith(2, null, handler2);
188188
});
189189

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

0 commit comments

Comments
 (0)