{"name":"typed-emitter","version":"0.0.1","description":"Basic pub/sub/emitter class for React apps, inspired by Flux","main":"emitter.js","scripts":{"test":"node test.js && eslint *.js && echo 'Tests passed, eslint passed'"},"repository":{"type":"git","url":"git+https://github.com/wyantb/typed-emitter.git"},"keywords":["emitter","events"],"author":{"name":"Brian Wyant"},"license":"MIT","bugs":{"url":"https://github.com/wyantb/typed-emitter/issues"},"homepage":"https://github.com/wyantb/typed-emitter#readme","dependencies":{"lodash":"^4.11.1"},"devDependencies":{"eslint":"^2.8.0","eslint-config-airbnb":"^8.0.0","eslint-plugin-import":"^1.5.0"},"gitHead":"5917d86bce95622ecfcdb582fce16c76c068ac38","_id":"typed-emitter@0.0.1","_shasum":"9ab64ece9d878014b65d4a75e25b5f5ad669016f","_from":".","_npmVersion":"3.8.3","_nodeVersion":"5.10.1","_npmUser":{"name":"wyantb","email":"wyantb@gmail.com"},"maintainers":[{"name":"wyantb","email":"wyantb@gmail.com"}],"dist":{"shasum":"9ab64ece9d878014b65d4a75e25b5f5ad669016f","tarball":"http://registry-npm.ywwl.com/typed-emitter/download/typed-emitter-0.0.1.tgz","integrity":"sha512-yZay0bbxGQySwhE7jKjTgbCJSUHDRuhtXDuGiWtviQDtX1sqHRDFcqijRJKRYQTlnep7McVS6BxCENSjcZXh4w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH/ZzGFClDcl66IULc2akdK9R52ytmdo7ASjbGzpbGTiAiEAv+1hoPTEfS/qUd0jdVCzOtGUGDdEzUhwRaMTs9uUa1k="}],"size":1919,"noattachment":false,"key":"/typed-emitter/-/typed-emitter-0.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/typed-emitter-0.0.1.tgz_1461371857941_0.16576259746216238"},"directories":{},"readme":"# Typed-Emitter\n\n[![NPM Version](https://img.shields.io/npm/v/typed-emitter.svg)](https://www.npmjs.com/package/typed-emitter)\n\nStrictly typed event emitter interface for TypeScript.\n\nCode size: Zero bytes - Just the typings, no implementation. Use the default event emitter of the `events` module in node.js or bring your favorite implementation when writing code for the browser.\n\n\n## Installation\n\n```sh\n$ npm install --save-dev typed-emitter\n\n# Using yarn:\n$ yarn add --dev typed-emitter\n```\n\n\n## Usage\n\n```ts\nimport EventEmitter from \"events\"\nimport TypedEmitter from \"typed-emitter\"\n\n// Define your emitter's types like that:\n// Key: Event name; Value: Listener function signature\ntype MessageEvents = {\n  error: (error: Error) => void,\n  message: (body: string, from: string) => void\n}\n\nconst messageEmitter = new EventEmitter() as TypedEmitter<MessageEvents>\n\n// Good 👍\nmessageEmitter.emit(\"message\", \"Hi there!\", \"no-reply@test.com\")\n\n// TypeScript will catch those mistakes ✋\nmessageEmitter.emit(\"mail\", \"Hi there!\", \"no-reply@test.com\")\nmessageEmitter.emit(\"message\", \"Hi there!\", true)\n\n// Good 👍\nmessageEmitter.on(\"error\", (error: Error) => { /* ... */ })\n\n// TypeScript will catch those mistakes ✋\nmessageEmitter.on(\"error\", (error: string) => { /* ... */ })\nmessageEmitter.on(\"failure\", (error: Error) => { /* ... */ })\n```\n\n## Extending an emitter\n\nYou might find yourself in a situation where you need to extend an event emitter, but also want to strictly type its events. Here is how to.\n\n```ts\nclass MyEventEmitter extends (EventEmitter as new () => TypedEmitter<MyEvents>) {\n  // ...\n}\n```\n\nAs a generic class:\n\n```ts\nclass MyEventEmitter<T> extends (EventEmitter as { new<T>(): TypedEmitter<T> })<T> {\n  // ...\n}\n```\n\n## RxJS `fromEvent` types inference\n\nThe default `fromEvent` from RxJS will return an `Observable<unknown>` for our typed emitter.\n\nThis can be fixed by the following code, by replacing the `fromEvent` type with our enhanced one: `FromEvent`:\n\n```ts\nimport { fromEvent as rxFromEvent } from \"rxjs\"\nimport { default as TypedEmitter, FromEvent } from \"typed-emitter/rxjs\"\n\n// The `Observable` typing can be correctly inferenced\nconst fromEvent = rxFromEvent as FromEvent\n```\n\nLearn more from [rxjs fromEvent compatibility #9](https://github.com/andywer/typed-emitter/issues/9)\nfor the `fromEvent` compatibility discussions.\n\n## Why another package?\n\nThe interface that comes with `@types/node` is not type-safe at all. It does not even offer a way of specifying the events that the emitter will emit...\n\nThe `eventemitter3` package is a popular event emitter implementation that comes with TypeScript types out of the box. Unfortunately there is no way to declare the event arguments that the listeners have to expect.\n\nThere were a few other examples of type-safe event emitter interfaces out there as well. They were either not published to npm, had an inconsistent interface or other limitations.\n\n## License\n\nMIT\n","publish_time":1461371860379,"_cnpm_publish_time":1461371860379,"dist-tags":{"latest":"2.1.0","testing":"1.5.0-from-event"}}