2021-05-07 14:30:51 +02:00
|
|
|
import { writable } from 'svelte/store'
|
|
|
|
import api from "builderStore/api"
|
|
|
|
|
2021-05-11 17:51:01 +02:00
|
|
|
export default function (url) {
|
2021-05-07 14:30:51 +02:00
|
|
|
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()
|
|
|
|
|
2021-05-07 14:52:58 +02:00
|
|
|
return {subscribe: store.subscribe, refresh: get}
|
2021-05-07 14:30:51 +02:00
|
|
|
}
|