Completed
Pull Request — master (#290)
by korelstar
33:12
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
			if (state.notesIds[id].error) {
28
				OC.Notification.show(
29
					state.notesIds[id].errorMessage,
30
					{ type: 'error' }
31
				)
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
				return false
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...
33
			}
34
			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...
35
		},
36
37
		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...
38
			function nthIndexOf(str, pattern, n) {
39
				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...
40
				while (n-- && i++ < str.length) {
41
					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...
42
					if (i < 0) {
43
						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...
44
					}
45
				}
46
				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...
47
			}
48
49
			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...
50
			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...
51
			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...
52
				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...
53
				if (maxLevel > 0) {
54
					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...
55
					if (index > 0) {
56
						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...
57
					}
58
				}
59
				if (categories[cat] === undefined) {
60
					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...
61
				} else {
62
					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...
63
				}
64
			}
65
			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...
66
			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...
67
				if (details) {
68
					result.push({
69
						name: category,
70
						count: categories[category],
71
					})
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
				} else if (category) {
73
					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...
74
				}
75
			}
76
			if (details) {
77
				result.sort(function(a, b) {
78
					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...
79
				})
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
			} else {
81
				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...
82
			}
83
			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...
84
		},
85
	},
86
87
	mutations: {
88
		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...
89
			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...
90
			if (note) {
91
				// don't update meta-data over full data
92
				if (updated.content !== null || note.content === null) {
93
					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...
94
					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...
95
					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...
96
					note.favorite = updated.favorite
97
					note.category = updated.category
98
					Vue.set(note, 'unsaved', updated.unsaved)
99
					Vue.set(note, 'error', updated.error)
100
					Vue.set(note, 'errorMessage', updated.errorMessage)
101
				}
102
			} else {
103
				state.notes.push(updated)
104
				Vue.set(state.notesIds, updated.id, updated)
105
			}
106
		},
107
108
		setNoteAttribute(state, params) {
109
			let note = state.notesIds[params.noteId]
110
			if (note) {
111
				note[params.attribute] = params.value
112
			}
113
		},
114
115
		remove(state, id) {
116
			for (let i = 0; i < state.notes.length; i++) {
117
				let note = state.notes[i]
118
				if (note.id === id) {
119
					state.notes.splice(i, 1)
120
					delete state.notesIds[id]
121
					break
122
				}
123
			}
124
		},
125
126
		removeAll(state) {
127
			state.notes = []
128
			state.notesIds = {}
129
		},
130
131
		addUnsaved(state, id) {
132
			Vue.set(state.unsaved, id, state.notesIds[id])
133
		},
134
135
		clearUnsaved(state) {
136
			state.unsaved = {}
137
		},
138
139
		setSettings(state, settings) {
140
			state.settings = settings
141
		},
142
143
		setSaving(state, isSaving) {
144
			state.isSaving = isSaving
145
		},
146
147
		setManualSave(state, isManualSave) {
148
			state.isManualSave = isManualSave
149
		},
150
151
		setDocumentTitle(state, title) {
152
			state.documentTitle = title
153
		},
154
155
		setSidebarOpen(state, open) {
156
			state.sidebarOpen = open
157
		},
158
	},
159
160
	actions: {
161
		addAll(context, notes) {
162
			for (let i = 0; i < notes.length; i++) {
163
				context.commit('add', notes[i])
164
			}
165
		},
166
	},
167
})
168