miwon
TypeScript icon, indicating that this package has built-in type declarations

1.0.18 • Public • Published

Miwon

Miwon is oriented to intergrated state container with api fetching and cache normalizing.

Concept

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

  • [x] store
    • [x] createStore
  • [x] subscription
    • [x] subscribe
    • [x] unsubscribe
    • [x] clear
    • [x] getSubscriptions
  • [x] fetcher
    • [x] createFetcher
    • [x] errorHandling
  • [x] cahce
    • [x] cache with normalized data
    • [x] get cache with key
  • [x] normalizer

Package Sidebar

Install

npm i miwon

Weekly Downloads

1

Version

1.0.18

License

MIT

Unpacked Size

25 kB

Total Files

15

Last publish

Collaborators

  • joooon