Total Complexity | 12 |
Complexity/F | 1.33 |
Lines of Code | 57 |
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 | const hubUrl = response.headers.link.match(/<([^>]+)>;\s+rel=(?:mercure|"[^"]*mercure[^"]*")/)[1]; |
||
23 | const h = new URL(hubUrl); |
||
|
|||
24 | h.searchParams.append('topic', 'http://twity.io/p/{provider}/{package}') |
||
25 | const es = new EventSource(h); |
||
26 | es.onmessage = e => { |
||
27 | let data = JSON.parse(e.data); |
||
28 | |||
29 | if(data.updateInProgress === true) { |
||
30 | commit('addProvider', data.provider); |
||
31 | } else { |
||
32 | commit('removeProvider', data.provider); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | }); |
||
37 | } |
||
38 | }, |
||
39 | |||
40 | mutations: { |
||
41 | 'setActivity': (state, value) => { |
||
42 | state.activity = value; |
||
43 | }, |
||
44 | 'addProvider': (state, value) => { |
||
45 | let index = state.activity.indexOf(value); |
||
46 | if (index === -1) { |
||
47 | state.activity.push(value); |
||
48 | } |
||
49 | }, |
||
50 | 'removeProvider': (state, value) => { |
||
51 | let index = state.activity.indexOf(value); |
||
52 | if (index > -1) { |
||
53 | state.activity.splice(index, 1); |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 |
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.