Completed
Push — master ( d231ed...aa59a9 )
by Alejandro
59s queued 56s
created

src/mercure/helpers/index.js   A

Complexity

Total Complexity 6
Complexity/F 1.2

Size

Lines of Code 23
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
mnd 1
bc 1
fnc 5
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
bpm 0.2
cpm 1.2
noi 2
c 0
b 0
f 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);
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 1
  hubUrl.searchParams.append('topic', topic);
13 1
  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 1
  es.onmessage = ({ data }) => onMessage(JSON.parse(data));
20 2
  es.onerror = ({ status }) => status === 401 && onTokenExpired();
21
22 1
  return () => es.close();
23
};
24