Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-idb",
"version": "0.1.8",
"version": "0.1.9",
"description": "IndexedDB wrapper for Vuejs based on Dexie",
"main": "dist/index.js",
"author": "David Grill <grilldotcom@gmail.com>",
Expand Down
5 changes: 4 additions & 1 deletion src/modules/list-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ export default (name, options, db, api) => {
},
// REMOVE
[types[`${NAME}_REMOVE`]](state, entity) {
state.collection = state.collection.filter(e => e[_id] !== entity[_id])
const index = state.collection.findIndex(e => e[_id] == entity[_id])
if(index > -1){
state.collection = [ ...state.collection.slice(0, index), ...state.collection.slice(index+1) ]
}
},
[types[`${NAME}_REMOVE_FAIL`]](state, entity) {
state.collection = [ ...state.collection, entity ]
Expand Down
11 changes: 5 additions & 6 deletions src/mutations/list-defaults.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default (name, options, db) => {
const update = (payload) => db[name].put(payload)
const id = options.primary ? options.primary : 'id'
const update = (payload) => db[name].put(payload)
const id = options.primary ? options.primary : 'id'
const remove = (payload) => db[name].where(id).equals(payload[id]).delete()

const NAME = name.toUpperCase()

Expand All @@ -9,17 +10,15 @@ export default (name, options, db) => {
db[name].bulkPut(payload)
},
[NAME + '_ADD']: update,
[NAME + '_ADD_FAIL']: update,
[NAME + '_ADD_FAIL']: remove,
[NAME + '_ADD_SUCCESS']: update,
[NAME + '_UPDATE']: update,
[NAME + '_UPDATE_FAIL']: update,
[NAME + '_UPDATE_SUCCESS']: update,
[NAME + '_UPDATES']: update,
[NAME + '_UPDATES_FAIL']: update,
[NAME + '_UPDATES_SUCCESS']: update,
[NAME + '_REMOVE'](payload){
db[name].where(id).equals(payload[id]).delete()
},
[NAME + '_REMOVE']: remove,
[NAME + '_REMOVE_FAIL']: update
}
}