rxjs5

Why does Rxjs unsubscribe on error?

一世执手 提交于 2019-11-30 13:01:29
In short: How to proceed listening after an error in stream without putting a .catch before every .subscribe ? If you need more details they are here: Lets assume I have a Subject of current user or null. I get the data from API sometimes and send to the Subject. It updates the view accordingly. But at some point error occurs on my server and I want my application to continue working as before but notify some places about the error and KEEP listening to my Subject. Initially I thought that if I just do userSubject.error(...) it will only trigger .catch callback and error handlers on subscribes

Angular and RxJS imports

此生再无相见时 提交于 2019-11-30 12:14:15
I've always known to import my Observable operators separately to limit the load times. However I've noticed something today that I hope someone could please explain to me. I am using IntelliJ/WebStorm with Webpack. Let's say on a page in my ngOnInit I have an http call: ngOnInit() { this.http.get('https//:google.com').map(e => e); } If I don't import the map operator the compiler will complain, so I import it like this: import 'rxjs/add/operator/map'; All is good in the world. Until I need to use an Observable. So, I'll add one. ngOnInit() { let test = Observable.create(subscriber => { return

How to debug rxjs5?

≡放荡痞女 提交于 2019-11-30 11:30:16
On RxJS - Goals I read that their goal is better debuggability: Goals Provide more debuggable call stacks than preceding versions of RxJS I have just started to use redux-observable which is quite easier for me to understand comparing it to redux-saga as I am already used to the reactive style with lodash and ramda (ok, fp style maybe ;). I was surprised that it's not possible to debug it yet. Is it true? If so, then I gotta switch to redux-saga s maybe or stick with redux-thunk . Edit based on Jay Phelps's answer By debugging I meant: "How to set a breakpoint on e.g. observable.map(...) in a

How to implement a draggable div in Angular 2 using Rx

Deadly 提交于 2019-11-30 11:05:18
问题 I've been trying to get a draggable div working using Angular 2. I'm using this example from the angular2-examples repo as a starting point, only really adjusting the code to account for the removal of the toRx() method. The code works, but it does not account for mouseout events. This means that if I click on a Draggable div, and move the mouse slowly , the div will move with the mouse. But if I move the mouse too fast, a mouseout event is sent instead of a mousemove event, and the dragging

Why does Rxjs unsubscribe on error?

和自甴很熟 提交于 2019-11-30 07:28:55
问题 In short: How to proceed listening after an error in stream without putting a .catch before every .subscribe ? If you need more details they are here: Lets assume I have a Subject of current user or null. I get the data from API sometimes and send to the Subject. It updates the view accordingly. But at some point error occurs on my server and I want my application to continue working as before but notify some places about the error and KEEP listening to my Subject. Initially I thought that if

The right way to test rxjs

二次信任 提交于 2019-11-30 05:03:01
问题 I brought the book rxjs in action and just finish the testing section. Testing rxjs codes are different then usual testing, because everything are lazy loading. In the book, they mention two test method, either passing done(I am using QUnit and done signals async code is finish) or marble diagrams. My question is, which method should I choose, that I have mentioned above? 回答1: I have been getting this question a lot from my colleagues. I finally got around to document my ways of testing RxJs

RxJs: lossy form of zip operator

别来无恙 提交于 2019-11-30 04:38:51
问题 Consider using the zip operator to zip together two infinite Observables, one of which emits items twice as frequently as the other. The current implementation is loss-less, i.e. if I keep these Observables emitting for an hour and then I switch between their emitting rates, the first Observable will eventually catch up with the other. This will cause memory explosion at some point as the buffer grows larger and larger. The same will happen if first observable will emit items for several

Cannot create observable from Observable.bindNodeCallback(fs.readFile) in TypeScript

雨燕双飞 提交于 2019-11-30 03:53:05
问题 I am trying to use rxjs 5 to write a Node.js server in TypeScript, but I hit an error when converting fs.readFile to its rxjs form. I expect the following code would work in TypeScript // This is a JavaScript example from the official documentation. It should // also work at the TypeScript envrionment. import * as fs from 'fs'; import { Observable } from 'rxjs'; let readFileAsObservable = Observable.bindNodeCallback(fs.readFile); // This is the line that throws the error. let result =

How to manage state without using Subject or imperative manipulation in a simple RxJS example?

穿精又带淫゛_ 提交于 2019-11-30 03:40:27
I have been experimenting with RxJS for two weeks now, and although I love it in principle I just cannot seem to find and implement the correct pattern for managing state. All articles and questions appear to agree: Subject should be avoided where possible in favor of just pushing state through via transformations; .getValue() should be deprecated entirely; and .do should perhaps be avoided except for DOM manipulation? The problem with all such suggestions is that none of the literature appears to directly say what you should be using instead, besides "you'll learn the Rx way and stop using

RxJS - .subscribe() vs .publish().connect()

北战南征 提交于 2019-11-30 03:17:36
This is mainly an RxJs best practice/approach question, since my POC code works but I'm brand new to RxJs. The question boils down to .subscribe() vs .publish().connect() , since they both appear to do the same thing. In my angular2 app, I have a button that calls a function to log the user out, which calls a function in my service that performs some server side actions and returns me a URL to redirect the user to. In order to initiate the request I call .subscribe() to cause the observable to start producing values. I was reading an article on "Cold vs Hot Observables" and it another approach