New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

actions-creator

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

actions-creator

actions-creator is an awesome javascript package that allows you to dynamically create action objects in Redux without having to declare constants and separate action-creator functions for each action.

latest
Source
npmnpm
Version
3.0.1
Version published
Maintainers
1
Created
Source

Actions Creator - Redux

You can find the full documentation on the website

Description

actions-creator is an awesome javascript package that allows you to dynamically create action objects in Redux without having to declare CONSTANTS and separate action-creator functions for each action.

Documentation

Installation

npm install actions-creator

Usage Example

import {actionsCreator} from 'actions-creator'

const action_1 = actionsCreator.MY.FIRST.ACTION('arg1')
//      {
//          type: 'MY/FIRST/ACTION',
//          payload: 'arg1',
//      } 

const action_2 = actionsCreator.This.is.my.second.action(2021)
//      {
//          type: 'This/is/my/second/action',
//          payload: 2021,
//      } 


// To get the type of action
String( actionsCreator.MY.FIRST.ACTION ) // 'MY/FIRST/ACTION'
// or
actionsCreator.MY.FIRST.ACTION().type // 'MY/FIRST/ACTION'

Actions With Callback

Sometimes we need the action to have callback capability. It might be necessary in many cases.

Actions Creator allows us to do this in a beautiful way: When we try to generate an action object, we can pass the callback function as the last argument. Actions Creator will check and if the last argument is a function, it will be considered as a callback function.

import {actionsCreator} from 'actions-creator'

const callback = () => {
    console.log('Hello, I am callback!!!')
}

const action = actionsCreator.MY.CALLBACKABLE.ACTION(123, callback)
//      {
//          type: 'MY/CALLBACKABLE/ACTION',
//          payload: 123,
//          cb: [Function callback],
//      }

action.cb() // 'Hello, I am callback!!!'

Syntax

actionsCreator.ANY.ACTION(payload, callback?)

  • payload <Any>
    Any value as a payload.
  • callback <Function>
    Any function as a callback.

Returns <Object>

  • type <String> Action type as a string.
        actionsCreator.ANY.ACTION().type === 'ANY/ACTION' // true
    
  • payload <Any>
    The value of the payload - given in the first argument.
            actionsCreator.ANY.ACTION(123).payload === 123 // true
    
  • cb <Function>
    The function of the callback - given in the last argument.
            const callback = () => {};
    
            actionsCreator.ANY.ACTION(123, callback).cb === callback // true
    

Customize

We do not recommend to customize, but if you need to do it, you can easily do that:
see: Produce By Path Pattern

Contributing

Read our contributing guide to learn about our development process.

Code of Conduct

This project has adopted the Contributor Covenant as its Code of Conduct, and we expect project participants to adhere to it. Please read the full text so that you can understand what actions will and will not be tolerated.

Authors

License

MIT License

Keywords

actions-creator

FAQs

Package last updated on 24 Oct 2022

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