rxjs

Independent chain cancellation in redux-observable?

删除回忆录丶 提交于 2019-12-10 10:06:32
问题 I'm new to RxJS. In my app I need independent cancellation of deferred action. Here's a working example (the delay is 3 seconds). But when I choose to delete multiple items and cancel one of them, then canceled all at once. Epic code: const itemsEpic = action$ => action$.ofType('WILL_DELETE') .flatMap(action => Observable.of({type: 'DELETE', id: action.id}) .delay(3000) .takeUntil(action$.ofType('UNDO_DELETE')) ) I think I need to pass an id to takeUntil operator, but I don't know how to do

Using RxJS 6.x WebSocketSubject client

北战南征 提交于 2019-12-10 09:47:37
问题 I cannot figure out how to use WebSocketSubjects in rxjs v6.x Here's the working HTML/JS for v5.5.6 . The commented out code is my attempt at getting it working in v6.x : <html> <head> <!-- <script src="https://unpkg.com/@reactivex/rxjs@6.0.0/dist/global/rxjs.umd.js"></script> --> <script src="https://unpkg.com/@reactivex/rxjs@5.5.6/dist/global/Rx.js"></script> <script> // const { WebSocketSubject } = rxjs.webSocket; // const socket$ = WebSocketSubject.create('ws://localhost:8080'); const

Get one object from observable array

拈花ヽ惹草 提交于 2019-12-10 09:10:30
问题 How do you write a function that takes an Observable<T[]> and returns Observable<T> ? For example, I have two methods: getTransactions(): Observable<Transaction[]>{ ... } getTransaction(id: number): Observable<Transaction>{ return this.getTransactions().pipe(find(txn => txn.id === id)); } I get the error that type 'Observable' is not assignable to type 'Observable'. Type 'Transaction[] is not assignable to type 'Transaction'. Property 'id' is missing in type 'Transaction[]'. As I understand,

Start first call of IntervalObservable instant

与世无争的帅哥 提交于 2019-12-10 05:33:55
问题 I'm using an IntervalObservable to make continuous calls to the server side of my application. I can subscribe and unsubscribe to to the Oberservable and everything works fine with one exception: The first call to the server is delayed, but I want it to be instant. The behaviour of the IntervalObservable is in principle correct, but does not match my requirements. @Injectable() export class LoggerService { constructor(private http: Http) { } private apiURL = 'assets/file.json'; getList() {

Angular2 Rxjs 404 error

倖福魔咒の 提交于 2019-12-10 05:10:11
问题 I have the following error when trying to start my Angular2 application: Failed to load resource: the server responded with a status of 404 (Not Found) angular2-polyfills.js:332 Error: Error: XHR error (404 Not Found) loading http://localhost:55707/rxjs(…) Here is my index.html: <!DOCTYPE html> <html> <head> <base href="/"> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Streak Maker</title> <link rel="icon" type="image/png" href="

Rxjs: take(1) usage

巧了我就是萌 提交于 2019-12-10 03:59:55
问题 I have seen a tutorial on rxjs as like this. My question is: 1) What is the usage of take(1) here? I see a lot of explanation online but i don't really get it. Also, i don't see any benefit of using take(1) in this code. And the author do use take(1) on every return function in REST api related service. 2) The author did not unsubscribe after subscribe. Is it because the author use take(1) therefore manual unsubscribe is not needed? 3) What if i want to implement catch function. Should i

RxJS forkJoin does not complete

一曲冷凌霜 提交于 2019-12-09 20:53:12
问题 When I subscribe to getAllSubModules forkJoin executes all those observables without error but does not complete. I know forkJoin completes only after all its observables completed but as a proof I see '-----' 3 times in console which confirm everything is successful so all its observables completed. getSubmodules(id): Observable<any> { return this.authService.getToken() .flatMap((token) => this.http.get(`${this.URL}/ROS/applications/modules/${id}/subModules?token=${token}`)) .map((res: any)

Firestore : Retrieve a single document

廉价感情. 提交于 2019-12-09 18:58:59
问题 I want to retrieve a single document from Firestore. So I do not mean the list of documents in the collection (I know how to do that). Let's say I know one of the key-value pair of the document and I would like to find and retrieve the document into Angular 4. interface Occupations { duration: number; id_entity: number; id_job: number; id_user: number; salary: number; start_time: number; } occupationDoc:AngularFirestoreDocument<Occupations>; occupation: Observable<Occupations>; <h1>A specific

How to delay one epic until another has emitted a value

余生颓废 提交于 2019-12-09 18:48:01
问题 In redux-observable I need to wait before doing an API request until another epic has completed. Using combineLatest doesn't work, nothing happens after APP_INITIALIZED finishes. I also tried withLatestFrom but neither works. const apiGetRequestEpic = (action$, store) => { return Observable.combineLatest( action$.ofType('APP_INITIALIZED'), action$.ofType('API_GET_REQUEST') .mergeMap((action) => { let url = store.getState().apiDomain + action.payload; return ajax(get(url)) .map(xhr => { return

How to use RxJS to display a “user is typing” indicator?

痞子三分冷 提交于 2019-12-09 18:20:36
问题 I know a little bit of BaconJS, but now I'm trying to learn RxJS by creating a "User is typing..." indicator. It's pretty simple, it can be explained in two simple rules: When the user is typing, the indicator should be immediately visible. When the user stops typing, the indicator should still be visible until 1 second after the user's last typing action. I'm not sure if this is correct, but I have so far created two streams: One heartbeat stream that emits a 0 every second. One stream to