npm.io
0.0.0-alpha.7 • Published 8 years agoCLI

deltax

Licence
ISC
Version
0.0.0-alpha.7
Deps
2
Size
23 kB
Vulns
0
Weekly
0
Stars
1

DeltaX

Description

Helper methods and cli to remove the boilerplate of Redux project setup and development.

Setup

  1. npm install deltax --save
  2. cd <src directory>
  3. deltax create

Usage

  1. Create Actions
// ./store/actions/counter.js
import { createAction as ca } from "deltax"

export const inc = ca("INCREMENT")
export const dec = ca("DECREMENT")
  1. Create Reducer

deltax reducer counter

// ./store/reducers/counter.js
import { createReducer as cr } from "deltax"
import { inc, dec } from "../actions/counter"

export default cr({ count: 0 }, [
  inc.case(({ count }, v = 1) => ({ count: count + v })),
  dec.case(({ count }, v = 1) => ({ count: count - v }))
])
  1. Dispatch Actions
// ./components/counter.js
import { connect } from "react-redux"
import { inc, dec } from "../store/actions/counter"

export default connect(
  ({ counter }) => ({ counter }),
  dispatch => ({
    inc () {
      dispatch(inc())
    },
    dec () {
      dispatch(dec())
    }
  })
)

Example

Keywords