Skip to content

n4bcak3/redux-delayed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-delayed

Build Status npm

Redux middleware for accepting actions with delayed dispatch

Usage

import delayedMiddleware from 'redux-delayed';

// Here our middleware's
const middlewares = [
  ...
  delayedMiddleware,
  ...
];

const enhancer = applyMiddleware(...middlewares)

// And creating store
const store = createStore(
  rootReducer,
  initState,
  enhancer
);

Types of actions

Default action (as object)

export function testAction() {
  return {
    type: TEST_ACTION,
    payload
  };
};

Action as function:

export function testAction(data) {
  ...
  return dispatch => {
    dispatch({
      type,
      payload
    })
  };
};

Action as Promise:

export function testAction(data) {
  return new Promise((resolve, reject) => {
     ...
     // Should be resolved/rejected with FSA
     resolve({
       type,
       payload
     })
  });
};

Combined action with promise and types:

export function testAction(data) {
  return {
    types: [
        TEST_ACTION, // dispatched on call
        TEST_ACTION_ON_RESOLVE, // dispatched if promise resolved
        TEST_ACTION_ON_REJECT // if rejected
    ],
    promise: () =>
      source.fetchSomeData(data)
  };
};

Contributing

If something is unclear, confusing, or needs to be refactored, please let me know. Will appreciate any help :3

About

Redux middleware for accepting actions with delayed dispatch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published