rxjs5

How do I - Long polling and Schedulers?

ぐ巨炮叔叔 提交于 2019-12-01 12:40:23
I am trying to schedule a long polling mechanism. And I was wondering if I could leverage Schedulers for that. Here's what I have been thinking so far. Schedule via timer, but only enqueue next iteration if previous iteration has already finished. Enqueue next iteration as previous iteration is finishing. I have been looking at existing schedulers, but I am not really sure which one to pick and what to overload. And last but not least - as I am a novice in Rx world - what are the advantages that the use of Scheduler would offer vis-a-vis "roll your own" approach. Something like this:

Angular HTTP Interceptor how to chain an observable

强颜欢笑 提交于 2019-12-01 08:49:10
I am using the Azure AD adal library to do authentication. There is a call to aquire a token that returns an observable. How can this observable be added into the intercept? In the below example, how can I get the request that is set inside the subscribe to be returned as the Observable? intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { this.authAzureService.getAccessToken() .subscribe(token => { // I need this to be returned request = this.getRequestWithHeaders(request, token); }); // This returns the request before the access token is added return next

this keyword for function parameter

走远了吗. 提交于 2019-12-01 08:22:01
Recently when I use Rxjs 5, I downloaded Rxjs by using npm install Rxjs@5.0.1, from downloaded code under node_modules, I found Observable.d.ts in Rxjs folder, I saw it declare its constructor like below: * * @constructor * @param {Function} subscribe the function that is called when the Observable is * initially subscribed to. This function is given a Subscriber, to which new values * can be `next`ed, or an `error` method can be called to raise an error, or * `complete` can be called to notify of a successful completion. */ constructor(subscribe?: <R>(this: Observable<T>, subscriber:

Combine multiple observable arrays into new object array

丶灬走出姿态 提交于 2019-12-01 08:09:50
I have 3 observable arrays like below. persons = [ { "firstName":"john", "lastName":"public", "locationID":"1", "departmentID":"100" }, { "firstName":"sam", "lastName":"smith", "locationID":"2", "departmentID":"101" } ] departments = [{"departmentID": "100", "name": "development" }, {"departmentID": "101", "name": "sales" }] locations = [{"locationID": "1", "name": "chicago"}, {"locationID":"2", "name": "ny"}] I am trying to combine these 3 into below result , result = [ { "firstName":"john", "lastName":"public", "location":"development", "department":"sales" }, { "firstName":"sam", "lastName"

this keyword for function parameter

家住魔仙堡 提交于 2019-12-01 06:53:46
问题 Recently when I use Rxjs 5, I downloaded Rxjs by using npm install Rxjs@5.0.1, from downloaded code under node_modules, I found Observable.d.ts in Rxjs folder, I saw it declare its constructor like below: * * @constructor * @param {Function} subscribe the function that is called when the Observable is * initially subscribed to. This function is given a Subscriber, to which new values * can be `next`ed, or an `error` method can be called to raise an error, or * `complete` can be called to

Combine multiple observable arrays into new object array

淺唱寂寞╮ 提交于 2019-12-01 05:09:07
问题 I have 3 observable arrays like below. persons = [ { "firstName":"john", "lastName":"public", "locationID":"1", "departmentID":"100" }, { "firstName":"sam", "lastName":"smith", "locationID":"2", "departmentID":"101" } ] departments = [{"departmentID": "100", "name": "development" }, {"departmentID": "101", "name": "sales" }] locations = [{"locationID": "1", "name": "chicago"}, {"locationID":"2", "name": "ny"}] I am trying to combine these 3 into below result , result = [ { "firstName":"john",

Flattening nested Observables

邮差的信 提交于 2019-12-01 03:54:45
I'm a stuck in nested observable hell and could do with a hand. I have the following block of code return this.findUser(term).map( users => { return users.map( user => this.getLastLogin(user.user_id).map( last_login => { user.last_login = last_login; return user; })); }); findUser returns Observable<User[]> and getLastLogin returns Observable<number> . I'm basically hoping to fetch a list of users and then update this with the information from another value. Right now the code above is returning <Observable<Observable<User>[]> . I thought I could replace the initial map with flatMap but this

How to handle multiple action types in one epic? Any cons of doing the same?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 02:40:45
Pretty new to redux-observables, rxjs and observables. Wanted to know how can I handle another action, say 'ActionTwo' in the same epic const Epic1 = (action$,store) => { return action$.ofType('ActionOne') .mergeMap((action) => { return ajax({'method': 'GET', 'url': 'someUrl') .map(response => resultActoin(action.userId, response.response)); } ); } Something like const Epic1 = (action$){ if('ActionOne') make a API call. if('ActionTwo') make some other API call. else do nothing. } Is it the same API call? If so, ofType() accepts more than one type. You can just do action$.ofType('ActionOne',

import .of() for Observable in typescript

半腔热情 提交于 2019-12-01 02:28:47
I'm using this great repo for my angular 2 test project (TypeScript) - https://github.com/qdouble/angular-webpack2-starter . And I need to use Observable.of(..) . When I try to import it: import { Observable } from "rxjs/Observable"; import { of } from 'rxjs/observable/of'; I get: Property 'of' does not exist on type 'typeof Observable'. I also tried it the following way: import { Observable } from "rxjs/Observable"; import { of } from 'rxjs/add/observable/of'; // notice 'add' I got: node_modules/rxjs/add/observable/of"' has no exported member 'of'. So, how can one import this Of() static

What does subscribe do, and how it is related to Observable?

血红的双手。 提交于 2019-12-01 02:01:47
I'm new to Angular and the tutorial I followed has the term " Observable ". The tutor explained it, but I didn't completely understand. What is an Observable , and why do we always have to call observable.subscribe() ? What does subscribe() actually do? What is an Observable ? An Observable can be seen as a data source. That data might exist (or not) and might change over time (or not). An Observable emits data, until it has nothing to emit anymore and then completes (there are some Observable that will never complete) or throws an exception (error handling is a big part of Observable