@jsantell/event-target
v1.1.3
Published
EventTarget class
Downloads
30
Readme
event-target
Simple implementation of EventTarget. Hosted on npm as @jsantell/event-target. ES6-ified for inclusion via module bundler.
Installation
$ npm install --save @jsantell/event-target
Usage
import EventTarget from '@jsantell/event-target';
class ChunkReader extends EventTarget {
constructor(data) {
this.data = data;
requestAnimationFrame(() => this.read(data));
}
read() {
for (let i = 0; i < this.data.length; i += 4) {
this.dispatchEvent('chunk', this.data.substr(i, 4));
}
this.dispatchEvent('end');
}
}
const reader = new ChunkReader('hello world!');
reader.addEventListener('chunk', c => console.log('chunk!'));
reader.addEventListener('end', () => console.log('end!'));
Build
$ npm run build
Publish
$ npm run version
License
MIT License, Copyright © 2018 Jordan Santell