@strong-roots-capital/observable
v1.0.2
Published
Observe and react to EventSources
Downloads
6
Readme
Observable
Capable of observing and reacting to EventSources
Install
npm install @strong-roots-capital/observable
Use
import Observable from '@strong-roots-capital/observable'
import { EventSource } from '@strong-roots-capital/event-source'
class MyObservable extends Observable {
handleEvent(event: string | symbol, ...args: any[]) {
console.log(`In handleEvent with event '${event}' and arguments ${args}`)
}
}
const es = new EventSource()
const myobservable = new MyObservable()
myobservable.source = es
es.emit('some-event', 1, 2, 3)
//=> In handleEvent with event 'some-event' and arguments [1, 2, 3]