0.3.0 • Published 10 months ago

yarw v0.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 months ago

YARW

A typesafe, effective redux wrapper. Inspired by many ideas:

Needs TypeScript 4.1

Features

  • Type safety
    • Never losing type information downstream through all the layers of your application (e.g. no type assertions or hacking with any type)
  • Less boilerplate code
    • Generate action creator/dispatcher automatically
  • Code splitting friendly
    • Add reducer at any time in your application lifecycle
  • Still redux
    • So you can still use most of your favorite redux middlewares/tools

Usage

import { createRoot, registerSlice } from 'yarw'

// Create a `Root` that like be the `store` of redux
const root = createRoot()

// You can dynamically register a `Slice` at any time
setTimeout(() => {
  const slice = registerSlice(root, 'sliceName', {
    initialState: { count: 0 },
    reducers: {
      doSomething(state, action: Action.Payload<number>) {
        return { ...state, count: state.count + action.payload }
      },
    },
  })

  // Action, actionCreator and actionDispatcher has been created automatically
  slice.doSomething(100)

  // Let's print the count
  console.log('current count', slice.getState(root).count)

  // You can even unregister slice when you no need, then the reducer will no
  // longer work
  setTimeout(() => slice.unregister(), Math.randaom() * 1000)
}, Math.random() * 1000)

More usage please read docs/example.ts

0.3.0

10 months ago

0.2.0

3 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.0

4 years ago