Skip to content

Instantly share code, notes, and snippets.

View Martin-Andersen's full-sized avatar

Martin H. Andersen Martin-Andersen

View GitHub Profile
@Martin-Andersen
Martin-Andersen / httpStore.js
Created June 5, 2022 14:00 — forked from joshnuss/httpStore.js
A Svelte store backed by HTTP
import { writable } from 'svelte/store'
// returns a store with HTTP access functions for get, post, patch, delete
// anytime an HTTP request is made, the store is updated and all subscribers are notified.
export default function(initial) {
// create the underlying store
const store = writable(initial)
// define a request function that will do `fetch` and update store when request finishes
store.request = async (method, url, params=null) => {