npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mctigger-flux-dispatcher

v0.3.1

Published

A flux dispatcher

Downloads

1

Readme

flux-dispatcher

This is a dispatcher for Facebook's (React) Flux architecture.

##Installation

npm install mctigger-flux-dispatcher

##Dependencies

Just like React the dispatcher requires a polyfill for ES5 methods such as Array.prototype.every IF you need to support older browsers. If you support modern browsers only, you are fine to go without any dependencies.

##Use

Stores can be registered like this

dispatcher.register('action1', [], store1Function);

or like this

dispatcher.register({
	action: 'action1',
	dependencies: [],
	fn: store1Function
});

Synchronous

var Dispatcher = require('mctigger-flux-dispatcher');

var d = new Dispatcher();

var THREAD_SELECTED_ACTION = 'thread_selected_action';

var MessageStore = {};
var ThreadStore = {};

ThreadStore.onThreadSelected = d.register(THREAD_SELECTED_ACTION, [], function(payload, next) {
	// Do something important here and use the payload

	console.log(payload);
	console.log('A');

	// Don't forget to call next!
	next();
});

MessageStore.onThreadSelected = d.register(THREAD_SELECTED_ACTION, [ThreadStore.onThreadSelected], function(payload, next) {
	// Do something important here

	console.log(payload);
	console.log('B');

	next();
});

d.dispatch(THREAD_SELECTED_ACTION, 1);

Result:

	-> 1
	-> A
	-> 1
	-> B

Asynchrous

Just a little change in onThreadSelected to demonstrate how the dispatcher works with async dependencies.

ThreadStore.onThreadSelected = d.register(THREAD_SELECTED_ACTION, [], function(payload, next) {
	// Do something important here and use the payload

	console.log(payload);
	console.log('A');

	setTimeout(function() {
		// Don't forget to call next!
		next();
	}, 1000);
});

Result:

	-> 1
	-> A
	After 1000ms
	-> 1
	-> B

Optimistic updates

You can combine synchronous and async dependencies to create optimistic updates.

var Dispatcher = require('mctigger-flux-dispatcher');

var d = new Dispatcher();

var THREAD_SELECTED_ACTION = 'thread_selected_action';

var MessageStore = {};
var ThreadStore = {};

ThreadStore.onThreadSelected = d.register(THREAD_SELECTED_ACTION, [], function(payload, next) {
	console.log('C');
	loadThreadFromServer(function() {
		console.log('D');
		next();
	});
});

ThreadStore.onThreadSelectedOptimistic = d.register(THREAD_SELECTED_ACTION, [], function(payload, next) {
	console.log('A');
	next();
});

MessageStore.onThreadSelected = d.register(THREAD_SELECTED_ACTION, [ThreadStore.onThreadSelected], function(payload, next) {
	console.log('E');
	next();
});

MessageStore.onThreadSelectedOptmistic = d.register(THREAD_SELECTED_ACTION, [ThreadStore.onThreadSelectedOptimistic], function(payload, next) {
	console.log('B');
	next();
});

d.dispatch(THREAD_SELECTED_ACTION, {id: 2});

Result

	-> A/C Update UI with cached data here
	-> B Update UI with cached data here
	After server responded
	->D Update UI with the real data
	->E Update UI with the real data