1.0.0 • Published 8 years ago

redux-namer v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

Naming your Redux actions as constants is extremely important! Naming your async Redux actions can be quite boring.

How do you achieve the readability of constant action names without getting bored by code like the following?

  export const FETCH_TODO_REQUEST = FETCH_TODO_REQUEST;
  export const FETCH_TODO_FAILURE = FETCH_TODO_FAILURE;
  export const FETCH_TODO_SUCCESS = FETCH_TODO_SUCCESS;

redux-namer is very tiny library that allows you to achieve the same effect, but with this code:

  import namer from 'redux-namer'; // Import library

  let name = namer('todo'); // Create todo namespace
  export const FETCH_TODO = name.async('fetch');
  export const ADD_TODO = name.sync('add');

  console.log(FETCH_TODO);
  /*
    object {
      request: TODO_FETCH_REQUEST,
      failed: TODO_FETCH_FAILED,
      done: TODO_FETCH_DONE,
    }
  */

  console.log(ADD_TODO);
  /*
    string TODO_ADD
  */

Using camelCase or snake_case

  import {camelCase as namer} from 'redux-namer'; // Import library
  // for snake_case, use:
  // import {snake_case as namer} from 'redux-namer';

  let name = namer('todo'); // Create todo namespace
  export const FETCH_REMOTE = name.async('FETCH_REMOTE');
  export const FETCH_LOCAL = name.sync('fetch local');

  console.log(FETCH_MINE);
  /*
    object {
      request: todo.fetchRemote.request,
      failed: todo.fetchRemote.failed,
      done: todo.fetchRemote.done,
    }
  */

  console.log(ADD_TODO);
  /*
    string todo.fetchLocal
  */
1.0.0

8 years ago