Skip to content

Commit

Permalink
Merge pull request #26 from ddgll/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ddgll authored Oct 3, 2017
2 parents 058028e + e4b4270 commit 9db8694
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ IndexedDB wrapper for Vuejs based on Dexie
```
# 0.1.10 BUGFIX
RETURN Promise.reject()
BUGFIX #22

# 0.1.4 Enhancement
BUGFIX on listSelect vuex action
Expand Down
12 changes: 8 additions & 4 deletions src/modules/biglist-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@ export default (name, options, db, api) => {

const blActions = {
[`${name}Select`]({ commit }, payload) {
db[name].where(_id).equals(payload.id).first().then((entity) => {
commit(types[`${NAME}_SELECT`], entity)
})
if (payload) {
db[name].where(_id).equals(payload[_id]).first().then((entity) => {
commit(types[`${NAME}_SELECT`], entity)
})
} else {
commit(types[`${NAME}_SELECT`], null)
}
},
[`${name}LoadResponse`]({ commit, dispatch, state }, payload){
if(!payload || !payload.length) return commit(types[`${NAME}_LOAD_SUCCESS`])
Expand Down Expand Up @@ -205,7 +209,7 @@ export default (name, options, db, api) => {
const blMutations = {
// SELECT
[types[`${NAME}_SELECT`]] (state, entity) {
state.selected = { ...entity }
state.selected = entity !== null ? { ...entity } : null
},
// INFINITE
[types[`${NAME}_SET_INFINITE`]] (state, { iStart, iLimit, collection }) {
Expand Down
10 changes: 8 additions & 2 deletions src/modules/list-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ export default (name, options, db, api) => {
// actions
const actions = {
[`${name}Select`]({ commit, state }, payload) {
const index = state.collection.findIndex(e => e[_id] === payload[_id])
commit(types[`${NAME}_SELECT`], index)
if (payload) {
const index = state.collection.findIndex(e => e[_id] === payload[_id])
commit(types[`${NAME}_SELECT`], index)
} else {
commit(types[`${NAME}_SELECT`], -1)
}
},
[`${name}Load`]({ commit }, payload){
console.log('LOAD DATA')
Expand Down Expand Up @@ -191,6 +195,8 @@ export default (name, options, db, api) => {
const index = state.collection.findIndex(e => e[_id] == entity[_id])
if(index > -1){
state.collection = [ ...state.collection.slice(0, index), entity , ...state.collection.slice(index+1) ]
} else {
state.collection = [ ...state.collection, entity ]
}
state.loading = true
},
Expand Down

0 comments on commit 9db8694

Please sign in to comment.