Last active
April 1, 2016 07:48
-
-
Save jamesmorgan/2917a9896dd16f57f2c400fab9759a59 to your computer and use it in GitHub Desktop.
GamesService.ConnectableObservable.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class GamesService { | |
/** Internal model state */ | |
private games:Object[]; | |
/** Private Subject **/ | |
private _gamesSource:Subject<Object[]> = new Subject<Object[]>(); | |
/** Public Observer **/ | |
gamesChanged$:Observable<Object[]> = | |
/** Create an Observable */ | |
this._gamesSource.asObservable() | |
/** | |
* publishReplay() = Changes return type fo ConnectableObservable see: http://reactivex.io/documentation/operators/replay.html | |
* The Observable will always emit the same complete sequence to any future observers, | |
* even those observers that subscribe after the connectable Observable has begun to emit items to other subscribed observers. | |
*/ | |
.publishReplay() // returns ConnectableObservable<T> | |
/** | |
* refCount() = turns ConnectableObservable and returns an ordinary Observable see: http://reactivex.io/documentation/operators/refcount.html | |
* Joining & disconnecting the underlying the ConnectableObservable to the Connectable. | |
* RefCount then keeps track of how many other observers subscribe to it and does not disconnect from the underlying connectable Observable until the last observer has done so. | |
*/ | |
.refCount() // return Observable<T> | |
/** share() = This will allow multiple Subscribers to one Observable */ | |
.share(); // return Observable<T> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment