Add message to handlers
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>) {
|
||||
|
||||
Reference in New Issue
Block a user