Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

oj-event

orange-juice-nl14MIT6.0.0TypeScript support: included

Makes namespaced eventlisteners possible on any DOM element. (on('click.nmsp', () => {}); off('click.nmsp');

namespace, event, dom, listener

readme

Event

Adds on, once, off and has methods to the Window, Document and Element prototypes.

Usage

import

import "oj-event"

on

on(event: string | string[], cb: Function, opts?: IOptions): this

  • adds the namespaced callback as an eventListener
  • this will override any previous events with the same namespace
  • if event is an array will recursively call on with each event
window.on("click.namespace", e => { ... })

off

off(event: string | string[]): this

  • removes the namespaced event
  • if event is an array will recursively call off with each event
window.off("click.namespace")

has

has(event: string | string[]): boolean

  • returns true if the event or all events are subscribed
window.has("click.namespace")

Types

IOptions

{ 
  preventDefault?: boolean
  stopPropagation?: boolean
  capture?: boolean
  passive?: boolean 
 }