GithubHelp home page GithubHelp logo

vijaypemmaraju / action-utils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from groovelabs/action-utils

0.0 1.0 0.0 22 KB

helpers for creating well-named redux actions in a declarative way

JavaScript 100.00%

action-utils's Introduction

action-utils

A set of helper functions that are meant to help declare redux actions in a object-like way while still allowing for well-named actions.

createActions(actions:Object)

Takes in a plain javascript object and returns back the same object shape, but with every leaf in the tree prefixed with all its parents. For example:

createActions({
  FOO: keyMirror(['BAR']),
})

will be transformed to:

{
  FOO: {
    BAR: 'FOO/BAR',
  }
}

This allows for the actions to be nicely namespaced as both javascript objects and uniquely prefixed strings.

keyMirror(keys:Array<String>)

Takes in a list of strings and returns a plain Javascript object with the values mirroring the keys. For example:

keyMirror(['FOO', 'BAR'])

will be transformed to:

{ FOO: 'FOO', BAR: 'BAR' }

standardActions()

This is an opinionated usage of keyMirror that provides some default action names to represent lifecycles (BEGIN, PROGRESS, SUCCESS, FAILURE). This is very useful for any kind of action that involves an API call.

Usage

import { createActions, keyMirror, standardActions } from 'action-utils';

export const actionTypes = createActions({
  PEOPLE: {
    FETCH_PEOPLE: standardActions(),
    ...keyMirror([
      'SELECT_PEOPLE',
      'UNSELECT_PEOPLE',
      'SET_ACTIVE_PERSON_ID',
      'UNSET_ACTIVE_PERSON_ID',
      'MOVE_TO_PAGE',
    ]),
  },
}).PEOPLE;

action-utils's People

Contributors

vijaypemmaraju avatar

Watchers

 avatar

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.