Simple EventTarget implementation.
MIT License
Simple implementation of EventTarget. Hosted on npm as @jsantell/event-target. ES6-ified for inclusion via module bundler.
$ npm install --save @jsantell/event-target
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!'));
$ npm run build
$ npm run version
MIT License, Copyright © 2018 Jordan Santell