rxjs5

What are the semantics of different RxJS subjects?

我的未来我决定 提交于 2019-11-26 12:27:44
Documentation for the topic is sparse and it's hard to discover an "entry-point" there. user3743222 Semantics differ according to the type of subjects. I will divide them in two kinds : vanilla ( Rx.Subject ), and special-purpose subjects (the other three). The special-purpose subjects share part of the semantics of the vanilla subject with a few caveats due to their specialization (for instance, completion/reconnection behaviour). Vanilla Rx.Subject semantics Key features subjects implement the observer, observable interface (and the disposable interface as they have a dispose handler on

When to use asObservable() in rxjs?

大城市里の小女人 提交于 2019-11-26 11:59:20
问题 I am wondering what is the use of asObservable: As per docs: An observable sequence that hides the identity of the source sequence. But why would you need to hide the sequence? 回答1: When to use Subject.prototype.asObservable() The purpose of this is to prevent leaking the "observer side" of the Subject out of an API. Basically to prevent a leaky abstraction when you don't want people to be able to "next" into the resulting observable. Example (NOTE: This really isn't how you should make a

How to get an observable to return data immediately and every 5 seconds thereafter

♀尐吖头ヾ 提交于 2019-11-26 11:21:01
问题 I want to create an observable that returns data from a webapi. I\'d like it to return the data immediately, and poll the API every 10 seconds. The code below shows I\'m using the \'interval\' method. But this delays the first set of data by 10 seconds. How do I get that first flush of data to come down with no initial delay? export class EventService { public events$: Observable<Event[]>; private _eventsObserver: Observer<Event[]>; private pollInterval: number = 5000; private _dataStore: {

How to return value from function which has Observable subscription inside?

爷,独闯天下 提交于 2019-11-26 05:26:44
问题 I dont know how to extract value from Observable to be returned by function in which Observable is present. I need just a value from it to be returned, nothing else. Current version which works function getValueFromObservable() { this.store.subscribe( (data:any) => { console.log(data) } ) } getValueFromObservable() I need this to work, function to return value, and then: function getValueFromObservable() { this.store.subscribe( (data:any) => { return data } ) } console.log

How to force observables to execute in sequence?

ε祈祈猫儿з 提交于 2019-11-26 04:27:54
问题 I am moving from the Promise world to the Observable world. One thing I usually do with Promise is to chain a series of tasks and make them run in sequence. For example, I have three tasks: printLog1() to print 1 to the console, printLog23() to print 2 and 3 to the console, and printLog4() to print 4. When I want to print 1-2-3-4, I would write a promise chain like printLog1() .then(() => { printLog23(); }) .then(() => { printLog4(); }); Now I want the same functionality with Observable and I

What are the semantics of different RxJS subjects?

醉酒当歌 提交于 2019-11-26 03:36:28
问题 Documentation for the topic is sparse and it\'s hard to discover an \"entry-point\" there. 回答1: Semantics differ according to the type of subjects. I will divide them in two kinds : vanilla ( Rx.Subject ), and special-purpose subjects (the other three). The special-purpose subjects share part of the semantics of the vanilla subject with a few caveats due to their specialization (for instance, completion/reconnection behaviour). Vanilla Rx.Subject semantics Key features subjects implement the

Angular2+ http at an interval

空扰寡人 提交于 2019-11-26 02:18:16
问题 I am quite new to angular and rxjs. I am trying to create an angular2 app that gets some data from staticly served text file(Locally on server), which I would like to retrieve and map to Datamodel using Angular2\'s http provider and rxjs\'s map at a fixed time interval(5000) . To reflect any changes to the served txt file. With rxjs 4.x I know you could use Observable.interval(5000) to do the job, but it does not seem to exist in rxjs 5. My workaround currently refresh the whole application

Hot and Cold observables : are there &#39;hot&#39; and &#39;cold&#39; operators?

对着背影说爱祢 提交于 2019-11-25 23:35:02
问题 I reviewed the following SO question: What are the Hot and Cold observables? To summarize: a cold observable emits its values when it has an observer to consume them, i.e. the sequence of values received by observers is independent of time of subscription. All observers will consume the same sequence of values. a hot observable emits value independently of its subscriptions, i.e. the values received by observers are a function of the time of subscription. Yet, I feel like hot vs. cold is

What is the correct way to share the result of an Angular Http network call in RxJs 5?

て烟熏妆下的殇ゞ 提交于 2019-11-25 21:41:30
问题 By using Http, we call a method that does a network call and returns an http observable: getCustomer() { return this.http.get(\'/someUrl\').map(res => res.json()); } If we take this observable and add multiple subscribers to it: let network$ = getCustomer(); let subscriber1 = network$.subscribe(...); let subscriber2 = network$.subscribe(...); What we want to do, is ensure that this does not cause multiple network requests. This might seem like an unusual scenario, but its actually quite