@f/create-action

Action creator creator for flux standard actions

Stats

StarsIssuesVersionUpdatedCreatedSize
@f/create-action
201.1.16 years ago6 years agoMinified + gzip package size for @f/create-action in KB

Readme

create-action

Build status Git tag NPM version Code style

Action creator creator for flux standard actions. Very similar to the function of the same name found in redux-actions, but implemented as a micro-module and without the special error handling stuff.

Installation

$ npm install @f/create-action

Usage

var createAction = require('@f/create-action')
var incrementBy = createAction(INCREMENT_BY)

// ...

dispatch(incrementBy(2))

API

createAction(type, payloadCreator, metaCreator)

  • type - String or other identifier that represents the type of the action to create
  • payloadCreator - Function that produces payload from the arguments to the action creator (optional - defaults to https://github.com/micro-js/identity)
  • metaCreator - Function that produces meta from the arguments to the action creator (optional)

Returns: An action creator that creates an action according to the arguments specified.

toString sugar

Action creators returned by createAction override Function.prototype.toString, and instead return the type string. This allows the function to double as the action type, for useThis means that instead of writing this:

const SET_TEXT = 'SET_TEXT'
const setText = createAction('SET_TEXT')

export {
  setText,
  SET_TEXT
}

You can just write this:

export default createAction('SET_TEXT')

And then use it in a reducer map, like this:

combineReducers({
  text: handleActions({
    [setText]: (state, text) => text
  })
})

type property

If abusing toString as above makes you squeamish, then the type is also set on the type property of the action creator, so that you can access it that way as well, if you prefer.

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.