Passed
Pull Request — master (#251)
by Alejandro
18:31
created

src/mercure/helpers/index.js   A

Complexity

Total Complexity 6
Complexity/F 1.2

Size

Lines of Code 25
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 20%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
mnd 1
bc 1
fnc 5
dl 0
loc 25
bpm 0.2
cpm 1.2
noi 2
c 0
b 0
f 0
rs 10
ccs 2
cts 10
cp 0.2
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);
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

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.

Loading history...
11
12
  hubUrl.searchParams.append('topic', topic);
13
  const es = new EventSource(hubUrl, {
0 ignored issues
show
Bug introduced by
The variable EventSource seems to be never declared. If this is a global, consider adding a /** global: EventSource */ comment.

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.

Loading history...
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