Skip to content

Commit 6250341

Browse files
authored
Update mutations.js -> Consistency with docs
Rearrange order of mutations
1 parent c8b16ff commit 6250341

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

src/service-module/mutations.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -145,28 +145,6 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
145145
}
146146
},
147147

148-
clearAll (state) {
149-
state.ids = []
150-
state.currentId = null
151-
state.copy = null
152-
state.keyedById = {}
153-
},
154-
155-
clearList (state) {
156-
let currentId = state.currentId
157-
let current = state.keyedById[currentId]
158-
159-
if (currentId && current) {
160-
state.keyedById = {
161-
[currentId]: current
162-
}
163-
state.ids = [currentId]
164-
} else {
165-
state.keyedById = {}
166-
state.ids = []
167-
}
168-
},
169-
170148
setCurrent (state, itemOrId) {
171149
const { idField } = state
172150
const Model = globalModels.byServicePath[servicePath]
@@ -190,13 +168,6 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
190168
state.copy = null
191169
},
192170

193-
// Removes the copy from copiesById
194-
clearCopy (state, id) {
195-
const newCopiesById = Object.assign({}, state.copiesById)
196-
delete newCopiesById[id]
197-
state.copiesById = newCopiesById
198-
},
199-
200171
// Creates a copy of the record with the passed-in id, stores it in copiesById
201172
createCopy (state, id) {
202173
const current = state.keyedById[id]
@@ -211,8 +182,8 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
211182
}
212183
},
213184

214-
// Resets the copy to match the original record, locally
215-
rejectCopy (state, id) {
185+
// Deep assigns copy to original record, locally
186+
commitCopy (state, id) {
216187
const isIdOk = checkId(id, undefined, debug)
217188
const current = isIdOk ? state.keyedById[id] : state.keyedById[state.currentId]
218189
const Model = globalModels.byServicePath[servicePath]
@@ -224,11 +195,13 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
224195
copy = Model.copiesById[id]
225196
}
226197

227-
_merge(copy, current)
228-
},
198+
updateOriginal(copy, current)
229199

230-
// Deep assigns copy to original record, locally
231-
commitCopy (state, id) {
200+
// Object.assign(current, copy)
201+
},
202+
203+
// Resets the copy to match the original record, locally
204+
rejectCopy (state, id) {
232205
const isIdOk = checkId(id, undefined, debug)
233206
const current = isIdOk ? state.keyedById[id] : state.keyedById[state.currentId]
234207
const Model = globalModels.byServicePath[servicePath]
@@ -240,9 +213,36 @@ export default function makeServiceMutations (servicePath, { debug, globalModels
240213
copy = Model.copiesById[id]
241214
}
242215

243-
updateOriginal(copy, current)
216+
_merge(copy, current)
217+
},
244218

245-
// Object.assign(current, copy)
219+
// Removes the copy from copiesById
220+
clearCopy (state, id) {
221+
const newCopiesById = Object.assign({}, state.copiesById)
222+
delete newCopiesById[id]
223+
state.copiesById = newCopiesById
224+
},
225+
226+
clearAll (state) {
227+
state.ids = []
228+
state.currentId = null
229+
state.copy = null
230+
state.keyedById = {}
231+
},
232+
233+
clearList (state) {
234+
let currentId = state.currentId
235+
let current = state.keyedById[currentId]
236+
237+
if (currentId && current) {
238+
state.keyedById = {
239+
[currentId]: current
240+
}
241+
state.ids = [currentId]
242+
} else {
243+
state.keyedById = {}
244+
state.ids = []
245+
}
246246
},
247247

248248
// Stores pagination data on state.pagination based on the query identifier (qid)

0 commit comments

Comments
 (0)