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

flux-dispatcherasync

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

flux-dispatcherasync

Async flux dispatcher with promises

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

flux-dispatcherasync

Async flux dispatcher with promises

Works as the original dispatcher, except when the callback returns a promise.

When a promise is returned the flow will wait for the resolve of the promise to continue. The waitfor for the promise should be called outside the depending callback as the waitfor does not wait by itself. Best is to register a so called main callback, which checks for dependencies for the payload and calls the appropriate waitfor(s).

Usage

import {Dispatcher} from "flux";
import "./lib/dispatcherAsync";

const dispatcher = new Dispatcher();
//see code example https://facebook.github.io/flux/docs/dispatcher/ for more information.

//general dispatcher needs to be registered first
dispatcher.register(function (payload) {
	switch (payload.actionType) {
		case "SaveClient":
			dispatcher.waitFor([Client.dispatchToken]);
			
		//and continue	...
	}
});

Client.dispatchToken = dispatcher.register(function(payload) {
  if (payload.actionType === 'FetchClient') {
    return new Promise((resolve, reject) => {
        //do some logic and resolve
        resolve();
    });
  }
});


Keywords

FAQs

Package last updated on 08 Nov 2019

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