Git Product home page Git Product logo

redux-action-types-creator's Introduction

redux-action-types-creator

build status

A simple lib help your define redux action type in easy way.

Installation

  yarn add redux-action-types-creator

Or

  npm install redux-action-types-creator --save

Usage

  import actionTypeCreator, { SYNC, ASYNC } from 'redux-action-types-creator'

  const actionType = actionTypeCreator('APP')

  const TODO_TYPES = actionType({
    TODO: {
      CREATE: SYNC,
      UPDATE: SYNC,
      FETCH: ASYNC,
      USER: {
        FETCH: ASYNC,
        DELETE: SYNC,
      }
    }
  })

  /**

  {
    TODO: {
      CREATE: '@@APP/TODO/CREATE',
      UPDATE: '@@APP/TODO/UPDATE',
      FETCH: {
        START: '@@APP/TODO/FETCH/REQUEST',
        SUCCESS: '@@APP/TODO/FETCH/SUCCESS',
        FAIL: '@@APP/TODO/FETCH/FAILURE',
        ALL: [
          '@@APP/TODO/FETCH/REQUEST',
          '@@APP/TODO/FETCH/SUCCESS',
          '@@APP/TODO/FETCH/FAILURE',
        ]
      },
      USER: {
        FETCH: {
          START: '@@APP/TODO/USER/FETCH/REQUEST',
          SUCCESS: '@@APP/TODO/USER/FETCH/SUCCESS',
          FAIL: '@@APP/TODO/USER/FETCH/FAILURE',
          ALL: [
            '@@APP/TODO/USER/FETCH/REQUEST',
            '@@APP/TODO/USER/FETCH/SUCCESS',
            '@@APP/TODO/USER/FETCH/FAILURE',
          ]
        },
        DELETE: '@@APP/TODO/USER/DELETE',
      }
    }
  }

  */

  // now you can access type like:

  console.log(TODO_TYPES.TODO.CREATE) // '@@APP/TODO/CREATE'
  console.log(TODO_TYPES.TODO.FETCH.ALL) // access all async types in easy way
  /*
    [
      '@@APP/TODO/FETCH/REQUEST',
      '@@APP/TODO/FETCH/SUCCESS',
      '@@APP/TODO/FETCH/FAILURE',
    ]
  */

SYNC: generate a single normal type.
ASYNC: generate three types for async operation.

You can define your own async types suffix by:

  actionTypeCreator('namespace', {
    asyncSuffix: [
     'START', 'SUCCESS', 'FAIL',  // default value is: ['REQUEST', 'SUCCESS', 'FAILURE']
    ]
  })

redux-action-types-creator's People

Contributors

darmody avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

redux-action-types-creator's Issues

don't depend on all of lodash

Hi! I love this module. I was trying to track down some bloat in my app, and found this module may be a culprit. It's importing all of lodash, when it really only needs

import T from 'lodash/fp/stubTrue';
import compose from 'lodash/fp/compose' ;
import concat from 'lodash/fp/concat';
import cond from 'lodash/fp/cond';
import drop from 'lodash/fp/drop';
import equals from 'lodash/fp/equals';
import keys from 'lodash/fp/keys';
import map from 'lodash/fp/map';
import merge from 'lodash/merge'
import placeholder from 'lodash/fp/placeholder';
import set from 'lodash/fp/set';
import split from 'lodash/fp/split';

I think splitting these up might help

here's how i tracked it down:

screen shot 2017-06-05 at 6 27 02 pm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.