MOVED: https://github.com/frontrockets/redux-abstract-action
import AbstractAction from 'src/lib/AbstractAction'
// We create an Action constructor specifically for the collection (domain). We specify collection
// name by overriding `_namespace`. This can be easily automated by babel plugin.
class Action extends AbstractAction {
_namespace = 'Users'
}
// We create a new Action creator (setting a name can be easily automated by babel plugin)
const pullOne = new Action('pullOne', {
// Here we specify functions which will generate a payload according to arguments (we can specify
// generators for `init`, `success` and `failure` actions)
init: id => ({ id }),
success: data => data,
})
Every action has the following interface:
// To create actions:
pullOne.init()
pullOne.success()
pullOne.failure()
// To reference types of created actions:
pullOne.INIT_TYPE
pullOne.SUCCESS_TYPE
pullOne.FAILURE_TYPE
In our example above those functions will return this:
pullOne.init(10)
//- { type: 'Users/pullOne/INIT', payload: { id: 10 } }
pullOne.success({ name: 'Eugene' })
//- { type: 'Users/pullOne/SUCCESS', payload: { name: 'Eugene' } }
pullOne.failure()
//- { type: 'Users/pullOne/FAILURE', payload: {} }
pullOne.INIT_TYPE
//- 'Users/pullOne/INIT'
pullOne.SUCCESS_TYPE
//- 'Users/pullOne/SUCCESS'
pullOne.FAILURE_TYPE
//- 'Users/pullOne/FAILURE'