magic-action-types

1.0.1 • Public • Published

✨ Magical ✨ Action Types (for Flux, Redux, etc)

But why tho?

This is annoying.

const INCREMENT = 'app/counter/INCREMENT'
const DECREMENT = 'app/counter/DECREMENT'

This is weird.

const types = keyMirror({
  INCREMENT: null,
  DECREMENT: null,
})

But this is ✨ magical ✨

const { INCREMENT, DECREMENT } = types('app/counter')

Usage

npm install magic-action-types

Use object destructuring to simplify your action type definitions.

import types from 'magic-action-types'
 
const { INCREMENT, DECREMENT } = types()
// INCREMENT === "INCREMENT"
// DECREMENT === "DECREMENT"

Pass a namespace to the types function.

const { INCREMENT, DECREMENT } = types('app/counter')
// INCREMENT === "app/counter/INCREMENT"
// DECREMENT === "app/counter/DECREMENT"

Go ahead, save your namespace too.

const counterTypes = types('app/counter')
 
const { INCREMENT, DECREMENT } = counterTypes
// INCREMENT === "app/counter/INCREMENT"
// DECREMENT === "app/counter/DECREMENT"

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    0
  • 1.0.0
    1

Package Sidebar

Install

npm i magic-action-types

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • markalfred