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

redux-promise-thunk

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-promise-thunk

Thunk generator to dispatch Flux-Standard-Action in each phase of promise

  • 0.1.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

redux-promise-thunk

This lib can help you dispatch FSA(flux standard action) in each phase of your promise;

You need to use redux thunk as one of your middleware to make this lib work.

Install

npm i redux-promise-thunk

Usage

createPromiseThunk(actionName, promiseCreator [, metaCreator])

createPromiseThunk will create an action creator, but instead of action object, it returns a thunk function, which will be processed by redux-thunk.

The action creator created by createPromiseThunk only receives one parameter and will pass it to promiseCreator. Example:

//editTodo is a thunk
const editTodo = createPromiseThunk('EDIT_TODO', function(todo) {
  return todoApi.edit(todo); //todoApi.edit() should return a Promise object;
});

//TodoItem.jsx
const {editTodo} = bindActionCreators(actions, dispatch);

class TodoItem extends Component {
  //...
  handleEdit(todo) {
    editTodo(todo);//only one parameter is allowed, and will be passed to promiseCreator;
  }
  //...
}

The thunk function will dispatch following flux standard actions(FSA) for the promise you returned in promiseCreator:

NameWhenpayloadmeta.asyncStep
${actionName}_STARTpromiseCreator(data) been calledfirst argument of promiseCreator'START'
${actionName}_COMPLETEDpromise resolvedvalue of promise'COMPLETED'
${actionName}_FAILEDpromise rejectedreason of promise'FAILED'

Example

Check examples/todo-mvc for further info, the TodoActions.editTodo shows optimistic update with composed thunk. and loadingMiddleWare shows how to do some aspect things like loading label with action.meta.asyncStep

Keywords

FAQs

Package last updated on 19 Jan 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