Completed
Pull Request — master (#290)
by korelstar
31:08
created

src/store.js (48 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
import Vue from 'vue'
0 ignored issues
show
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
2
import Vuex from 'vuex'
0 ignored issues
show
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
3
4
Vue.use(Vuex)
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
5
6
export default new Vuex.Store({
0 ignored issues
show
'export' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
7
	state: {
8
		settings: {},
9
		notes: [],
10
		notesIds: {},
11
		unsaved: {},
12
		isSaving: false,
13
		isManualSave: false,
14
		documentTitle: null,
15
		sidebarOpen: false,
16
	},
17
18
	getters: {
19
		noteExists: (state) => (id) => {
0 ignored issues
show
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
20
			return state.notesIds[id] !== undefined
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
21
		},
22
23
		getNote: (state) => (id) => {
0 ignored issues
show
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
24
			if (state.notesIds[id] === undefined) {
25
				return null
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
26
			}
27
			return state.notesIds[id]
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
28
		},
29
30
		getCategories: (state) => (maxLevel, details) => {
0 ignored issues
show
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
31
			function nthIndexOf(str, pattern, n) {
32
				let i = -1
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
33
				while (n-- && i++ < str.length) {
34
					i = str.indexOf(pattern, i)
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
35
					if (i < 0) {
36
						break
0 ignored issues
show
Line breaking error 'break'.
Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
37
					}
38
				}
39
				return i
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
40
			}
41
42
			let categories = {}
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
43
			let notes = state.notes
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
44
			for (let i = 0; i < notes.length; i += 1) {
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
45
				let cat = notes[i].category
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
46
				if (maxLevel > 0) {
47
					let index = nthIndexOf(cat, '/', maxLevel)
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
48
					if (index > 0) {
49
						cat = cat.substring(0, index)
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
50
					}
51
				}
52
				if (categories[cat] === undefined) {
53
					categories[cat] = 1
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
54
				} else {
55
					categories[cat] += 1
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
56
				}
57
			}
58
			let result = []
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
59
			for (let category in categories) {
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
60
				if (details) {
61
					result.push({
62
						name: category,
63
						count: categories[category],
64
					})
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
65
				} else if (category) {
66
					result.push(category)
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
67
				}
68
			}
69
			if (details) {
70
				result.sort(function(a, b) {
71
					return (a.name).localeCompare(b.name)
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
72
				})
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
73
			} else {
74
				result.sort()
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
75
			}
76
			return result
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
77
		},
78
	},
79
80
	mutations: {
81
		add(state, updated) {
0 ignored issues
show
Backwards Compatibility introduced by
'concise methods' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
82
			let note = state.notesIds[updated.id]
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
83
			if (note) {
84
				// don't update meta-data over full data
85
				if (updated.content !== null || note.content === null) {
86
					note.title = updated.title
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
87
					note.modified = updated.modified
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
88
					note.content = updated.content
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
89
					note.favorite = updated.favorite
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
90
					note.category = updated.category
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
There were too many errors found in this file; checking aborted after 55%.

If JSHint finds too many errors in a file, it aborts checking altogether because it suspects a configuration issue.

Further Reading:

Loading history...
91
					Vue.set(note, 'unsaved', updated.unsaved)
92
					Vue.set(note, 'error', updated.error)
93
					Vue.set(note, 'errorMessage', updated.errorMessage)
94
				}
95
			} else {
96
				state.notes.push(updated)
97
				Vue.set(state.notesIds, updated.id, updated)
98
			}
99
		},
100
101
		setNoteAttribute(state, params) {
102
			let note = state.notesIds[params.noteId]
103
			if (note) {
104
				Vue.set(note, params.attribute, params.value)
105
			}
106
		},
107
108
		remove(state, id) {
109
			for (let i = 0; i < state.notes.length; i++) {
110
				let note = state.notes[i]
111
				if (note.id === id) {
112
					state.notes.splice(i, 1)
113
					delete state.notesIds[id]
114
					break
115
				}
116
			}
117
		},
118
119
		removeAll(state) {
120
			state.notes = []
121
			state.notesIds = {}
122
		},
123
124
		addUnsaved(state, id) {
125
			Vue.set(state.unsaved, id, state.notesIds[id])
126
		},
127
128
		clearUnsaved(state) {
129
			state.unsaved = {}
130
		},
131
132
		setSettings(state, settings) {
133
			state.settings = settings
134
		},
135
136
		setSaving(state, isSaving) {
137
			state.isSaving = isSaving
138
		},
139
140
		setManualSave(state, isManualSave) {
141
			state.isManualSave = isManualSave
142
		},
143
144
		setDocumentTitle(state, title) {
145
			state.documentTitle = title
146
		},
147
148
		setSidebarOpen(state, open) {
149
			state.sidebarOpen = open
150
		},
151
	},
152
153
	actions: {
154
		addAll(context, notes) {
155
			for (let i = 0; i < notes.length; i++) {
156
				context.commit('add', notes[i])
157
			}
158
		},
159
	},
160
})
161