Add message to handlers

This commit is contained in:
Jon Staab
2024-08-27 11:54:04 -07:00
parent fcbaa67ade
commit 8a8bea71be
13 changed files with 71 additions and 61 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@welshman/store",
"version": "0.0.3",
"version": "0.0.4",
"author": "hodlbod",
"license": "MIT",
"description": "A collection of utilities based on svelte/store for use with welshman",
@@ -32,7 +32,7 @@
},
"dependencies": {
"@welshman/lib": "0.0.15",
"@welshman/util": "0.0.27",
"@welshman/util": "0.0.28",
"svelte": "^4.2.18"
}
}
+14
View File
@@ -61,6 +61,20 @@ export const custom = <T>(start: Start<T>, opts: {throttle?: number} = {}) => {
}
}
export const adapter = <Source, Target>({
store,
forward,
backward,
}: {
store: Writable<Source>,
forward: (x: Source) => Target,
backward: (x: Target) => Source,
}) => ({
...derived(store, forward),
set: (x: Target) => store.set(backward(x)),
update: (f: (x: Target) => Target) => store.update((x: Source) => backward(f(forward(x)))),
})
export function withGetter<T>(store: Writable<T>): Writable<T> & {get: () => T}
export function withGetter<T>(store: Readable<T>): Readable<T> & {get: () => T}
export function withGetter<T>(store: Readable<T> | Writable<T>) {