Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@allganize/dom-event-utils

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@allganize/dom-event-utils

Very small library that makes working with DOM event emitters API a little easier to work with

  • 1.1.1
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
Source

dom-event-utils

Very small library that makes working with DOM event emitters API a little easier to work with. These are all common utilities that I find myself reaching for, regardless of the framework I'm in.

Methods

eventToPromise - convert an event to a promise that resolves once it's called. For example:

import { eventToPromise } from 'dom-event-utils';

function createPopup() {
  const popup = window.open('/my-popup');
  return eventToPromise(popup, 'load', () => {
    // do stuff here
    return popup;
  }, 10000); //timeout is optional. If reached, it'll reject the promise
}

on - just like addEventListener, but returns an unsubscribe function.

import { on } from 'dom-event-utils';

const off = on(document.querySelector('.btn'), 'click', () => { /* click handler */ });
//...later, somewhere else...
off();

once - only called once and then unsubscribed from the event source

import { once } from 'event-utils';

once(document, 'DOMContentLoaded', () => {
  //...do things here
});

Keywords

FAQs

Package last updated on 03 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc