rxjs5

BehaviorSubject initial value not working with share()

﹥>﹥吖頭↗ 提交于 2019-12-10 13:22:51
问题 share() operator is applied to a BehaviorSubject. BehaviorSubject has initial value. Goal is to create a single shared subscribtion. But this shared subscribtion does not seem to work when BehaviorSubject has an initial value. Getting unexpected results. Code shown below: let subject = new Rx.BehaviorSubject(0); let published = subject .do(v => console.log("side effect")) .share(); published.subscribe((v) => console.log(v+" sub1")); published.subscribe((v) => console.log(v+" sub2")); subject

How to dispatch an empty action?

坚强是说给别人听的谎言 提交于 2019-12-10 12:50:37
问题 I am using ngrx/effects. How can I dispatch an empty action? This is how I am doing now: @Effect() foo$ = this.actions$ .ofType(Actions.FOO) .withLatestFrom(this.store, (action, state) => ({ action, state })) .map(({ action, state }) => { if (state.foo.isCool) { return { type: Actions.BAR }; } else { return { type: 'NOT_EXIST' }; } }); Since I have to return an action, I am using return { type: 'NOT_EXIST' }; . Is there a better way to do this? 回答1: I've used similar unknown actions, but

Convert a plain string[] into a Observable<string[]> and concat it to another Observable<string[]> using RxJS 5

好久不见. 提交于 2019-12-10 06:24:54
问题 I am trying to convert a plain string[] into a Observable<string[]> and concat it to an existing Observable<string[]> . I will then use an angular2 async pipe in order to display the Observable . Here is my code: import {Injectable} from "angular2/core"; import {Observable} from "rxjs/Observable"; import 'rxjs/Rx'; @Injectable() export class AppService { constructor() { console.log('constructor', 'appService'); this.constructSomeObservable(); } someObservable$:Observable <string[]>;

Start first call of IntervalObservable instant

与世无争的帅哥 提交于 2019-12-10 05:33:55
问题 I'm using an IntervalObservable to make continuous calls to the server side of my application. I can subscribe and unsubscribe to to the Oberservable and everything works fine with one exception: The first call to the server is delayed, but I want it to be instant. The behaviour of the IntervalObservable is in principle correct, but does not match my requirements. @Injectable() export class LoggerService { constructor(private http: Http) { } private apiURL = 'assets/file.json'; getList() {

What's the difference between publish and multicast operator in rxjs 5?

谁说胖子不能爱 提交于 2019-12-10 02:43:36
问题 I'm reading the rxjs manual, I'm a little confused about what's the difference between multicast and publish operators. They seem very similar. 回答1: I had the same question when reading http://reactivex.io/rxjs/manual/overview.html. So to make it clear, .publish() is just shorthand for .multicast(new Rx.Subject()) (and publishBehavior , publishLast , and publishReplay are similar but instantiate BehaviorSubject , AsyncSubject and ReplaySubject respectively). 回答2: They are indeed very similar,

RXJS 5 .subscribe() without arguments

纵然是瞬间 提交于 2019-12-10 01:59:22
问题 So a quick question. I've been using RxJS 5 for a few months now, and I've run into a bit of behavior that I don't really understand, as I haven't been able to look it up anywhere. I'm in a situation where subscribing to an observable chain with simply .subscribe(); doesn't trigger the observable. However, if I add an onNext callback (empty or not), the observable triggers, and the chain processes: .subscribe(() => {}); Can anyone explain why this behavior happens? EDIT2 - Removed irrelevant

RxJS forkJoin does not complete

一曲冷凌霜 提交于 2019-12-09 20:53:12
问题 When I subscribe to getAllSubModules forkJoin executes all those observables without error but does not complete. I know forkJoin completes only after all its observables completed but as a proof I see '-----' 3 times in console which confirm everything is successful so all its observables completed. getSubmodules(id): Observable<any> { return this.authService.getToken() .flatMap((token) => this.http.get(`${this.URL}/ROS/applications/modules/${id}/subModules?token=${token}`)) .map((res: any)

How to use RxJS to display a “user is typing” indicator?

痞子三分冷 提交于 2019-12-09 18:20:36
问题 I know a little bit of BaconJS, but now I'm trying to learn RxJS by creating a "User is typing..." indicator. It's pretty simple, it can be explained in two simple rules: When the user is typing, the indicator should be immediately visible. When the user stops typing, the indicator should still be visible until 1 second after the user's last typing action. I'm not sure if this is correct, but I have so far created two streams: One heartbeat stream that emits a 0 every second. One stream to

Observable .catch is not a function

牧云@^-^@ 提交于 2019-12-09 09:31:41
问题 I get this very annoying error when running my code from a unix environment. This works fine when I run the code locally through ng serve , But when I deploy the code to my server, this error halts all program execution: ERROR TypeError: this.http.get(...).catch is not a function Google results state that I should import rxjs namespaces straight from their location, and not through the rxjs/Rx bundle, but I get this error regardless. Other results point out that I may have missed importing

Cannot find module 'rxjs/subject/BehaviorSubject'

醉酒当歌 提交于 2019-12-09 05:01:35
问题 I am using Angular 2. When I use either of these two, my program runs well: import { BehaviorSubject } from 'rxjs/Rx'; import { BehaviorSubject } from 'rxjs'; However, I try to use the following way: import { BehaviorSubject } from 'rxjs/subject/BehaviorSubject'; But I failed, my browser console shows: Uncaught Error: Cannot find module 'rxjs/subject/BehaviorSubject' How can I use third way correctly? Thanks 回答1: import {BehaviorSubject} from 'rxjs/BehaviorSubject'; rxjs 6.x import