mori-reducer

A createReducer function using Mori.hashMap for storing actionHandlers

Usage no npm install needed!

<script type="module">
  import moriReducer from 'https://cdn.skypack.dev/mori-reducer';
</script>

README

Installation

  • Just run npm install mori-reducer or anything
  • add import { createReducer } from 'mori-reducer' to import this package into your code

Usage

Take a peek at this fancy snippet

import { createStore } from 'redux'
import { hashMap } from 'mori'
import { createReducer } from 'mori-reducer'
import { SOME_ACTION, SOME_OTHER_ACTION } from './action-constants'

const exampleReducer = createReducer('', hashMap(
  SOME_ACTION, (state, action) => {
    return 'this is a better state'
  },
  SOME_OTHER_ACTION, (state, action) => {
    return 'this is a way better state'
  }
)

const store = createStore(exampleReducer, 'initial state')

store.dispatch({type: SOME_ACTION})

// from v1.0.4 you can use a Mori.hashMap as action
store.dispatch(hashMap('type', SOME_OTHER_ACTION))

console.log(store.getState())
// 'this is a way better state'

How to test

  • clone this repo
  • cd into its directory
  • run npm install
  • run npm test to test this package

Contributors

Uses