mitt
https://github.com/developit/mitt
- mitt
- all
- on
- off
- emit ```jsx npm install —save mitt
//
import mitt from ‘mitt’
const emitter = mitt()
// listen to an event emitter.on(‘foo’, e => console.log(‘foo’, e) )
// listen to all events emitter.on(‘*’, (type, e) => console.log(type, e) )
// fire an event emitter.emit(‘foo’, { a: ‘b’ })
// clearing all events emitter.all.clear()
// working with handler references: function onFoo() {} emitter.on(‘foo’, onFoo) // listen emitter.off(‘foo’, onFoo) // unlisten
<a name="GLRxz"></a>
### ts
```tsx
import mitt from 'mitt';
type Events = {
foo: string;
bar?: number;
};
const emitter = mitt<Events>(); // inferred as Emitter<Events>
emitter.on('foo', (e) => {}); // 'e' has inferred type 'string'
emitter.emit('foo', 42); // Error: Argument of type 'number' is not assignable to parameter of type 'string'. (2345)
PubSubJS
https://github.com/mroderick/PubSubJS
npm install pubsub-js
import PubSub from 'pubsub-js'