rxjs

Angular rxjs Observable.timer is not a function with import

一曲冷凌霜 提交于 2019-12-10 12:54:14
问题 In my angular application I recieve the following error: ERROR TypeError: rxjs_Observable__WEBPACK_IMPORTED_MODULE_4__.Observable.timer is not a function at SwitchMapSubscriber.project (hybrid.effect.ts:20) at SwitchMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/switchMap.js.SwitchMapSubscriber._next (switchMap.js:34) at SwitchMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:54) at FilterSubscriber.push../node_modules/rxjs/

return subject from inside map

99封情书 提交于 2019-12-10 12:24:42
问题 Asking this as a followup on this (How to return observable from subscribe), as the accepted solution didn't solve my use case Here is my code @Effect() searchQuery$ = this.actions$ .ofType(PlayerSearchActions.SEARCH_NEW_QUERY) .map(toPayload) .withLatestFrom(this.store) .map((latest: any[]) => latest[1]) .do((res)=>{console.log("Starting search with:",res);}) .switchMap((store: MyState) => this.youtubeSearch.resetPageToken() .searchAll(store.search.query, store.search.queryParams) .do((res)=

Wait for RxJS operation - to blocking?

青春壹個敷衍的年華 提交于 2019-12-10 11:56:25
问题 I am using Angular 4.3.5. Our app has "programs" that a user can be "subscribed" to. I have a router guard function that looks like this: canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { const programName = route.params['program_name']; const programId = this.programService.getIdForName(programName); if (this.userService.isLoggedIn() && this.subscriptionService.isSubscribed(programId)) { return true; } else { this.router.navigate(['']); return false; } } To get the

rxjs: - receive values emitted before subscribe

痴心易碎 提交于 2019-12-10 11:37:13
问题 my emit.next(1) is lost, I want my subscriber to get that value. My subscriber can't subscribe until after the emit has already happened. This answer suggests publish and connect RxJs: how to get values emitted before we subscribe? however I wasn't sure how to get it working: console.log('make emit') let emit = new Subject<number>(); console.log('make obs') let obs = emit.asObservable() console.log('emit 1') emit.next(1) console.log('subscribe') obs.subscribe((v)=>console.log(v,'!')) console

Guarantee `n` seconds between emit without waiting initially

亡梦爱人 提交于 2019-12-10 11:17:47
问题 Given an event stream like (each - is 10ms ) --A-B--C-D With debounceTime(20) we get -----------D With throttleTime(20) we get --A----C-- With throttleTime(20, undefined, {leading: true, trailing: true} we get --A----CD How can I instead guarantee that I have that much time between each emit, so for example with 20ms --A-----C--D In general the throttleTime with the trailing: true gets closest, but it can sometimes cause the trailing output to be too close to the leading output. Sample code

Angular2 call a Component from a Service

a 夏天 提交于 2019-12-10 11:16:51
问题 I am trying to call a Method in my Component from a a Service . What is the proper way to do this? I have tried to use rxjs Subject to create an Observable, but I cannot get it to fire. import {Subject} from 'rxjs/Subject'; export class MyService { callComponent = function(value) { let invokeEvent = new Subject(); invokeEvent.next({some:value}) } } and in my Component export class MyComponent { constructor(private _myService: MyService) { this._myService.invokeEvent.subscribe(value => console

RxJS and React's setState - delay function execution until subscription

霸气de小男生 提交于 2019-12-10 11:14:52
问题 RxJS has a nifty function, fromCallback that takes a function whose last parameter is a callback and returns an Observable . And I want to combine that with React's setState function so that I can do something analogous to: const setState = Rx.Observable.fromCallback(this.setState); setState({ myState: 'Hi there!' }).concat(....) so that any operations chained to setState are guaranteed to happen after the state has been set and, most importantly, that setState isn't invoked until there's an

What functionalities that RxJS provide for Angular2?

最后都变了- 提交于 2019-12-10 10:19:31
问题 There is some references of RxJS in the Angular2 project. What is RxJS being used for in Angular2? 回答1: A list of what angular2 uses RxJS for Http (for example its get method returns an Observable ) EventEmitter (like you said, extends from Subject ) AsyncPipe which supports Promise , Observable or EventEmitter . QueryList's changes method returns an EventEmitter . Update NG_ASYNC_VALIDATORS which implements Validator and overrides the method validate to return either a Promise or an

debounceTime & distinctUntilChanged in angular 6

六月ゝ 毕业季﹏ 提交于 2019-12-10 10:16:06
问题 I found some tutorial in rxjs that uses debounce and distinctUntilChanged. How can I implement it in angular 6? The tutorial code is this: var observable = Rx.Observable.fromEvent(input,'input'); observable.map(event=>event.target.value) .debounceTime(2000) .subscribe({ next:function(value){ console.log(value) } } This is my code: In html, I have this: <input class="form-control" [(ngModel)]="userQuestion" type="text" name="userQuestion" id="userQuestions"> in Typescript, I have this: import

Take N values from Observable until its complete based on an event. Lazy loading a multi select list

﹥>﹥吖頭↗ 提交于 2019-12-10 10:09:09
问题 I'm new to rxjs, and I'm developing an angular multiselect list component that should render a long list of values (500+). I'm rendering the list based on an UL, I'm iterating over an observable that will render the LI's. I'm thinking about my options to avoid impacting the performance by rendering all the elements at once. But I don't know whether this is possible or not, and if it's possible what is the best operator to use. The proposed solution: On init I load all the data into an