Lint
This commit is contained in:
@@ -3,7 +3,6 @@ import {Repository} from "@welshman/relay"
|
||||
import {get} from "svelte/store"
|
||||
import {afterEach, beforeEach, describe, expect, it, vi} from "vitest"
|
||||
import {
|
||||
adapter,
|
||||
custom,
|
||||
deriveEvents,
|
||||
deriveEventsMapped,
|
||||
@@ -114,28 +113,6 @@ describe("Store utilities", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("adapter", () => {
|
||||
it("should adapt between different types", () => {
|
||||
const source = synced<number>("test", 0)
|
||||
const adapted = adapter({
|
||||
store: source,
|
||||
forward: n => n.toString(),
|
||||
backward: s => parseInt(s, 10),
|
||||
})
|
||||
|
||||
const mockFn = vi.fn()
|
||||
adapted.subscribe(mockFn)
|
||||
|
||||
adapted.set("42")
|
||||
expect(get(source)).toBe(42)
|
||||
expect(mockFn).toHaveBeenLastCalledWith("42")
|
||||
|
||||
adapted.update(s => (parseInt(s, 10) + 1).toString())
|
||||
expect(get(source)).toBe(43)
|
||||
expect(mockFn).toHaveBeenLastCalledWith("43")
|
||||
})
|
||||
})
|
||||
|
||||
describe("Event-related stores", () => {
|
||||
const mockRepository = {
|
||||
query: vi.fn(),
|
||||
|
||||
@@ -121,22 +121,6 @@ export const custom = <T>(
|
||||
}
|
||||
}
|
||||
|
||||
// Simple adapter
|
||||
|
||||
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)))),
|
||||
})
|
||||
|
||||
// Event related stores
|
||||
|
||||
export type DeriveEventsMappedOptions<T> = {
|
||||
|
||||
Reference in New Issue
Block a user