type-stash

1.0.1 • Public • Published

type-stash

Redux type-management library:

Why type-stash:

  • it removes the need for a dedicated "types" file
  • I developed this because I found the process of creating types to be disruptive

Index:

  1. Installation:
  2. Usage:
  3. API:
  4. Dependencies:
  5. Author:
  6. License:

Installation:

npm install --save type-stash

Usage:

  • access your types through the library's .use() method
  • if there is no existing constant that matches the input, it creates it; otherwise, it returns it

Actions:

// Before:
import { type__APP_RENDER } from '../App_types.js';

export default (bool) => {
  return {
    type: type__APP_RENDER,
    payload: bool
  };
};

// After:
import typeStash from 'type-stash';

export default (bool) => {
  return {
    type: typeStash.use('APP_RENDER'),
    payload: bool
  };
};

Reducers:

// Before:
import { type__App_RENDER } from '../App_types.js';

export default (state = false, action) => {
  switch(action.type) {
    case type__App_RENDER:
      return action.payload;
    default:
      return state;
  };
};

// After:
import typeStash from 'type-stash';

export default (state = false, action) => {
  switch(action.type) {
    case typeStash.use('App_RENDER'):
      return action.payload;
    break;
    default:
      return state;
  };
};

API:

typeStash.use([string]):

  • This method lets you access and create type's through the library
  • By convention, name your types in all caps

Arguments([1]):

  1. [type_name]:
    • A string which gets used as the type

Returns: [string]

Example:

typeStash.use('POST_CREATE');

Dependencies:

-none

Author:

Dane Sirois

License:

MIT

Readme

Keywords

Package Sidebar

Install

npm i type-stash

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • dane_sirois