0
假設我有以下類:如何在自定義類中使用RxJS?
class XHRUpload {
constructor() {
// Some AJAX code here and listening on progress event,
// and then pass the progress info out of this class.
}
}
另外我有一個可觀察對象:
const observable = Rx.Observable.create((obs) => {
obs.next(/* progress info here */)
})
但是我應該如何在課堂上使用此觀察的對象,以便能夠使用它的類外?
什麼,我現在就可以做的唯一的事情是這樣的:
const observable = Rx.Observable.create((obs) => {
new XHRUpload(obs)
// Then in the class...
obs.next(/* progress info here */)
})
// And then...
observable.subscribe({
next: value => {/* Progress data... */},
error: err => {/* Something bad has happened! */},
complete:() => {/* Transfer has been completed! */}
})
但它似乎是一個不好的做法,是不是?