rxjs5

Compare most recent values from multiple BehaviorSubjects

﹥>﹥吖頭↗ 提交于 2019-12-11 17:55:43
问题 Say I have this: isMatchedCountLessThanTotalCountMessage(){ // I want to implement this // "returns" a string asynchronously } getMatchedEventsCount() { return this.dcs.matchCount.asObservable(); } getTotalEventsCount() { return this.dcs.totalCount.asObservable(); } matchedCount and totalCount are like so: public matchCount = new BehaviorSubject<number>(0); public totalCount = new BehaviorSubject<number>(0); these Observables fire integers as values change. Anytime a value is fired from

ReduxObservable cancellation based on action type and its data

我的梦境 提交于 2019-12-11 16:54:47
问题 I have React app which uses redux-observable with typescript. In this scenario, FetchAttribute Action gets triggered with a id and then make an ajax call. In certain case, I would want to cancel the ajax request if "FETCH_ATTRIBUTE_CANCEL" action was triggered with the same id as of "FetchAttributeAction" action. action$.ofType(FETCH_ATTRIBUTE) .switchMap((request: FetchAttributeAction) => { return ajax.getJSON(`/api/fetch-attribute?id=${request.id}`) .flatMap((fetchUrl) => { // return new

Rxjs: Missing property error with lettable operators

丶灬走出姿态 提交于 2019-12-11 15:40:04
问题 I'm trying to use Lettable Operators in my import statement after upgrading to Angular 5.0.0 and I get this error. ERROR in src/app/components/hero-detail/hero-detail.component.ts(32,8): error TS2339: Property 'switchMap' does not exist on type 'Observable<ParamMap>'. I changing from import "rxjs/add/operator/switchMap" to import { switchMap } from "rxjs/operators" If fails on this code block: ngOnInit(): void { this.route.paramMap .switchMap((params: ParamMap) => this.heroService.getHero(

Observable of array, find index of value

泄露秘密 提交于 2019-12-11 14:48:59
问题 I'm writing an Angular app that gets a selection of stores from a service, as an Observable. When the user clicks a marker on the map, I want to get the index of the store in the array that lives inside the Observable. stores: Observable<Store[]>; ngOnInit() { this.stores = http.get<Store[]>('URL'); } onMarkerClick(event) { const geopoint = event.geopoint; //How can I get the index where store.geopoint === event.geopoint? } 回答1: For filtering the stores from the array you do: this

How to guarantee the continuity of observable stream in case of http errors?

北战南征 提交于 2019-12-11 09:50:19
问题 I have a problem with the below method ( onTrySignin ) when I encounter an HTTP error response. The catch block right after my HTTP call prevents the Side Effect from throwing an Action error. if I do console.log I get this error. TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. how can I preserve the Observable stream and pass the response to the next block ( mergeMap ) where I can fire other Actions , ( FailedSignin

Observable concat method on array returns the same array

為{幸葍}努か 提交于 2019-12-11 08:49:26
问题 In my service I try to solve the next problem. I have a json file with the names of other json files (cards): { "filename1" : ... , "filename2" : ... , ... "filenameN" : ... } I need to load all that files. "filenameX" files have some card data : { dataX } I need to combine loaded data in object: { "filename1" : { data1 }, "filename2" : { data2 }, ... "filenameN" : { dataN } } I create Observer for any file loading and try to combine them to a high-level single Observer which is resolved when

angular 5, RxJs { map } import doesn't work or i'm missing something?

纵然是瞬间 提交于 2019-12-11 07:41:12
问题 I'm trying to map the result of my httpclient and we need to use the new import for RxJs to get the treeshaking working. so i've found 2 map but none work... import { map } from 'rxjs/operator/map'; import { map } from 'rxjs/operators/map'; the old fashion way that we need to remove import 'rxjs/add/operator/map'; Here is the code i need to get to work! getValues(): Observable<Value[]> { return this.http.get<Response<Values>>(this.url).map(reponse => { return reponse.data.values; }); } but

How to split a data frame from an arrayBuffer with RxJS?

☆樱花仙子☆ 提交于 2019-12-11 06:58:12
问题 I'm using websocket to receive data frame from hardware. The data frame is defined like this: 0xbb(head) ---data--- 0xee(tail) the received data is store in Uint8Array, there maybe multiple frame: var buffer = new Uint8Array([0xbb,0,0,0,0xee,0xbb,1,1,1,0xee,0xbb,3,3,3,0xee]); and I can convert the array to observable: var obs= Rx.Observable.from(buffer); RxMarbles: --0xbb--0--0--0--0xee--0xbb--1--1--1--0xee--0xbb--2--2--2--0xee------ ------------------000------------------111-----------------

How to refactor a subscribe inside a subscribe in rxjs

左心房为你撑大大i 提交于 2019-12-11 06:20:00
问题 For example: this.saveSubscription$ = this.ds.onSave$.subscribe(x => this.sb.updateMachineTool(this.viewEditModel.viewEditModel).subscribe(x = { console.log('alert results', x) }) ) this.ds.onSave$ is a subject that triggers when a save button on a different component is clicked. this.sb.updateMachineTool is an httpClient post that updates a specific tool should I be using some type of map so i'm not subscribing to both areas? How can I refactor this code? 回答1: To Refactor your code You can

Rx.js, handling Chrome Extension webrequest API callback functions

99封情书 提交于 2019-12-11 06:01:25
问题 I'm trying to use Rx.js to handle the flow of Chrome extension webrequest API. Each webrequest addListener() call takes a mandatory callback function as the first parameter. This sends request objects to the function. However, the callback can return a webRequest.BlockingResponse that determines the further life cycle of the request. I'm struggling to handle the blocking response as part of the observable. This code works well for examining all image requests, for example