Redux Action Utils
Factory functions for reducing action creator boilerplate.
npm install --save redux-action-utils
Before
var types = require('./action-types')
function addLesson() {
return {
type: types.ADD_LESSON
}
}
function importLessons(lessons) {
return {
type: types.IMPORT_LESSONS,
lessons
}
}
function updateLesson(options) {
return {
type: types.SELECT_LESSON,
id: options.id,
update: options.update
}
}
module.exports = {addLesson, importLessons, updateLesson}
After
var types = var actionCreator optionsActionCreator = moduleexports = addLesson: importLessons: updateLesson:
API
actionCreator(type: String)
Creates an action creator which will create an action object with the given type.
var ac = // → {type: 'ADD_LESSON'}
actionCreator(type: String, props: Array<String>)
actionCreator(type: String, ...props: String)
Creates an action creator which will create an action object with the given type and use the given property names to pass any positional arguments given to it.
var ac = // → {type: 'IMPORT_LESSONS', lessons: ['lesson 1', 'lesson 2']}
optionsActionCreator(type: String)
Creates an action creator which takes a single object argument and adds its properties to the action object.
optionsActionCreator(type: String, props: Array<String>)
optionsActionCreator(type: String, ...props: String)
Creates an action creator which takes a single object argument and adds only the specified properties from it to the action object.
var ac = /* →{ type: 'UPDATE_LESSON', id: 1, update: { text: '## Lesson 1' }}*/