diff --git a/packages/builder/src/helperStores.js b/packages/builder/src/helperStores.js new file mode 100644 index 0000000000..f4eb2020c4 --- /dev/null +++ b/packages/builder/src/helperStores.js @@ -0,0 +1,20 @@ +import { writable } from 'svelte/store' +import api from "builderStore/api" + +export function fetchData (url) { + const store = writable({status: 'LOADING', data: {}, error: {}}) + + async function get() { + store.update(u => ({...u, status: 'SUCCESS'})) + try { + const response = await api.get(url) + store.set({data: await response.json(), status: 'SUCCESS'}) + } catch(e) { + store.set({data: {}, error: e, status: 'ERROR'}) + } + } + + get() + + return [store, get] +} \ No newline at end of file diff --git a/packages/builder/vite.config.js b/packages/builder/vite.config.js index 69b5730b5b..77d1eaa7bb 100644 --- a/packages/builder/vite.config.js +++ b/packages/builder/vite.config.js @@ -56,6 +56,10 @@ export default ({ mode }) => { find: "actions", replacement: path.resolve("./src/actions"), }, + { + find: "helperStores", + replacement: path.resolve("./src/helperStores"), + }, { find: "helpers", replacement: path.resolve("./src/helpers"),