src/store/mutations.js   A
last analyzed

Complexity

Total Complexity 16
Complexity/F 1.14

Size

Lines of Code 70
Function Count 14

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 48.65%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 0
c 4
b 0
f 0
nc 1
dl 0
loc 70
ccs 18
cts 37
cp 0.4865
crap 0
rs 10
wmc 16
mnd 1
bc 16
fnc 14
bpm 1.1428
cpm 1.1428
noi 0

12 Functions

Rating   Name   Duplication   Size   Complexity  
A mutations.js ➔ updateComment 0 8 1
A mutations.js ➔ setOrderBy 0 3 1
A mutations.js ➔ orderByNewest 0 3 1
A mutations.js ➔ setConfig 0 3 1
A mutations.js ➔ setLastCommentTime 0 3 1
A mutations.js ➔ setMaxDepth 0 7 2
A mutations.js ➔ deleteComment 0 6 1
A mutations.js ➔ setUser 0 3 1
A mutations.js ➔ oderByOldest 0 3 1
A mutations.js ➔ addComment 0 8 1
A mutations.js ➔ clearComments 0 3 1
A mutations.js ➔ updatePagination 0 7 1
1
import Vue from 'vue';
2
3 4
export const setConfig = function(state, config) {
4
	Vue.set(state, 'config', Object.assign({}, state.config, config));
5
};
6
7 4
export const setLastCommentTime = function(state) {
8
	state.lastCommentTime = new Date();
9
};
10
11 4
export const setMaxDepth = function(state, depth) {
12 4
	if (typeof depth !== 'number') {
13
		throw 'Depth must be an integer';
14
	}
15
16
	state.maxDepth = depth;
17
};
18
19 4
export const setOrderBy = function(state, orderBy) {
20
	state.orderBy = orderBy;
21
};
22
23 4
export const orderByNewest = function(state) {
24
	state.orderBy = 'newest';
25
};
26
27 4
export const oderByOldest = function(state) {
28
	state.orderBy = 'oldest';
29
};
30
31 4
export const setUser = function(state, user) {
32
	Vue.set(state, 'user', user);
33
};
34
35 4
export const addComment = function(state, comment) {
36
	let comments = state.comments;
37
38
	comment.created = new Date(comment.created);
39
	comments.push(comment);
40
41
	Vue.set(state, 'comments', comments);
42
};
43
44 4
export const deleteComment = function(state, comment) {
45
	let comments = state.comments.filter(function(commentFromList) {
46
		return commentFromList.id !== comment.id;
47
	});
48
	Vue.set(state, 'comments', comments);
49
};
50
51 4
export const updateComment = function(state, editedComment) {
52
	state.comments.forEach(function(comment) {
53 4
		if (comment.id == editedComment.id) {
54
			let index = state.comments.indexOf(comment);
55
			state.comments[index] = editedComment;
56
		}
57
	});
58
};
59
60 4
export const updatePagination = function(state, data) {
61 2
	let key = data.model + data.modelId + data.parentId;
62 2
	let pagination = Object.assign({}, state.pagination);
63 2
	pagination[key] = data.pagination;
64
65 2
	Vue.set(state, 'pagination', pagination);
66
};
67
68 4
export const clearComments = function(state) {
69
	Vue.set(state, 'comments', []);
70
};
71