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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tiny-flux

v0.0.2

Published

A very small, fast implementation of the Flux design pattern

Readme

tiny-flux

A very small, fast implementation of the Flux design pattern. It does exactly what you need, and nothing more. Less than 200 lines uncompressed, 800 bytes when minified and gzipped.

Installation

npm install tiny-flux

Download

If you're not using npm you can simply download the source here: tiny-flux.js, or as a minified file here: bin/tiny-flux.min.js.

Usage


var Dispatcher = require('tiny-flux').Dispatcher,
	Store = require('tiny-flux').Store;

// Alternative without require:

var Dispatcher = TinyFlux.Dispatcher,
	Store = TinyFlux.Store;

Example


/* Constructing a Dispatcher */
var MyDispatcher = new Dispatcher();

/* Constructing a Store */
var MyStore = new Store({
	dispatcher: MyDispatcher,
	initialize: function() {

		this.number = 0; // only accessible from inside the Store methods

		this.func = function() {
			// autobinding 'this'
			return this.number * 2;
		};

	},
	callback: function(action) {

		switch (action.type) {
			case INCREMENT_NUMBER:
				this.number++;
				this.emitChange();
				break;
		}

	},
	getNumber: function() {
		return this.number;
	},
	getCalculation: function() {
		return this.func();
	}
});

/* Constructing another Store */
var MyOtherStore = new Store({
	dispatcher: MyDispatcher,
	initialize: function() {
		this.otherNumber = MyStore.getNumber() * 10;
	},
	callback: function(action) {

		MyDispatcher.waitFor(MyStore);
		if (MyDispatcher.didEmitChange(MyStore)) {
			this.otherNumber = MyStore.getNumber() * 10;
			this.emitChange();
		}

	},
	getOtherNumber: function() {
		return this.otherNumber;
	}
});

/* Dispatching an action */
MyDispatcher.dispatch({
	type: INCREMENT_NUMBER
});

/* Listening to changes */
function updateView() {
	var otherNumber = MyOtherStore.getOtherNumber();

	// ...
};
MyOtherStore.addChangeListener(updateView);

/* Removing change listeners */
MyOtherStore.removeChangeListener(updateView);

Documentation

The Dispatcher

The Dispatcher is a simple constructor that takes no arguments. You construct a Dispatcher like so:


var MyDispatcher = new Dispatcher();
// That's all!

MyDispatcher will have the following methods:

Method: register(store, callback)

This registers a new store to the dispatcher. The store argument can be anything, but a TinyFlux Store object is recommended. The callback will be the function that's called for handling an action.

Example usage:


var MyStore = {};
MyDispatcher.register(MyStore, function(action) {
	// ...
});

Note: If you use a custom object like in this example instead of a TinyFlux Store, your callback needs to return whether or not it emitted a change (boolean). If you use the TinyFlux Store, this will be handled automatically.

Method: dispatch(action)

This dispatches the supplied object, action, handing it to all the registered stores.

Example usage:


MyDispatcher.dispatch({
	type: ACTION_TYPE,
	property: // ...
});
Method: waitFor(store1, store2, ..., storeN)

When called it makes sure that stores 1 through N have handled the current action before continuing in the current callback.

Note: Must be called from within a store callback.

Example usage:


var MyStore = {};
MyDispatcher.register(MyStore, function(action) {
	// ...
});

var MyOtherStore = {};
MyDispatcher.register(MyOtherStore, function(action) {
	// ... might execute before MyStore, might execute after MyStore

	MyDispatcher.waitFor(MyStore);

	// ... will definitely execute after MyStore
});
Method: didEmitChange(store1, store2, ..., storeN)

Tells you whether any of the stores from 1 through N have emitted a change. If any have, it'll return true, otherwise false.

Note: Must be called from within a store callback.

Example usage:


var MyStore = {};
MyDispatcher.register(MyStore, function(action) {
	// ...
});

var MyOtherStore = {};
MyDispatcher.register(MyOtherStore, function(action) {
	MyDispatcher.waitFor(MyStore);
	if (!MyDispatcher.didEmitChange(MyStore))
		return;

	// ... will only execute if MyStore has changed.
	// ... useful for creating stores whos data depends on other stores
});
Method: addPostDispatchCallback(callback) and removePostDispatchCallback(callback)

Internal functions...

The Store

The Store is a constructor for creating a TinyFlux Store object that gives you all the functionality you want from a Flux Store in a simple package.

A Store works like so:


var MyStore = new Store({
	dispatcher: MyDispatcher, // what Dispatcher does this store listen to?
	initialize: function() {

		this.myPrivateNumber = 0; // only accessible from inside the store
		this.myPrivateFunction = function() {
			// 'this' can always from within private functions as well
			return this.myPrivateNumber * 2;
		};

	},
	callback: function(action) {
		// this callback function is automatically registered with the dispatcher: MyDispatcher

		switch (action.type) {
			case INCREMENT_NUMBER:
				this.myPrivateNumber++;
				this.emitChange(); // call this to emit a change
				break;

			default:
				break;
		}

	},
	getPrivateNumber: function() {
		// public function
		return this.myPrivateNumber;
	},
	getPrivateCalculation: function() {
		return this.myPrivateFunction();
	}
});

MyStore will have the following methods:

Method: getPrivateNumber() and getPrivateCalculation()

The methods you define in the constructor object will be available.

Example usage:


MyStore.getPrivateNumber();
Method: addChangeListener(callback)

This method allows you to listen for changes emitted by the Store.

Example usage:


MyStore.addChangeListener(function() {
	updateUI();
});
Method: removeChangeListener(callback)

This method allows you to remove callbacks from the Store.

Example usage in a React component:


var MyComponent = React.createComponent({
	componentWillMount: function() {
		MyStore.addChangeListener(this.handleChange);
	},
	componentWillUnmount: function() {
		MyStore.removeChangeListener(this.handleChange);
	},
	handleChange: function() {
		// ...
	},
	render: function() {
		// ...
	}
});