I am having problems with some observables. It seems I canβt get two observables in order to combine each other well. They work great on their own, but I need both values.
db.glass.subscribe( ( glass: GlassData[] ): void => { console.log( glass );
Not everyone is familiar with the observables, the first thing I tried was nested into each other, but the inner one seems to do nothing.
db.glass.subscribe( ( glass: GlassData[] ): void => { console.log( glass );
It seemed a little silly, so I searched on Google to find out if there is a better way to combine observables, and it turns out that there are several. I tried zip and forkJoin as they looked the most similar to what I wanted to do, but nothing forkJoin with them.
Observable.zip( db.cassette_designs, db.glass, ( cassettes: CassetteData[], glass: GlassData[] ): void => { console.log( cassettes );
It may be something simple, as I am calling functions incorrectly, but I would have thought that at some point I would get some warning or error. tsc does not have any code problems, and I do not receive messages in the console developer on Chrome or Firefox.
Update
I tried combineLatest , but it still doesn't display anything in the console. I have to miss something, but I'm not sure what. They work individually.
Observable.combineLatest( db.cassette_designs, db.glass, ( cassettes: CassetteData[], glass: GlassData[] ): void => { console.log( cassettes );
Observables are created as follows:
... public Listen( event: string ): Observable<Response> { return new Observable<Response>( ( subscriber: Subscriber<Response> ): Subscription => { const listen_func = ( res: Response ): void => subscriber.next( res ); this._socket.on( event, listen_func ); return new Subscription( (): void => this._socket.removeListener( event, listen_func ) ); }); } ...
Then, in order to actually get the observables, I send a response listen to the corresponding event. eg.
... public cassette_designs: Observable<CassetteData[]>; ... this.cassette_designs = _socket.Listen( "get_cassette_designs" ) .map( ( res: Response ) => res.data.data );