Skip to content

honeo/await-event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

await-event

なにこれ

Promiseインスタンスを返し、イベントを一度だけ掴んでresolve(event)する。
ブラウザ拡張機能のAPIでも動く(といいなと思っている)。

使い方

$ npm i @honeo/await-event

Browser (EventTarget)

import AwaitEvent from '@honeo/await-event';

// or Dynamic import, CDN
const AwaitEvent = await import('https://cdn.rawgit.com/honeo/await-event/master/index.mjs').then( (mod)=>{
	return mod.default;
});



(async function(){
	const event = await AwaitEvent(document.body, 'click', false);
	console.log(event.type); // "click"
}());

document.body.click();

Node.js (EventEmitter)

import AwaitEvent from '@honeo/await-event';
import {EventEmitter} from 'events';

const eventemitter = new EventEmitter();

(async function(){
	const event = await AwaitEvent(eventemitter, 'hoge');
	console.log(event.fuga); // "piyo"
}());

eventemitter.emit('hoge', {fuga: 'piyo'});

About

イベントの発生を待つやつ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published