1.0.18 • Published 2 years ago
miwon v1.0.18
Miwon
Miwon is oriented to intergrated state container with api fetching and cache normalizing.
Concept
- Cache Normalizing like Apollo Client
- Handling sever-side-data like TanStack Query
Notice
- Miwon is a kind of seasoning for cook.
- This library is experimental and unstable. (also, document is unkind)
Installation
npm install miwon
yarn add miwon
Quick Start
1. Add Miwon to your project
import { addMiwon } from 'miwon'
const miwon = addMiwon({
config: {
baseURL: 'https://my-json-server.typicode.com' //change base url for your project
}
})
2. Build Normalizer.
import { schema, normalize } from 'miwon'
const postsNormalizer = (res: any) => {
const commentEntity = new schema.Entity('comments')
const postEntity = new schema.Entity('posts', {
comments: [commentEntity]
})
const posts = new schema.Array(postEntity)
return normalize(res, posts).entities
}
3. Get data with Normalizer.
miwon.miwonQuery('/2hakjoon/miwon/posts', postsNormalizer).then(
() => console.log(getState()) // you can see normalized result which cached
)
Todo
- store
- createStore
- subscription
- subscribe
- unsubscribe
- clear
- getSubscriptions
- fetcher
- createFetcher
- errorHandling
- cahce
- cache with normalized data
- get cache with key
- normalizer