Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extending the svelte store writable with your own methods
const { writable, get } = require("svelte/store");
const merge = require("lodash/merge");
/**
* A svelte store writable with two extra methods
*
* Usage:
* const store = customStore({ name: "Erasmus" });
* store.merge({ name: "Billy" });
* store.reset();
*
* @param defaultValue
*/
function customStore(defaultValue){
const op = writable(defaultValue)
op.merge = obj => op.set(merge(get(op), obj));
op.reset = () => op.set(defaultValue);
return op;
}
modex.exports = customStore;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.