events manager very simple
All browser | Backend (Nodejs) | Mobile (React Native) |
---|---|---|
✅ | ✅ | ✅ |
Compatibility with all javascript project
npm install jetemit --save
const { on, emit } = require('jetemit');
//or
import { on, emit } from 'jetemit';
call
import { emit } from 'jetemit';
/**
* emit(name, value);
* name is string
* value any
*/
emit('TIME', '2018-12-01 12:30');
listener
import { on } from 'jetemit';
/**
* on(name,function)
* name is string
*/
on('TIME', time => {
console.log(time);
});
unsubscribe listener
import { on } from 'jetemit';
/**
* on return unsubscribe function
*/
const unsubscribe = on('TIME', time => {
console.log(time);
});
unsubscribe();