Skip to content

williamoliveira/redux-act-light

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-act-light

A simpler and smaller version of redux-act, limited only to its core API

Install

# NPM
npm install redux-act-light --save
# Yarn
yarn add redux-act-light

Usage example

// Import functions
import { createStore } from 'redux'
import { createAction, createReducer } from 'redux-act-light'

// Create an action creator (type is required)
const add = createAction('ADD')
const increment = createAction('INCREMENT')
const decrement = createAction('DECREMENT')

// Create a reducer
const counterReducer = createReducer({
  [add]: (state, action) => state + action.payload,
  [increment]: state => state + 1,
  [decrement]: state => state - 1,
}, 0) // <-- This is the initial state

// Create the store
const store = createStore(counterReducer)

// Dispatch actions
store.dispatch(increment()); // store.getState() === 1
store.dispatch(increment()); // store.getState() === 2
store.dispatch(decrement()); // store.getState() === 1
store.dispatch(add(5)); // store.getState() === 6

Credits

About

Redux helpers inspired on the redux-act lib.

Resources

Stars

Watchers

Forks

Packages

No packages published