Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Type aliases

ICustomEventListener

ICustomEventListener: (evt: ICustomEvent) => void

Type declaration

IEventEachCallback

IEventEachCallback: (val: IEventEachCallbackParams) => void

Type declaration

IFireEvent

IFireEvent: (ev: string, payload?: any) => void

Type declaration

    • (ev: string, payload?: any): void
    • Parameters

      • ev: string
      • Optional payload: any

      Returns void

Procedure

Procedure: (...args: any[]) => void

Type declaration

    • (...args: any[]): void
    • Parameters

      • Rest ...args: any[]

      Returns void

Functions

debounce

  • debounce<F>(func: F, wait?: number, options?: IMemoOption): F

enhanceForEachEvent

  • enhanceForEachEvent(__namedParameters: { eachCallback: (val: IEventEachCallbackParams) => void; event: string | string[]; listener: undefined | ((evt: ICustomEvent) => void) }): void

getType

  • getType(data: any): string

sanitizateEventListener

throttle

  • throttle<F>(func: F, wait?: number, options?: IMemoOption): (Anonymous function)

Legend

  • Constructor
  • Method
  • Private property
  • Private method
  • Property
  • Static method

Generated using TypeDoc