Completed
Pull Request — master (#290)
by korelstar
32:21
created

src/store.js (47 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
		numNotes: (state) => () => {
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.notes.length
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
		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...
24
			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...
25
		},
26
27
		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...
28
			if (state.notesIds[id] === undefined) {
29
				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...
30
			}
31
			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...
32
		},
33
34
		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...
35
			function nthIndexOf(str, pattern, n) {
36
				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...
37
				while (n-- && i++ < str.length) {
38
					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...
39
					if (i < 0) {
40
						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...
41
					}
42
				}
43
				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...
44
			}
45
46
			// get categories from notes
47
			const categories = {}
0 ignored issues
show
Backwards Compatibility introduced by
'const' 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
			for (const note of state.notes) {
0 ignored issues
show
Backwards Compatibility introduced by
'for of' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
Backwards Compatibility introduced by
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
49
				let cat = note.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...
50
				if (maxLevel > 0) {
51
					const index = nthIndexOf(cat, '/', maxLevel)
0 ignored issues
show
Backwards Compatibility introduced by
'const' 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...
52
					if (index > 0) {
53
						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...
54
					}
55
				}
56
				if (categories[cat] === undefined) {
57
					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...
58
				} else {
59
					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...
60
				}
61
			}
62
			// get structured result from categories
63
			const result = []
0 ignored issues
show
Backwards Compatibility introduced by
'const' 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...
64
			for (const category in categories) {
0 ignored issues
show
Backwards Compatibility introduced by
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
65
				if (details) {
66
					result.push({
67
						name: category,
68
						count: categories[category],
69
					})
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...
70
				} else if (category) {
71
					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...
72
				}
73
			}
74
			if (details) {
75
				result.sort((a, b) => a.name.localeCompare(b.name))
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...
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...
76
			} else {
77
				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...
78
			}
79
			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...
80
		},
81
	},
82
83
	mutations: {
84
		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...
85
			const note = state.notesIds[updated.id]
0 ignored issues
show
Backwards Compatibility introduced by
'const' 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...
86
			if (note) {
87
				// don't update meta-data over full data
88
				if (updated.content !== null || note.content === null) {
89
					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...
90
					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...
91
					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...
There were too many errors found in this file; checking aborted after 56%.

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

Further Reading:

Loading history...
92
					note.favorite = updated.favorite
93
					note.category = updated.category
94
					Vue.set(note, 'unsaved', updated.unsaved)
95
					Vue.set(note, 'error', updated.error)
96
					Vue.set(note, 'errorMessage', updated.errorMessage)
97
				}
98
			} else {
99
				state.notes.push(updated)
100
				Vue.set(state.notesIds, updated.id, updated)
101
			}
102
		},
103
104
		setNoteAttribute(state, params) {
105
			const note = state.notesIds[params.noteId]
106
			if (note) {
107
				Vue.set(note, params.attribute, params.value)
108
			}
109
		},
110
111
		remove(state, id) {
112
			const index = state.notes.findIndex(note => note.id === id)
113
			if (index !== -1) {
114
				state.notes.splice(index, 1)
115
				delete state.notesIds[id]
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 (const note of notes) {
156
				context.commit('add', note)
157
			}
158
		},
159
	},
160
})
161