Total Complexity | 13 |
Complexity/F | 1.44 |
Lines of Code | 58 |
Function Count | 9 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import activityApi from '../../api/activity' |
||
2 | |||
3 | export default { |
||
4 | namespaced: true, |
||
5 | state : { |
||
6 | activity: [], |
||
7 | }, |
||
8 | getters: { |
||
9 | 'isInProgress': (state) => (provider) => { |
||
10 | return state.activity.indexOf(provider) > -1; |
||
11 | }, |
||
12 | 'count': (state) => { |
||
13 | return state.activity.length; |
||
14 | } |
||
15 | }, |
||
16 | actions: { |
||
17 | 'load': ({commit}) => { |
||
18 | activityApi.get().then(function (response) { |
||
19 | commit('setActivity', response.data); |
||
20 | |||
21 | // Mercure |
||
22 | if(response.headers.link) { |
||
23 | const hubUrl = response.headers.link.match(/<([^>]+)>;\s+rel=(?:mercure|"[^"]*mercure[^"]*")/)[1]; |
||
24 | const h = new URL(hubUrl); |
||
|
|||
25 | h.searchParams.append('topic', 'http://twity.io/p/{provider}/{package}') |
||
26 | const es = new EventSource(h, { withCredentials: true}); |
||
27 | es.onmessage = e => { |
||
28 | let data = JSON.parse(e.data); |
||
29 | |||
30 | if(data.updateInProgress === true) { |
||
31 | commit('addProvider', data.provider); |
||
32 | } else { |
||
33 | commit('removeProvider', data.provider); |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 | }); |
||
38 | } |
||
39 | }, |
||
40 | |||
41 | mutations: { |
||
42 | 'setActivity': (state, value) => { |
||
43 | state.activity = value; |
||
44 | }, |
||
45 | 'addProvider': (state, value) => { |
||
46 | let index = state.activity.indexOf(value); |
||
47 | if (index === -1) { |
||
48 | state.activity.push(value); |
||
49 | } |
||
50 | }, |
||
51 | 'removeProvider': (state, value) => { |
||
52 | let index = state.activity.indexOf(value); |
||
53 | if (index > -1) { |
||
54 | state.activity.splice(index, 1); |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 |
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.