state-types
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

State types

styled with prettier Greenkeeper badge Build Status npm bundle size (minified) npm

Tiny and easy creating unique types in popular state-management solutions

Usage

You can simple generate types object in one function:

import types from 'state-types'
 
const testTypes = types('@@test', ['foo', 'bar'])
 
// Will return
 
{
  'foo': '@@test/foo',
  'bar': '@@test/bar'
}

Vuex mutations, actions, etc.

You can use it in vuex:

import types from 'state-types'
 
const testMutations = types('@@types', ['foo', 'bar'])
 
export default {
  state: false,
 
  mutations: {
    [testMutations.foo]: (state) => state = true,
    [testMutations.bar]: (state) => state = false
  }
}
 
...
 
// Import it where you want and use
 
this.$store.commit(testMutations.foo)

Redux actions types

You can use it in redux:

import types from 'state-types'
 
export const actionsTypes = types('@@types', ['foo', 'bar'])
export const actionsCreators = {
  [actionsTypes.foo]: () => ({
    type: actionsTypes.foo
  }),
  [actionsTypes.bar]: () => ({
    type: actionsTypes.bar
  })
}
 
export (state = false, action) => {
  switch(action.type) {
    case actionsTypes.foo:
      return true
    case actionsTypes.bar:
      return false
    default:
      return state
  }
}
 
...
 
// Import it where you want and use
 
dispatch(actionsCreators.foo())

Other cases

You can use it everywhere because it solution hasn't any semantic and code bindings to libraries and frameworks.

Dependencies (0)

    Dev Dependencies (31)

    Package Sidebar

    Install

    npm i state-types

    Weekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    11.7 kB

    Total Files

    13

    Last publish

    Collaborators

    • lamartire