dacho
Utility of generating key/value object with a prefixed value.
For example, it is convenient to define ActionTypes for Flux, Redux and the like.
Besides, it prevent from defining same value. It throws Error if you registered already defined value.
dacho is named after Dacho Club that is Japanese comedy group.
They perform patterned reaction by the simple rules every time, but it is unique...
Installation
npm install --save dacho
Usage
Basic
It generate key/value object with a prefixed value.
import {reaction} from 'dacho';
export default reaction([
'IN',
'OUT',
'PUSH'
], 'NETTO/')
import {reaction} from 'dacho';
export default reaction([
'IN',
'OUT',
'PUSH',
'SHOWER',
], 'ODEN/')
import nettoActionTypes from './constants/nettoActionTypes';
import odenActionTypes from './constants/odenActionTypes';
function rejectBathing() {
return {
type: nettoActionTypes.PUSH,
payload: {member: 'UESHIMA'}
};
}
function rejectEating() {
return {
type: odenActionTypes.PUSH,
payload: {member: 'UESHIMA'}
};
}
It throws Error when you create same value object.
import {reaction} from 'dacho';
export default reaction([
'IN'
], 'NETTO/');
With Global Prefix
It generate object with global prefix.
import {createReaction} from 'dacho';
export default createReaction('DEGAWA/')
import reaction from './singletons/reaction';
export default reaction([
'IN',
'OUT',
'PUSH'
], 'NETTO/');
Tips
Testing
Despite collect values, It may raise Errors (key is already registered
) when executing unit tests.
One of solution of this problem is to use clear-require.
Example is here.
Flow
dacho
can use together with Flow annotation.
But, Flow version is 0.19 or higher.