Open xlearns opened 2 years ago
npm install mitt -S
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
npm install mitt -S
具体用法
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