rxjs

RXJS: Single Observable from dynamically created Observables

南笙酒味 提交于 2019-12-12 04:27:52
问题 I am trying to create an observable (fixedObservable here) which will be fed by multiple dynamically created observable over time. Whenever a subscription is made than the subscriber should get the most recent value from the fixedObservable. Although I have achieved it but I wanted to know if there is any simple solution to it. You can find the code here https://jsfiddle.net/dzm2t3pa/8/ . Thanks var resultdiv = document.getElementById('result'); function print(message) { var paraEl = document

Why arrow function is not passing arguments?

穿精又带淫゛_ 提交于 2019-12-12 04:23:07
问题 I'm using angular w/ rxjs to observe user events on the interface. However, I'm having this really simple problem with passing arguments to a method in an arrow function. Here is the problem: This is not working : searchterm is not being passed to this.searchFacilities ngOnInit() { this.searchTerm$.subscribe(searchterm => this.searchFacilities);/**Not working here**/ } searchFacilities(term: string){ console.log(term); this.facilityservice.searchFacilities(term) .subscribe(results => this

Rxjs execute the handler only once

对着背影说爱祢 提交于 2019-12-12 03:38:37
问题 I have two observable that I am listening too with the merge operator when one of them is fire, or both I need to execute the handler only once, How can I do this with rx? var source1 = Rx.Observable.interval(1000); var source2 = Rx.Observable.interval(1000); var source = Rx.Observable.merge( source1, source2) .subscribe(() => console.log('This needs to run only once and not kill the stream')) 回答1: You can use selector function of multicast Optional selector function that can use the

How do I get an observable to update a variable in IE?

醉酒当歌 提交于 2019-12-12 03:37:46
问题 For some reason I can get this code to work in Chrome but did not find a solution for Safari and IE. I haven't tried Firefox yet. My project is using the typescript transpiler. constructor(){ this.eventStream = Observable.fromEvent(window,'resize'); this.eventStream.subscribe((event) => this.updateWindow(event)); } ngOnInit(){ this.updateWindow(); } updateWindow(event:any){ this.updateHeight = window.innerHeight; } Plunker example 回答1: Your code works in Firefox, but not in Safari and IE, it

rxjs subscription calls a function that returns a promise, need Promise.each style scheduling

﹥>﹥吖頭↗ 提交于 2019-12-12 03:36:34
问题 I'm trying to read JSON from a file, filter out stuff I don't want and possibly map and flatten the JSON elements, and then for each filtered JSON line in the file call a function that returns a promise. (Basically tail -f from a bunyan produced file). Additional Requirement: I want the pacing to be based on how fast the functions resolve the promise (output pacing, one element at a time, like Promise.each) Sounds like a great use for RXJS and promises, right? Well, except that all the

RxJs - parse file, group lines by topics, but I miss the end

我怕爱的太早我们不能终老 提交于 2019-12-12 03:25:03
问题 I am trying RxJS. My use case is to parse a log file and group lines by topic ( i.e.: the beginning of the group is the filename and then after that I have some lines with user, date/time and so on) I can analyse the lines using regExp. I can determine the beginning of the group. I use ".scan" to group the lines together, when I've the beginning of new group of line, I create an observer on the lines I've accumulated ... fine. The issue is the end of the file. I've started a new group, I am

Rxjs testing - is it possible to use marble diagrams also in RxJs 4?

空扰寡人 提交于 2019-12-12 02:59:35
问题 I have a simple question. RxJS v5 uses marble diagrams for its testing (example here). Is it possible to use the same technique in RxJS v4 and if so, how to ? 回答1: You can always roll your own: here's a simple function to convert a string to a cold observable that emits string values: // string -> Observable<string> function fromMarble(s) { const items = s.split('-') .filter(x => x); return Rx.Observable.from(items); } fromMarble('--1--2--cheese--4--5').subscribe(x => console.log(x)); // >> 1

Reconnecting a WebSocket with a shared RxJS observable

我们两清 提交于 2019-12-12 02:50:58
问题 I have an observable like this: const records$ = Rx.DOM.fromWebSocket('ws://192.168.2.4:9001/feed/', null) .map(ev => parseRecord(ev.data)) .share(); I have many subscribers. When the connection is lost, all subscribers unsubscribe: let records$Subscription; records$Subscription = records$.subscribe( record => { ... }, error => records$Subscription.dispose() ); I verified that the call to dispose is indeed being made once for every subscription. Therefore, the share refcount has reached zero.

this.myService.myEvent.toRx().subscribe() called but no DOM refresh (Zone trigger)

混江龙づ霸主 提交于 2019-12-12 02:49:46
问题 I'm playing with angular2 alpha 40 with ng2-play starter from pawel. Examples are in typescript. I have a service MovieList like this: export class Movie { selected: boolean = false constructor(public name:string, public year:number, public score:number) {} } export class MovieListService { list: Array<Movie> selectMovie = new EventEmitter(); constructor() { this.list = [new Movie('Star Wars', 1977, 4.4)]; } add(m:Movie) { this.list.push(m); } remove(m:Movie) { for(var i = this.list.length -

Is it possible to update Observable with own data in Angular2 / Typescript?

岁酱吖の 提交于 2019-12-12 02:46:46
问题 I have an ngFor with async like that: <div *ngFor="let location of googleSearchLocations | async"> <div *ngFor="let location of facebookSearchLocations | async"> and this is my component: private searchTerms = new Subject<string>(); googleSearchLocations: Observable<GoogleLocation[]>; facebookSearchLocations: Observable<FacebookLocation[]>; ngOnInit(): void { this.googleSearchLocations = this.searchTerms .debounceTime(300) .switchMap(term => term ? this.locationService.getGoogleLocations(term