项目作者: unlight

项目描述 :
Event emitter using DOM's addEventListener/dispatchEvent
高级语言: JavaScript
项目地址: git://github.com/unlight/onn.git
创建时间: 2019-06-23T15:45:54Z
项目社区:https://github.com/unlight/onn

开源协议:MIT License

下载


onn

Event emitter using DOM’s addEventListener/dispatchEvent

Usage

  1. const { on } = require('onn');
  2. const off = on(document, 'login', (event) => {
  3. console.log(`Hello, ${event.detail.name}!`); // => Hello, Bob!
  4. });
  5. document.dispatchEvent(new CustomEvent('login', { detail: { name: 'Bob' } }));
  6. off(); // Unsubscribe