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
+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>) {