Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-actions

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-actions

FSA compliant way of creating actions automatically

  • 2.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

create-actions

A tool to create action creators

Why would you use this?

If you're working with instances of alt or if you want to use action creators then this facilitates the creation of them by keeping your code concise.

Alt supports using action creators to dispatch, this means you can import your actions directly in a component to use them rather than inject it through using context.

Example action creator

const CountIncremented = {
  id: 'increment',
  dispatch() {
    return 1
  }
}

You can then listen to this action in your store normally

this.bindAction(CountIncremented, this.incrementCount)

and you can dispatch it using alt.dispatch

alt.dispatch(CountIncremented)

Writing various actions can be tedious so this tool creates a shorthand for creating them.

Use it to create your own actions. Actions return the data they want to dispatch. Good for use with Alt

import createActions, { dispatch } from 'create-actions'

export default createActions('UserActions', {
  loggedIn: dispatch,
  loggedOut: dispatch,
  changedName(newName) {
    request.put('/users', { id: 4, name: newName })
    return newName
  },
})

You can also generate actions if all they are doing is passing data directly through to the store.

import { generateActions } from 'create-actions'

export default generateActions('MusicActions', [
  'genreSelected',
  'songPlayed',
  'songStopped',
  'fetchRelatedAlbums',
])

Using this with something like redux is also straightforward.

import { generateActions } from 'create-actions'
const DocumentActions = generateActions('DocumentActions', ['changedTitle'])

store.dispatch(DocumentActions.changedTitle.dispatch('This is the new title'))

Keywords

FAQs

Package last updated on 31 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc