Skip to content

littleLane/cvent

Repository files navigation

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
  • Debounce supports last times will be called
  • Keep improve...

License

MIT

About

A lightweight extension library based on browser events!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published