Simple emitter based on Rx.Subject. Version 2+ is based on rxjs 5+
npm install rx-emitter
or
yarn add rx-emitter
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');
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!');
});
Rx-Emitter is released under the Apache 2.0 license.