Skip to content

Commit fe144e1

Browse files
committed
also use removeTemps for non created
1 parent 59c7d25 commit fe144e1

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/service-module/service-module.mutations.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,16 @@ export default function makeServiceMutations() {
179179
removeTemps(state, tempIds) {
180180
const ids = tempIds.reduce((ids, id) => {
181181
const temp = state.tempsById[id]
182-
if (temp && temp[state.tempIdField]) {
183-
delete temp.__isTemp
184-
Vue.delete(temp, '__isTemp')
185-
ids.push(temp[state.tempIdField])
182+
if (temp) {
183+
if (temp[state.idField]) {
184+
// Removes __isTemp if created
185+
delete temp.__isTemp
186+
Vue.delete(temp, '__isTemp')
187+
ids.push(temp[state.idField])
188+
} else {
189+
// Removes uncreated temp
190+
ids.push(temp[state.tempIdField])
191+
}
186192
}
187193
return ids
188194
}, [])

test/service-module/model-temp-ids.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,40 @@ describe('Models - Temp Ids', function() {
213213
})
214214
})
215215

216+
it('removes uncreated temp', function() {
217+
const { makeServicePlugin, BaseModel } = feathersVuex(feathersClient, {
218+
idField: '_id',
219+
serverAlias: 'temp-ids'
220+
})
221+
class Thing extends BaseModel {
222+
public static modelName = 'Thing'
223+
public constructor(data?, options?) {
224+
super(data, options)
225+
}
226+
}
227+
const store = new Vuex.Store<RootState>({
228+
plugins: [
229+
makeServicePlugin({
230+
Model: Thing,
231+
service: feathersClient.service('things')
232+
})
233+
]
234+
})
235+
236+
const thing = new Thing({
237+
description: 'Robb Wolf - the Paleo Solution',
238+
website:
239+
'https://robbwolf.com/shop-old/products/the-paleo-solution-the-original-human-diet/',
240+
amount: 1.99
241+
})
242+
243+
assert(store.state.things.tempsById[thing.__id], 'item is in the tempsById')
244+
245+
store.commit('things/removeTemps', [thing.__id])
246+
247+
assert(!store.state.things.tempsById[thing.__id], 'temp item was removed')
248+
})
249+
216250
it('clones into Model.copiesById', function() {
217251
const { makeServicePlugin, BaseModel } = feathersVuex(feathersClient, {
218252
idField: '_id',

0 commit comments

Comments
 (0)