1.0.0 • Published 3 years ago

@aredridel/svelte-lens-store v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Svelte Lens Store

A functional lens into svelte stores

Use

bijectiveMapping

import { get, writable } from "svelte/store";

const base = writable(`{"hello":"world"}`);

const mapped = bijectiveMapping(base, JSON.parse, JSON.stringify);

get(mapped) // { hello: "world" }

mapped.set([1, 2, 3]);

get(base) // "[1,2,3]";

focusOnProperty

const base = writable({ hello: "world" } as { hello: any });

const mapped = focusOnProperty(base, "hello");

get(mapped) // "world";

mapped.set([1, 2, 3]);

get(base) // { hello: [1, 2, 3] }