Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dacho

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dacho

Utility of generating key/value object with a prefixed value

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

dacho

NPM version NPM downloads Build Status Coverage Status Dependency Status DevDependency Status License

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.

// constants/nettoActionTypes.js
import {reaction} from 'dacho';

export default reaction([
  'IN',
  'OUT',
  'PUSH'
], 'NETTO/')

// OR using Object.
//
// export default reaction({
//   IN: null,
//   OUT: null,
//   PUSH: null
// }, 'NETTO/');
// constants/odenActionTypes.js
import {reaction} from 'dacho';

export default reaction([
  'IN',
  'OUT',
  'PUSH',
  'SHOWER',
], 'ODEN/')

// OR using Object.
//
// export default reaction({
//   IN: null,
//   OUT: null,
//   PUSH: null
//   SHOWER: null
// }, 'ODEN/');
// actionCreator.js
import nettoActionTypes from './constants/nettoActionTypes';
import odenActionTypes from './constants/odenActionTypes';


function rejectBathing() {
  return {
    type: nettoActionTypes.PUSH,  // 'NETTO/PUSH'
    payload: {member: 'UESHIMA'}
  };
}

function rejectEating() {
  return {
    type: odenActionTypes.PUSH,  // 'ODEN/PUSH'
    payload: {member: 'UESHIMA'}
  };
}

// assert.deepEqual(nettoActionTypes, {
//   IN: 'NETTO/IN',
//   OUT: 'NETTO/OUT',
//   PUSH: 'NETTO/PUSH'
// });

// assert.deepEqual(odenActionTypes, {
//   IN: 'ODEN/IN',
//   OUT: 'ODEN/OUT',
//   PUSH: 'ODEN/PUSH'
//   SHOWER: 'ODEN/SHOWER'
// });

It throws Error when you create same value object.

// ./constants/nettoActionTypes2.js
import {reaction} from 'dacho';

export default reaction([
  'IN'
], 'NETTO/');

// -> throw Error because 'NETTO/IN' is already defined.

With Global Prefix

It generate object with global prefix.

// ./singletons/reaction.js
import {createReaction} from 'dacho';

export default createReaction('DEGAWA/')
// ./constants/degawaNettoActionTypes.js
import reaction from './singletons/reaction';

export default reaction([
  'IN',
  'OUT',
  'PUSH'
], 'NETTO/');

// import degawaNettoActionTypes from './constants/degawaNettoActionTypes';
//
// assert.deepEqual(degawaNettoActionTypes, {
//   IN: 'DEGAWA/NETTO/IN',
//   OUT: 'DEGAWA/NETTO/OUT',
//   PUSH: 'DEGAWA/NETTO/PUSH'
// });

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.

Keywords

FAQs

Package last updated on 13 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc