Total Complexity | 6 |
Complexity/F | 1.2 |
Lines of Code | 23 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
1 | import { EventSourcePolyfill as EventSource } from 'event-source-polyfill'; |
||
2 | |||
3 | 32 | export const bindToMercureTopic = (mercureInfo, topic, onMessage, onTokenExpired) => () => { |
|
4 | 4 | const { mercureHubUrl, token, loading, error } = mercureInfo; |
|
5 | |||
6 | 4 | if (loading || error) { |
|
7 | 3 | return undefined; |
|
8 | } |
||
9 | |||
10 | 1 | const hubUrl = new URL(mercureHubUrl); |
|
|
|||
11 | |||
12 | 1 | hubUrl.searchParams.append('topic', topic); |
|
13 | 1 | const es = new EventSource(hubUrl, { |
|
14 | headers: { |
||
15 | Authorization: `Bearer ${token}`, |
||
16 | }, |
||
17 | }); |
||
18 | |||
19 | 1 | es.onmessage = ({ data }) => onMessage(JSON.parse(data)); |
|
20 | 2 | es.onerror = ({ status }) => status === 401 && onTokenExpired(); |
|
21 | |||
22 | 1 | return () => es.close(); |
|
23 | }; |
||
24 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.