rxjs

Import UMD Javascript Modules into Browser

随声附和 提交于 2020-01-24 12:25:59
问题 Hi I am doing some research on RxJS. I am able to use the library simply by referencing it in my browser as such: <script src="https://unpkg.com/@reactivex/rxjs@5.5.6/dist/global/Rx.js"></script> It imports with the global object namespace variable of 'Rx'. I can make observables and do all the fun stuff. Where everything breaks down is when I change the src to point to the latest UMD file like this <script src="https://unpkg.com/rxjs/bundles/rxjs.umd.js"></script> The import seems to not be

Import UMD Javascript Modules into Browser

≡放荡痞女 提交于 2020-01-24 12:24:43
问题 Hi I am doing some research on RxJS. I am able to use the library simply by referencing it in my browser as such: <script src="https://unpkg.com/@reactivex/rxjs@5.5.6/dist/global/Rx.js"></script> It imports with the global object namespace variable of 'Rx'. I can make observables and do all the fun stuff. Where everything breaks down is when I change the src to point to the latest UMD file like this <script src="https://unpkg.com/rxjs/bundles/rxjs.umd.js"></script> The import seems to not be

Poll API using Angular HTTP Observable

拟墨画扇 提交于 2020-01-23 12:26:05
问题 In my component html, I am using the asyncPipe to subscribe to this http service. The service maps the json response object to an array of class instances. This all works great, but I would like http service to poll every few seconds. I've tried a bunch of things (like interval), but it seems RXJS is a bit of a minefield at the moment. Has anyone implemented this kind of thing using Angular 6? fetch(command, params?) { return this.http.post(`http://localhost:4000/${command}`, params) .pipe(

Angular observables - Do I need unsubscribe if no subscription?

送分小仙女□ 提交于 2020-01-23 11:42:16
问题 I am using latest angular 8 and am new to the concept of observables. Question I have if I am directly calling an observable and not apply it to a subscription variable, do I still need to unsubscribe. Below are the scenarios I would like to know if I need to unsubscribe on? Many thanks in advance Scenario 1 - Calling a httpService from a component: Service - httpService getContactsHttp(){ let headers: any = new HttpHeaders(this.authService.getHeadersClient()); return this.httpClient.get('

Convert infinite async callback sequence to Observable sequence?

大城市里の小女人 提交于 2020-01-23 07:51:21
问题 Let's say I have the following asynchronous callback-based "infinite" sequence, which I cancel after some time: 'use strict'; const timers = require('timers'); let cancelled = false; function asyncOperation(callback) { const delayMsec = Math.floor(Math.random() * 10000) + 1; console.log(`Taking ${delayMsec}msec to process...`); timers.setTimeout(callback, delayMsec, null, delayMsec); } function cancellableSequence(callback) { asyncOperation((error, processTime) => { console.log('Did stuff');

Rxjs Observable run sequentially and return an array

不问归期 提交于 2020-01-23 05:47:08
问题 var arr = [obs1, obs2, obs3]; Observable.forkJoin(...arr).subscribe(function (observableItems) {}) Runs observables in parallel and return an array. How can I run the observables sequentially and return an array. I do not want to get called for each observable, so concat() is not appropriate for me. I want to receive the same final result as forkJoin but run sequentially. Does it exist? or do I have to code my own observable pattern? 回答1: Just use concat and then toArray : var arr = [obs1,

Rx js understanding the lift method

↘锁芯ラ 提交于 2020-01-23 04:46:35
问题 I want to create a new operator and I find in the documentation that one of the ways is to do something like this: class MyObservable extends Observable { lift(operator) { const observable = new MyObservable() observable.source = this; observable.operator = operator; return observable; } // put it here .. or .. customOperator() { /* do things and return an Observable */ } } // ... put it here... MyObservable.prototype.mySimpleOperator = mySimpleOperator; I don't understand what is the lift

Angular 7 Communication through service subscribe method called twice

不问归期 提交于 2020-01-22 02:16:06
问题 I'm using angular, trying to communicate to a component that is not parent-child. So I'm communicating it through service service.ts Istoggle=false; @Output() change: EventEmitter < boolean > = new EventEmitter(); toggle() { this.Istoggle= !this.Istoggle; this.toggle.emit(this.Istoggle); } search.ts submit():void{ this.service.toggle(); } Home.ts ngOnInit() { this.service.change.subscribe(_toggle=> { //some code here } } so when I click on submit in Home component toggle subscribe get hit

RxJS queueing dependent tasks

隐身守侯 提交于 2020-01-21 15:54:16
问题 If I have an array of arrays like this { parent: [ { name: 'stu', children: [ {name: 'bob'}, {name: 'sarah'} ] }, { ... } ] } and I want to cycle through each parent and cycle through their children in series, so that I don't start the next parent until all the children have been processed (some long asynchronous process), how do I do this with RxJS? I have attempted this: var doChildren = function (parent) { console.log('process parent', parent.name); rx.Observable.fromArray(parent.children)

rxjs-1介绍

蓝咒 提交于 2020-01-21 15:50:53
RxJS is a library for composing asynchronous and event-based programs by using observable sequences. It provides one core type, the Observable , satellite types (Observer, Schedulers, Subjects) and operators inspired by Array#extras (map, filter, reduce, every, etc) to allow handling asynchronous events as collections. rxjs是一组异步和事件基础的库通过使用可观察的序列,它提供一个核心类型 Observable, 伴随类型( Observer观察者, Schedulers调度, Subjects主题)和操作符,其灵感来源于 Array#extras (map, filter, reduce, every, etc)。操作符准许操作异步事件的集合 Think of RxJS as Lodash for events. rxjs操作事件类似于Lodash操作js ReactiveX combines the Observer pattern with the