Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Latest commit

 

History

History
85 lines (58 loc) · 1.95 KB

README.md

File metadata and controls

85 lines (58 loc) · 1.95 KB

Rx-Emitter

Simple emitter based on Rx.Subject. Version 2+ is based on rxjs 5+

npm version Build Status Code Climate CircleCI dependencies:? devDependencies:?

Installation

npm install rx-emitter

or

yarn add rx-emitter

Usage

import Emitter from 'rx-emitter';
// or
// const Emitter =  require('rx-emitter);

class Application extends Emitter {
}

const app = new Application();

app.subscribe('loaded', () => {
  console.log('Loaded event has been fired successfully!');
});

Rx.Observable.combineLatest(
  app.subject('loaded'),
  app.subject('model-ready')
)
.subscribe(() => {
  console.log('Two events were fired in any order');
});


app.publish('loaded');

Configuration

You can configure emitter with different types of Subject.

Example:

class Application extends Emitter {
  constructor() {
    super({
      loaded: () => new Rx.ReplaySubject(1)
    });

    this.publish('loaded');
  }
}

const app = new Application();
app.subscribe('loaded', () => {
  console.log('Application loaded!');
});

License

Rx-Emitter is released under the Apache 2.0 license.

Donate