An extension library based on browser events!
You can install the stable version by npm:
$ npm i cvent
// or
$ yarn add cvent
Cvent provides flexible apis about event registration, unregistration, and trigger!
You can instantiate an object by
import Cvent from 'cvent'
const cvent = new Cvent()
Register a single event
const listener = (e) => {
console.log(e)
}
cvent.on('click', listener)
Register multiple events
const listener = (e) => {
console.log(e)
}
cvent.on('click1, click2', listener)
// Same as above
cvent.on(['click1', 'click2'], listener)
Unregister a single event
cvent.off('click', listener)
Unregister multiple events
cvent.off(['click1', 'click2'], listener)
Unregister a kind of events
cvent.off(['click1', 'click2'])
Trigger a kind of events
cvent.emit('click', [payload?: any])
Trigger a kind of events by debounce!
cvent.emit('click', [payload?: any], [debounceOptions])
DebounceOptions is an object!
Trigger a kind of events by throttle!
cvent.emit('click', [payload?: any], [throttleOptions])
ThrottleOptions is an object!
- Only respond to the first trigger of the event
- Debounce supports last times will be called
- Keep improve...