rxjs

Reduce returns empty array, however scan does not

淺唱寂寞╮ 提交于 2020-01-05 05:51:06
问题 Code: const Rx = require('rxjs') const data = [ { name: 'Zachary', age: 21 }, { name: 'John', age: 20 }, { name: 'Louise', age: 14 }, { name: 'Borg', age: 15 } ] const dataSubj$ = new Rx.Subject() function getDataStream() { return dataSubj$.asObservable().startWith(data); } getDataStream() .mergeMap(Rx.Observable.from) .scan((arr, person) => { arr.push(person) return arr }, []) .subscribe(val => console.log('val: ', val)); Using .reduce(...) instead of .scan(...) returns an empty array and

Observable from an array doesn't work in TypeScript

孤人 提交于 2020-01-05 05:01:12
问题 I'm trying to create an observable from an array, as documentation says in https://github.com/ReactiveX/rxjs/blob/master/doc/observable.md: import {Observable} from 'rxjs/Observable'; let theList = Observable.from(sites); but I get: TypeError: Observable_1.Observable.from is not a function my goal is to use operators like reduce or scan over a Observable sequence, as a standard Observable seems to not support, as below: this.theList = new Observable(observer => { // this works observer.next

RxJs-5-to-6-migrate crashes

你离开我真会死。 提交于 2020-01-05 04:45:09
问题 I'm trying to update my project from Angular 4 to Angular 6. I followed the update steps found on the Angular website and all goes quite smoothly. However, when trying to use the rxjs-5-to-6-migrate script, it crashes. I've tried various variations of paths, but noothing seems to work. I've no idea what's going on... PS D:\workspace\project> rxjs-5-to-6-migrate -p src/tsconfig.app.json Running the automatic migrations. Please, be patient and wait until the execution completes. child_process

RxJs-5-to-6-migrate crashes

こ雲淡風輕ζ 提交于 2020-01-05 04:45:08
问题 I'm trying to update my project from Angular 4 to Angular 6. I followed the update steps found on the Angular website and all goes quite smoothly. However, when trying to use the rxjs-5-to-6-migrate script, it crashes. I've tried various variations of paths, but noothing seems to work. I've no idea what's going on... PS D:\workspace\project> rxjs-5-to-6-migrate -p src/tsconfig.app.json Running the automatic migrations. Please, be patient and wait until the execution completes. child_process

RxJS vs rx-node

旧巷老猫 提交于 2020-01-05 04:21:42
问题 What's the difference between RxJS and rx-node? Why shouldn't I just use RxJS instead of rx-node in my NodeJS project? 回答1: The rx-node repository covers this in its first line: This project provides Reactive Extensions for JavaScript (RxJS) bindings for Node.js and io.js to abstract over the EventEmitter, Streams and more. RxJS is the official repository. rx-node adds support for a few node specific things, the details of which are outlined on their documentation page. If you need those

Produce a stream of values with data-driven delays in RxJS

末鹿安然 提交于 2020-01-05 04:15:06
问题 Given an array of objects which contain a message payload and time parameter like this: var data = [ { message:"Deliver me after 1000ms", time:1000 }, { message:"Deliver me after 2000ms", time:2000 }, { message:"Deliver me after 3000ms", time:3000 } ]; I would like to create an observable sequence which returns the message part of each element of the array and then waits for the corresponding amount of time specified in the object. I'm open to reorganising the data structure of the array if

rxjs throttle fetch until request has finished

若如初见. 提交于 2020-01-05 03:43:25
问题 I have an Observable that makes a request that gives back some information that is different each time. This observable is called by a user clicking a button. I want to prevent the user from clicking this button before the request has returned with information, and once it has returned, allow the user to click for an update once again. This is the request without stopping the user at any point. const fetchRepos = () => fetch( 'https://api.github.com/search/repositories?q=+language:javascript

Angular NgRx - Effect to continue polling a service only called the first time

流过昼夜 提交于 2020-01-04 14:16:23
问题 I have an application where I have just added NgRX where I wish to use effects to switch polling on and off. Sample outline I followed this post which seemed like a good approach. I have a simplified example of this here, with the bulk of the code is in app.effects.ts . Similar to the example, I have the effects startPolling$ , stopPolling$ and continuePolling$ , except I am using the newer createEffect factory methods. Also, I have moved the delay(2000) above the takeWhile() , as I found if

Implement delayed queue with RxJs Observable

人盡茶涼 提交于 2020-01-04 09:55:13
问题 Imagine we have a queue of booleans (we don't need a complex datastructure since we wanna store only the fact of the order). Items can get into the queue at anytime in any pace. The Observable would pop items from this queue and emit them in a delayed manner but the first emit is not needed to be delayed. After the queue gets empty it stay on hold until a new item gets in the queue which it will emmit right away. Please help me implement this behaviour. Given a user can press a button which

typescript error Expected 0 type arguments for get call

≯℡__Kan透↙ 提交于 2020-01-04 09:21:56
问题 I am getting typescript error Expected 0 type arguments, but got 1 for line that returns get call. What is wrong with my get call? public get(params: SummaryParams): Observable<Summary[]> { const uri = `${this.config.URLS.LOAD_SUMMARY}`; const params = new HttpParams() .set('startDate', params.startDate.toString()) .set('endDate', params.endDate.toString()) .set('userId', params.userId); return this.http.get<Summary[]>(uri, { params }); } 回答1: HttpClient has generic methods that can be used