Socket
Book a DemoInstallSign in
Socket

redux-action-type-factory

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-action-type-factory

Simple tool to create redux action type list with minimal typing, but fully autocomplete support

1.1.4
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

redux-action-type-factory

Simple tool to create redux action type list with minimal coding, but fully autocomplete/intellisense support

Installation

npm i redux-action-type-factory

or

yarn add redux-action-type-factory

This relies on typescript for intellisense to run.

Usage

actionTypesFactory

  • actionTypesFactory accepts first argument as the prefix, if this is empty string then there will be no prefix, the remaining arguments will be the action types.

  • Each defined actionType has five members, with default is the action type itself, four others will append a suffix accordingly:
    default: ${ACTION}
    begin: ${ACTION}_BEGIN
    succeeded: ${ACTION}_SUCCEEDED
    failed: ${ACTION}_FAILED
    cancelled: ${ACTION}_CANCELLED

Use them as following:

import { actionTypesFactory } from "redux-action-type-factory";

let actionType = actionTypesFactory("todo", "INCREMENT", "DECREMENT");

actionType.INCREMENT.default; // 'todo/INCREMENT'
actionType.INCREMENT.begin; // 'todo/INCREMENT_BEGIN'
actionType.INCREMENT.succeeded; // 'todo/INCREMENT_SUCCEEDED'
actionType.INCREMENT.failed; // 'todo/INCREMENT_FAILED'
actionType.INCREMENT.cancelled; // 'todo/INCREMENT_CANCELLED'

actionType.DECREMENT.default; // 'todo/DECREMENT'
actionType.DECREMENT.begin; // 'todo/DECREMENT_BEGIN'
actionType.DECREMENT.succeeded; // 'todo/DECREMENT_SUCCEEDED'
actionType.DECREMENT.failed; // 'todo/DECREMENT_FAILED'
actionType.DECREMENT.cancelled; // 'todo/DECREMENT_CANCELLED'

// or

let actionType = actionTypesFactory("", "END");

actionType.END.default; // 'END'
actionType.END.begin; // 'END_BEGIN'
actionType.END.succeeded; // 'END_SUCCEEDED'
actionType.END.failed; // 'END_FAILED'
actionType.END.cancelled; // 'END_CANCELLED'

dictionaryFactory

  • For those who just want to make a string dictionary, use this. dictionaryFactory accepts a list of string argument, return an object with the according key-value pair.
import { dictionaryFactory } from "redux-action-type-factory";

let platforms = dictionaryFactory("android", "ios", "web", "desktop");

platforms.android; // 'android'
platforms.ios; // 'ios'
platforms.web; // 'web'
platforms.desktop; // 'desktop'

And this is fully supported by VS Code intellisense!

Keywords

redux

FAQs

Package last updated on 16 Jul 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.