Passed
Pull Request — master (#3)
by Julien
03:49
created

assets/js/store/modules/activity.js   A

Complexity

Total Complexity 12
Complexity/F 1.33

Size

Lines of Code 57
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 1
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 12
mnd 1
bc 12
fnc 9
bpm 1.3333
cpm 1.3333
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A activity.js ➔ ??? 0 3 1
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);
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...
24
                h.searchParams.append('topic', 'http://twity.io/p/{provider}/{package}')
25
                const es = new EventSource(h);
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...
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