npm.io
0.0.5 • Published 6 years ago

cvent

Licence
MIT
Version
0.0.5
Deps
0
Size
71 kB
Vulns
0
Weekly
0
Stars
1

cvent

An extension library based on browser events!

Installation

You can install the stable version by npm:

$ npm i cvent
// or
$ yarn add cvent

Usage

Cvent provides flexible apis about event registration, unregistration, and trigger!

You can instantiate an object by

import Cvent from 'cvent'

const cvent = new Cvent()
on

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)
off

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'])
emit

Trigger a kind of events

cvent.emit('click', [payload?: any])
emitDebounce

Trigger a kind of events by debounce!

cvent.emit('click', [payload?: any], [debounceOptions])

DebounceOptions is an object!

emitThrottle

Trigger a kind of events by throttle!

cvent.emit('click', [payload?: any], [throttleOptions])

ThrottleOptions is an object!

Future Features
  • Only respond to the first trigger of the event
  • Support the specified number of responses
  • Debounce supports last times will be called
  • Keep improve...
License

MIT