Skip to content

A library is provide the reducer for Selective Hydration based on react hooks.

License

Notifications You must be signed in to change notification settings

MaxMEllon/hydreducer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

  • type-safe redux and support ducks pattern.

This module is development now

Feature

Multi store (store instance created each module.)

  • Want to hydarate each by module from server.
    • In redux case, that have to do chunking a store state, because that is a single state.
    • That's a incompatible the state chunking and streaming rendering.

Minimum type definition

  • This module is providing to infer types of state, actions, and reducer.
  • You have not to do define types.
  • Just define object it.

Other

  • tiny
  • universal (isomorphic)

Example

const [actions, Provider, useAction, useModuleState] = createModule
  .initialState({
    count: 0
  })
  .actions({
    setCount: createAction<number>("count/set"),
    increment: createAction("count/inc"),
    decrement: createAction("count/dec"),
  })
  .reducer((actions, reducer) => (
    reducer
      .case(actions.setCount, (state, payload) => ({
        ...state,
        count: payload
      })
      .case(actions.increment, (state) => ({
        ...state,
        count: state.count + 1
      }))
      .case(actions.decrement, (state) => ({
        ...state,
        count: state.count - 1
      }))
  ))
  .build()

// original API (like as useDispatch + useCallback)
const increment = useAction(() => actions.increment())
// like `useSelector` in react-redux
const count = useModuleState(state => state.count)

Inspired

TODO

  • testing
  • Promise or Rx or other anything.
  • approach to hydrate from server with React.

LICENSE

MIT

About

A library is provide the reducer for Selective Hydration based on react hooks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published