synchronous-dispatcher

1.1.7 • Public • Published

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.

Package Sidebar

Install

npm i synchronous-dispatcher

Weekly Downloads

6

Version

1.1.7

License

Apache-2.0

Unpacked Size

25.4 kB

Total Files

10

Last publish

Collaborators

  • oppikone