2.0.1 • Published 8 years ago

react-redux-boil v2.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Boil

Boil is a tool for reducing redux boilerplate. It allows to create state containers and reducers with small amount of code

Intallation

npm install --save react-redux-boil

Also you need to install react-redux package required as peer dependency

Usage

It's easy to create state containers and reducers with Boil:

import boil from 'react-redux-boil'

const state = boil({
  color: {
    defaultState: 'red',
    handlers: {
      change: state => (state === 'red' ? 'blue' : 'red')
    }
  },
  text: {
    defaultState: 'Some Text',
    handlers: {
     change: (state, text) => text
    }
  }
})

export default state

Then you need to create store from your models and pass it to Provider from react-redux

import {combineReducers, createStore } from 'redux'
import state from './state'

const rootReducer = combineReducers(state.reducers)
const store = createStore(rootReducer)
// Pass it to <Provider store={store}/>

Then you can use your state container and call reducers:

import { compose } from 'redux'
import React from 'react'
import state from '../state'

const Application = props => (
  <div>
    <input onChange={event => props.text.change(event.target.value)} value={props.text.value} />
    <div style={{ color: props.color.value }}>{props.text.value}</div>
    <div style={{ cursor: 'pointer' }} onClick={props.color.change}>
      Change color
    </div>
  </div>
)

const { containers } = state
export default compose(containers.color, containers.text)(Application)

If you want to understand more look at example

2.0.1

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago