Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aredridel/svelte-lens-store
Functional lenses over svelte stores
https://github.com/aredridel/svelte-lens-store
Last synced: about 1 month ago
JSON representation
Functional lenses over svelte stores
- Host: GitHub
- URL: https://github.com/aredridel/svelte-lens-store
- Owner: aredridel
- Created: 2022-05-15T21:35:02.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-05-15T21:35:34.000Z (over 2 years ago)
- Last Synced: 2024-10-17T19:04:28.252Z (about 2 months ago)
- Language: TypeScript
- Size: 6.84 KB
- Stars: 13
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-svelte-stores - svelte-lens-store
README
# Svelte Lens Store
A functional lens into svelte stores
## Use
### `bijectiveMapping`
```typescript
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`
```typescript
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] }
```