rxjs

Rxjs debounce on react text input component using Subjects does not batch input text on stateless/functional component

混江龙づ霸主 提交于 2020-01-21 10:27:21
问题 I'm trying to dive deeper into rxjs and found an issue where the input field I'm trying to debounce dispatches an event on every keypress, the debounce only holds the output but results in a tree like: a as(delay - waits 200ms, then fires the rest synchronously) asd asdf asdfg .... The same code works as expected in a class component(https://stackoverflow.com/a/44300853/1356046) but cannot understand why it doesn't work with stateless components. Here's an example: https://stackblitz.com/edit

Angular RxJS Observable: takeUntil vs. unsubscribe with a Subscription [closed]

心不动则不痛 提交于 2020-01-21 06:07:47
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 months ago . There are several ways to unsubscribe from observables on Angular components (by using ngOnDestroy). Which option below should be preferred and why (e.g. technical reasons, performance, etc.)? Option 1: takeUntil Using RxJS takeUntil to unsubscribe @Component({ selector:

Cannot find module 'rxjs-compat/Observable'

霸气de小男生 提交于 2020-01-20 01:05:06
问题 I am currently upgrading angular 4 to angular 6 code. I have installed "rxjs": "^6.3.2" and un-installed rxjs-compact as I have migrated the code to use the new rxjs operators. I am still getting the following errors. Dont know the reason why ERROR in [at-loader] ./node_modules/rxjs/BehaviorSubject.d.ts:1:15 TS2307: Cannot find module 'rxjs-compat/BehaviorSubject'. ERROR in [at-loader] ./node_modules/rxjs/Observable.d.ts:1:15 TS2307: Cannot find module 'rxjs-compat/Observable'. ERROR in [at

Angular—RxJS之Observable

二次信任 提交于 2020-01-19 17:29:46
目录 一、概述 二、详解 一、概述 Observable翻译为可观察对象,是RxJS中的一个对象,可以用来处理异步事件,例如http请求。实际上,在Angular中,所有的http请求返回的都是Observable。Observable和promise本质上是相同的,都是生产者主动向消费者push产品,而消费者被动接收。但两者也有很大区别,Observable可以发送任意多值,并且在被订阅钱,它是不会执行的,这是promise不具备的特点。 Observable用于在发送方和接收方之间传输消息,可以将这些消息看作流。 在创建Observable对象时,需要传入一个函数作为构造函数的参数,这个函数叫订阅者函数,是生产者向消费者推送消息的地方。在被消费者subscribe(订阅)之前,订阅者函数不会执行,直到subscribe()函数被调用,该函数返回一个subscription对象,里面有一个unsubscribe()函数,消费者可以随时拒绝消息的接收。 subscribe()函数接收一个observer(观察者)对象作为入参。 消息的发送可以是同步的,也可以是异步的。 我们可以使用一系列的RxJS操作符,在这些消息被接收方接收之前,对它进行一些列的处理、转换,因为这些操作符都是纯函数,没有副作用,可以放心使用,并不会产生期望之外的效果。 二、详解 observer观察者

RxJS/Angular: How to zip observable arrays of objects

僤鯓⒐⒋嵵緔 提交于 2020-01-17 07:33:40
问题 I am working with ionic 2 and angular 2. Right now I have two observables that contain object arrays and are being passed to my template to be displayed: users: Observable<User[]>; scores: Observable<Score[]>; In my template I currently have to display them separately: <ion-card *ngFor="let score of scores | async" > <ion-item text-wrap>{{ score.total }} </ion-item> </ion-card> <ion-card *ngFor="let user of users | async" (click)="goToPlayer(user, league)"> <ion-item text-wrap>{{ user.id }}<

How do I use the RXJS selector function in the Observable.bindCallback method?

自作多情 提交于 2020-01-17 06:00:33
问题 I believe that to get two params properly mapped back to the callback when using Observable.bindCallback method you have to use the "selector" function, but I cannot find documentation that explains how to do this. I may have a misunderstanding of what the selector function does, but it still should be documented. http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#static-method-bindCallback function testLogin(username, password, callback){ // ... callback(param1, param2); }

Is it safe to subscribe to an observable with an async function

泄露秘密 提交于 2020-01-17 01:49:24
问题 I have an event emitter that sends events at 50Hz. I'd like to subscribe to this emitter with an async method. The code looks like the following: this.emitter = fromEventPattern(this.addHandler, this.removeHandler, (err, char) => [err, char]); this.rxSubscription = this.emitter.subscribe(this.handleUpdatedValuesComingFromSensor); and handleUpdatedValuesComingFromSensor = async (arr: any[]): Promise<void> => { ... await someMethodAsync(); ... } I maybe wrong but I'm under the impression that

NgRx Get value without subscribing

泪湿孤枕 提交于 2020-01-15 10:37:28
问题 I am working my way through some ngrx tutorials and I think I'm starting to get my brain wrapped around it. What I don't understand is how to do something as simple as getting a value from the Store : Goal : Get a value from the store without having to subscribe to it. IE: store.myStoreProperty or store.getValue(<selector>) or ? From what I understand the only way to grab a value from the store is to do something like this: private readonly _store: Store<ApplicationState>; // ... this._store

How to periodically check live connection using rxjs?

江枫思渺然 提交于 2020-01-15 09:52:21
问题 I use rxjs to handle a websocket connection var socket = Rx.Observable.webSocket('wss://echo.websocket.org') socket.resultSelector = (e) => e.data I want to periodically (5s) sent a ping message and wait 3s to receive a pong response and subscribe to the a stream if no response has been receive. I try that without success. I admit I'm a bit lost will all the operator available to handle timeout, deboune or throttle. // periodically send a ping message const ping$ = Rx.Observable.interval(2000

How to periodically check live connection using rxjs?

冷暖自知 提交于 2020-01-15 09:52:10
问题 I use rxjs to handle a websocket connection var socket = Rx.Observable.webSocket('wss://echo.websocket.org') socket.resultSelector = (e) => e.data I want to periodically (5s) sent a ping message and wait 3s to receive a pong response and subscribe to the a stream if no response has been receive. I try that without success. I admit I'm a bit lost will all the operator available to handle timeout, deboune or throttle. // periodically send a ping message const ping$ = Rx.Observable.interval(2000