An ultra rapid and super efficient event dispatcher framework for hyper fast coding in JavaScript.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.gitignore
.npmignore
README.md
gruntfile.js
index.js
package.json

README.md

Synchronous Dispatcher is deprecated!

Synchronous Dispatcher is deprecated. Development is continued in Metamatic package!

introduction

This is a synchronous dispatcher that enables you to dispatch application-wide events everywhere in your app and handle them everywhere inside your app. Simple is beautiful - and usually works better as well! This is a framework for no-nonsense fast coding. Just forget all academic theorizations for a second and try it out - You'll notice that this just works. Use it with Angular or React or whatever you like.

If you like to know more about Synchronous Dispatcher, please visit the blog post or check out a sample React App using Synchronous Dispatcher.

Installation

npm install synchronous-dispatcher

Usage

When you want to dispatch an event somewhere in your app:

import { dispatch } from 'synchronous-dispatcher';

dispatch('MY-EVENT', someObject);

And when you want to catch the event:

import { handle } from 'synchronous-dispatcher';

handle('MY-EVENT', function(item) {
  console.log('I catch the event here..');
  console.log(item);
});

You can also register a handler under specified ID. It is useful when you want to explicitely remove that handler later:

handle('MY-EVENT', 'MANAGER', function(item) {
  console.log('I catch the event here..');
  console.log(item);
});

Note that if you define a new handler for 'MY-EVENT' under same ID 'MANAGER', your new handler will override the previous one. If you want one event to launch many handlers, you must define each handler under different ID!

When you want to kill a certain handler for a certain event, in this case a handler with id 'MANAGER' for 'MY-EVENT':

import { unhandle } from 'synchronous-dispatcher';

unhandle('MY-EVENT', 'MANAGER')

License

Apache 2.0

Author

Heikki Kupiainen / Oppikone

Tutorial

Please visit the blog post for tutorial.