@jswork/we-mitt
v1.0.4
Published
Global(window) event emitter.
Downloads
41
Maintainers
Readme
we-mitt
Global(window) event emitter.
installation
npm install @jswork/we-mitt
usage
import WeEmitt from '@jswork/we-mitt';
const wemiter = new WeEmitt();
// on
const res = wemiter.on('abc', (data)=>{
console.log('attach abc event', data);
});
// do something...
wemiter.emit('abc', { id: 1, name: 'xx' });
// detatch
res.destory();
apis
| name | params | description | | ---- | ------------ | ------------------------------------ | | on | name,handler | register an event | | off | name,handler | unregister an event | | emit | name,obj | fire an event | | one | name,obj | fire an event,only can register once |
license
Code released under the MIT license.