state-types
v1.0.0
Published
Tiny and easy creating unique types in popular state-management solutions
Downloads
4
Readme
State types
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.