@jsantell/event-target

EventTarget class

Usage no npm install needed!

<script type="module">
  import jsantellEventTarget from 'https://cdn.skypack.dev/@jsantell/event-target';
</script>

README

event-target

Build Status

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