Total Complexity | 6 |
Complexity/F | 1.2 |
Lines of Code | 25 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 20% |
Changes | 0 |
1 | import { EventSourcePolyfill as EventSource } from 'event-source-polyfill'; |
||
2 | |||
3 | 28 | export const bindToMercureTopic = (mercureInfo, topic, onMessage) => () => { |
|
4 | const { mercureHubUrl, token, loading, error } = mercureInfo; |
||
5 | |||
6 | 4 | if (loading || error) { |
|
7 | return undefined; |
||
8 | } |
||
9 | |||
10 | const hubUrl = new URL(mercureHubUrl); |
||
|
|||
11 | |||
12 | hubUrl.searchParams.append('topic', topic); |
||
13 | const es = new EventSource(hubUrl, { |
||
14 | headers: { |
||
15 | Authorization: `Bearer ${token}`, |
||
16 | }, |
||
17 | }); |
||
18 | |||
19 | es.onmessage = ({ data }) => onMessage(JSON.parse(data)); |
||
20 | |||
21 | // TODO Handle errors and get a new token |
||
22 | es.onerror = () => {}; |
||
23 | |||
24 | return () => es.close(); |
||
25 | }; |
||
26 |
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.