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

add-promise-listener

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-promise-listener

Using promises as generic event listener

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
59
increased by20.41%
Maintainers
0
Weekly downloads
 
Created
Source

add-promise-listener

Using promises as generic event listener.

import addPromiseListener from 'https://esm.run/add-promise-listener';

const button = document.getElementById('test-button');
const ac = new AbortController;
addPromiseListener(
  button,
  'click',
  {
    // optional: stopPropagation, stopImmediatePropagation or ...
    preventDefault: true,
    // optional signal to eventually catch rejections
    signal: ac.signal
  }
).then(
  event => {
    console.log(`${event.type}ed 🥳`);
    console.assert(event.currentTarget === button, 'currentTarget');
    console.assert(event.defaultPrevented, 'defaultPrevented');
  },
  event => {
    console.error(event.target.reason);
  }
);

// simulate a rejection in 5 seconds
setTimeout(() => ac.abort('timeout!'), 5000);

Keywords

FAQs

Package last updated on 11 Oct 2024

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