rxjs

'Error' message: 'Property 'from' does not exist on type 'typeof Observable'

柔情痞子 提交于 2019-12-21 08:50:12
问题 I am trying to learn reactive programming using RxJS. I was trying to create an observable from an array using Observable.from() method, but I am getting an error: Property 'from' does not exist on type 'typeof Observable' I scaffolded an Angular application using Angular CLI, so all the dependencies including RxJS package was imported correctly. In app.component.ts I added below import statements: import { Observable} from 'rxjs/Observable' import 'rxjs/observable/from' And my AppComponent

is there an equivalent of async pipe that you can use inside a component?

孤人 提交于 2019-12-21 08:07:08
问题 Does there exist something equivalent to the async pipe that I could use inside a component like this @Component({ selector: 'my-component', }) export class myComponent { myObservable$: Observable<string>; method() { doSomething(this.myObservable$); // here I would like to access directly the current string value of // myObservable$ without having to subscribe } } 回答1: You have to ask yourself: What do you want to achieve by avoiding the subscribe() call? My guess is that you want to prevent

Angular 6 Update - rxjs-5-to-6-migrate command not found

Deadly 提交于 2019-12-21 07:26:18
问题 In the upgrade process from update.angular.io: Remove deprecated RxJS 6 features using rxjs-tslint auto update rules. For most applications this will mean running the following two commands: npm install -g rxjs-tslint rxjs-5-to-6-migrate -p src/tsconfig.app.json But when I follow these steps and run rxjs-5-to-6-migrate -p src/tsconfig.app.json I'm getting the error: rxjs-5-to-6-migrate: command not found Is there any reason why this command isn't working? 回答1: I did get it working and my

How to await inside RxJS subscribe method

拈花ヽ惹草 提交于 2019-12-21 07:22:28
问题 Inside of an RxJS subject's subscribe callback, I want to await on an async function. Below is a code example which the typescript transpiler complains about saying: Error:(131, 21) TS2304:Cannot find name 'await'. async ngOnInit() { this.subscriber = dateSubscription.subscribe((date: Date) => { let dbKey = await this._someService.saveToDatabase(someObject); // wait for db write to finish before evaluating the next code // ... some other code here }); } Usually I see this when trying to call

How to await inside RxJS subscribe method

守給你的承諾、 提交于 2019-12-21 07:22:19
问题 Inside of an RxJS subject's subscribe callback, I want to await on an async function. Below is a code example which the typescript transpiler complains about saying: Error:(131, 21) TS2304:Cannot find name 'await'. async ngOnInit() { this.subscriber = dateSubscription.subscribe((date: Date) => { let dbKey = await this._someService.saveToDatabase(someObject); // wait for db write to finish before evaluating the next code // ... some other code here }); } Usually I see this when trying to call

How to await inside RxJS subscribe method

╄→гoц情女王★ 提交于 2019-12-21 07:22:06
问题 Inside of an RxJS subject's subscribe callback, I want to await on an async function. Below is a code example which the typescript transpiler complains about saying: Error:(131, 21) TS2304:Cannot find name 'await'. async ngOnInit() { this.subscriber = dateSubscription.subscribe((date: Date) => { let dbKey = await this._someService.saveToDatabase(someObject); // wait for db write to finish before evaluating the next code // ... some other code here }); } Usually I see this when trying to call

Pipe RxJS observable to existing subject

荒凉一梦 提交于 2019-12-21 07:09:39
问题 There is existing subject that is in use: const fooSubject = new BehaviorSubject(null); And there is another observable (another subject in this example): const barSubject = new Subject(); barSubject.subscribe( value => fooSubject.next(), err => fooSubject.error(err), () => fooSubject.complete() ); barSubject.next('bar'); The code works but looks clumsy. Is there a better way to pipe (in broad sense, not necessarily using pipe operator) barSubject observable to fooSubject ? It looks like an

How to catch error in Observable.forkJoin(…)?

夙愿已清 提交于 2019-12-21 07:04:40
问题 I use Observable.forkJoin() to handle the response after both http calls finishes, but if either one of them returns an error, how can I catch that error? Observable.forkJoin( this.http.post<any[]>(URL, jsonBody1, postJson) .map((res) => res), this.http.post<any[]>(URL, jsonBody2, postJson) .map((res) => res) ) .subscribe(res => this.handleResponse(res)) 回答1: You may catch the error in each of your observables that are being passed to forkJoin : // Imports that support chaining of operators

Composing and sequencing multiple epics in redux-observable

我与影子孤独终老i 提交于 2019-12-21 05:57:01
问题 I have a problem that I don't know how to resolve. I have two epics that do requests to api and update the store: const mapSuccess = actionType => response => ({ type: actionType + SUCCESS, payload: response.response, }); const mapFailure = actionType => error => Observable.of({ type: actionType + FAILURE, error, }); const characterEpic = (action$, store) => action$.ofType(GET_CHARACTER) .mergeMap(({ id }) => { return ajax(api.fetchCharacter(id)) .map(mapSuccess(GET_CHARACTER)) .catch

redux-observable epic that doesn't send any new actions

白昼怎懂夜的黑 提交于 2019-12-21 05:48:11
问题 Might be that I'm a noob and not fully understanding how this stuff should work yet, but I have an epic in redux-observable in which I want to use as a way to create a promise which will dispatch an action and wait for a different action before resolving. I've got it working by mapping the action to '__IGNORE__' but I really don't want to do that. Is there any way to just have an epic handle an action, but not pass anything else on? Here's my code: export const waitFor = (type, action) => new