rxjs

How to create an Rx (RxJS) stream that can be switched between single-item and batch-mode?

試著忘記壹切 提交于 2019-12-06 14:15:31
问题 I have an Rx stream that is an outgoing change feed from a particular component. Occasionally I want to be able to enter a batch mode on the stream so that items passed to onNext accumulate and are passed on only when the batch mode is exited. Normally I'll pass single items through the stream: stream.onNext(1); stream.onNext(2); There is a 1-to-1 mapping between the items passed to onNext and the items received in the subscribe , so the previous snippet results in two calls to subscribe with

How onComplete actually works in RxJS

核能气质少年 提交于 2019-12-06 14:02:27
Observables complete naturally if they are constructed from finite data. import {Observable, Subject} from "rx"; let stream0$ = Observable.of("1", "2", "3"); let stream1$ = stream0$.map(x => x); stream1$.subscribe( (val) => { console.log("onNext", val) }, (err) => { console.log("onError", err) }, () => { console.log("onCompleted") } ); // onNext 1 // onNext 2 // onNext 3 // onCompleted Or don't if not. But what about observables subscribed on subjects? For example: import {Observable, Subject} from "rx"; let subj$ = new Subject(); let stream1$ = subj$.map(x => x); stream1$.subscribe( (val) =>

Concatenation of Angular http requests

巧了我就是萌 提交于 2019-12-06 13:52:38
I am facing the following scenario. There is a Front End app, built with Angular(2), which is connected with a REST Back End accessible via http. Once an user logs in (using email and pwd), the Back End returns data related to the user and in particular an id associated with the user (let's call this userId ) and the code of the region where he lives (let's call this regionId ). Via the userId I can query the Back End to get the affinity group ID to which the user belongs (let's call this affinityId ). Finally, using affinityId and regionId I can retrieve from the Back End the discount to

What does observer.complete() do?

假装没事ソ 提交于 2019-12-06 13:25:53
In rxjs what exactly does the observer.complete() do after observer.next() ? From the documentation observer.complete notifies the Observer that the Observable has finished sending push-based notifications. In the other hand, observer.complete it's a callback function and an Observable calls this method after it has called next() for the final time, if it has not encountered any errors . In ReactiveX library, there are two types of messages. First ones are ordinary messages. Ordinary messages are the ones sent with .next() and there can be 0-many of them. Second type are notifications. These

Angular Material Table own datasource with filter method

你离开我真会死。 提交于 2019-12-06 13:23:31
With the help of this tutorial I wrote my own datasource for the angular material table. I get the list of data from an api and display it in a material table. Code MyDataSource export class MyDataSource extends DataSource<any> { private users: Observable<User[]>; constructor(private userService: UserService) { super(); } connect(): Observable<User[]> { this.users = this.userService.getAll(); return this.users; } disconnect() { } filterWithCriteria(filterData: any): any { return this.users .filter(element => element[filterData.criteria].toLocaleLowerCase().includes(filterData.searchTerm

Creating a simple scheduler

流过昼夜 提交于 2019-12-06 12:44:18
How would I go about creating a simple Scheduler that say, delays every item by a second? I want to use it for an Observable, and yes, I know that can be done in multiple other ways, I jsut want to accomplish it using a custom Scheduler. There's some related tutorial here: http://codebetter.com/matthewpodwysocki/2010/05/12/introduction-to-the-reactive-extensions-for-javascript-custom-schedulers/ but it is quite outdated and the API looks very different now. The current docs are not very usefuleither, but I guess I should be using Rx.Scheduler.prototype.schedulePeriodic , although I don't know

ReferenceError: Rx is not defined

我与影子孤独终老i 提交于 2019-12-06 11:58:22
问题 I am just started learning angular2 and I am trying to do sample of RxJs using angular2. It would be highly appreciated, If some one help me. RxJs Code- var obs = Rx.Observable.interval(500) .take(5) .do(i => console.log(i) ); package.json { "name": "angular-quickstart", "version": "1.0.0", "scripts": { "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ", "lite": "lite-server", "postinstall": "typings install", "tsc": "tsc", "tsc:w": "tsc -w", "typings": "typings" }, "license": "ISC",

How to create components from a JSON array in cycle js

拟墨画扇 提交于 2019-12-06 11:33:29
Given the labeled slider component example from the Cycle js web site. How would I take a JSON array of slider information objects and create a labeled slider component for each Object in the array. for example if I had an array like this let labelSliderArray = [ { label: 'Height', unit: 'in', min: 40, max: 84, init: 50 }, { label: 'Weight', unit: 'ibs', min: 40, max: 84, init: 50 }, { label: 'Age', unit: 'years', min: 10, max: 65, init: 20 } ] How would I map each label object to a label component. I have tried to map each label object to IsolatedLabeledSlider, like so const {div, input,

Using rx.js, how do I emit a memoized result from an existing observable sequence on a timer?

拥有回忆 提交于 2019-12-06 11:33:08
I'm currently teaching myself reactive programming with rxjs, and I've set myself a challenge of creating an observable stream which will always emit the same result to a subscriber no matter what. I've memoized the creation of an HTTP "GET" stream given a specific URL, and I'm trying to act on that stream every two seconds, with the outcome being that for each tick of the timer, I'll extract a cached/memoized HTTP result from the original stream. import superagent from 'superagent'; import _ from 'lodash'; // Cached GET function, returning a stream that emits the HTTP response object var

How to handle circularly dependent observables in RxJS?

≯℡__Kan透↙ 提交于 2019-12-06 11:30:54
问题 Let's say e.g. that somewhere on a server there is a mapping between integers and names and a web page provides a simple input where a user can enter a number and is given the corresponding name. In its basic form, this problem is simple: const input$ = Rx.Observable.fromEvent(..., "input"); const request$ = input$.map( ... ); const serverResponse$ = request$.flatMap( askServer ); Now I would like to cache the results so that a request is only done when the number is not in the cache. const