From 5ed5da2ceecb4f3dac169af51bfd7ca00a14f768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Tue, 23 Mar 2021 13:19:34 +0100 Subject: [PATCH] extract save function in tables store --- .../src/builderStore/store/backend/tables.js | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/builderStore/store/backend/tables.js b/packages/builder/src/builderStore/store/backend/tables.js index ecd3b28042..c78cdbb1a3 100644 --- a/packages/builder/src/builderStore/store/backend/tables.js +++ b/packages/builder/src/builderStore/store/backend/tables.js @@ -35,12 +35,7 @@ function createTablesStore() { } } - return { - subscribe, - set, - fetch, - select, - save: async table => { + async function save(table) { const updatedTable = cloneDeep(table) const oldTable = get(store).list.filter(t => t._id === table._id)[0] @@ -73,7 +68,14 @@ function createTablesStore() { await fetch() await select(savedTable) return savedTable - }, + } + + return { + subscribe, + set, + fetch, + select, + save, delete: async table => { await api.delete(`/api/tables/${table._id}/${table._rev}`) update(state => ({ @@ -104,14 +106,14 @@ function createTablesStore() { } state.draft.schema[field.name] = cloneDeep(field) - store.save(state.draft) + save(state.draft) return state }) }, deleteField: field => { update(state => { delete state.draft.schema[field.name] - store.save(state.draft) + save(state.draft) return state }) },