Skip to content
This repository has been archived by the owner on May 9, 2018. It is now read-only.

theJian/redux-hoax

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-hoax

Higher-order action creators for Redux

Installation

npm install --save redux-hoax

Usage

Dispatch a action exactly once.

// Import specific utils by path
import once from 'redux-hoax/once';

// Your action creator
const actionCreator = () => ({ type: 'INITIALIZE' });

// Creator a action that can only be dispatched once
const actionOnce = once(actionCreator);

dispatch(actionOnce()); // Dispatch succeeded

dispatch(actionOnce()): // Dropped and will never reach the store

Create action payload from current app state

import withStore from 'redux-hoax/withStore';

const actionCreator = message => ({
  type: 'NEW_MESSAGE',
  payload: {
    message
  }
});

// Select if current user is active
const isUserActive = store => store.userStatus === 'ACTIVE';

const messageNotifyActionCreator = withStore(
  // Only turn on notifies when user is active
  store => ({ notify: isUserActive(store) })
)(actionCreator);

// Dispatch a action with payload merged with the result of withStore
// {
//   ...
//   payload: { message, notify }
//   ...
// }
dispatch(messageNotifyActionCreator(message));

License

MIT

About

Higher-order action creators for Redux

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published