extract save function in tables store
This commit is contained in:
parent
6afd886755
commit
5ed5da2cee
|
@ -35,12 +35,7 @@ function createTablesStore() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
async function save(table) {
|
||||||
subscribe,
|
|
||||||
set,
|
|
||||||
fetch,
|
|
||||||
select,
|
|
||||||
save: async table => {
|
|
||||||
const updatedTable = cloneDeep(table)
|
const updatedTable = cloneDeep(table)
|
||||||
const oldTable = get(store).list.filter(t => t._id === table._id)[0]
|
const oldTable = get(store).list.filter(t => t._id === table._id)[0]
|
||||||
|
|
||||||
|
@ -73,7 +68,14 @@ function createTablesStore() {
|
||||||
await fetch()
|
await fetch()
|
||||||
await select(savedTable)
|
await select(savedTable)
|
||||||
return savedTable
|
return savedTable
|
||||||
},
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
set,
|
||||||
|
fetch,
|
||||||
|
select,
|
||||||
|
save,
|
||||||
delete: async table => {
|
delete: async table => {
|
||||||
await api.delete(`/api/tables/${table._id}/${table._rev}`)
|
await api.delete(`/api/tables/${table._id}/${table._rev}`)
|
||||||
update(state => ({
|
update(state => ({
|
||||||
|
@ -104,14 +106,14 @@ function createTablesStore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
state.draft.schema[field.name] = cloneDeep(field)
|
state.draft.schema[field.name] = cloneDeep(field)
|
||||||
store.save(state.draft)
|
save(state.draft)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
deleteField: field => {
|
deleteField: field => {
|
||||||
update(state => {
|
update(state => {
|
||||||
delete state.draft.schema[field.name]
|
delete state.draft.schema[field.name]
|
||||||
store.save(state.draft)
|
save(state.draft)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue