mirror of https://github.com/Budibase/budibase.git
2 changed files with 24 additions and 0 deletions
@ -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] |
|||
} |
|||
Loading…
Reference in new issue