rxjs

Difference between RxJS and IxJS?

守給你的承諾、 提交于 2020-08-22 04:36:48
问题 What's the difference between RxJS and IxJS, and when would I want to use one over the other? From the IxJS docs: RxJS is great for event-based workflows where the data can be pushed at the rate of the producer, however, IxJS is great at I/O operations where you as the consumer can pull the data when you are ready. After going through the docs, the only major difference seems to be the concept of Iterables in IxJS and Observables in RxJS . Both Iterables and Observables execute either

Angular4 - how to ensure ngOnDestroy finishes before navigating away

旧街凉风 提交于 2020-08-21 19:42:41
问题 I have a list of objects. The user can click on one, which then loads a child component to edit that component. The problem I have is that when the user goes back to the list component, the child component has to do some cleanup in the ngOnDestroy method - which requires making a call to the server to do a final 'patch' of the object. Sometimes this processing can be a bit slow. Of course what happens is the user arrives back on the list, and that api call completes before the database

Angular/RxJS: synchronous observable

断了今生、忘了曾经 提交于 2020-08-21 06:02:06
问题 I have a service that has a method foo. Inside the method I subscribe to an observable (http-client). foo () : boolean { let ret : false; this.http.get ("/blabla").subscribe ( (resp) => { ret = true; } return ret; ); I like to return a boolean value from foo that depends on the get. That is not working because http.get is asynchrouns - return is called before http.get finished. How can I make this synchronous? EDIT Returning the observable instead boolean is not an option here. That is

【译文】【前端架构鉴赏 01】:Angular 架构模式与最佳实践

自作多情 提交于 2020-08-14 01:17:30
本文原文: Angular Architecture Patterns and Best Practices (that help to scale) 译者序 这是作为译者我想说的话,并非原文中的内容。 我猜此时此刻你心里的疑问一定是:为什么是 Angular,不是 React,不是 Vue,不是 Flux,不是 Redux ? 因为你已经对它们太熟悉了。 我个人作为开发者而言最希望是能够汲取到“圈外”的“营养”,这样才能给我的成长带来帮助。 我想对各位也是一样。 你不用担心因为不会 Angular 而看不懂这一些列文章,它们基本上谈论的是应用架构——关于设计、组织、抽象,很少会落到具体的实现,即使有,连蒙带猜也能推测出一二。这也能从侧面说明我衷心想推荐这些佳作的原因:通过大段大段的代码阐述很容易;难的是几乎不用代码来跨越语言的说明更高层次的东西,比如 Martin Fowler, Uncle Bob Martin 他们的文章就能如此。 我不评价框架的流行和好坏,我只是把一切呈现在各位的眼前。它们并非和 Flux,Vuex 大相径庭,反而你们会看到它们的影子,但更多的是不一样的东西。我在里面看到了更好的职责划分和抽象。 在文中我会以引用的格式和“译者注”开头穿插一些我的个人备注和带给我启发性的问题,你可以理解为文章的“评论音轨”,但其中问题我不会给予回答。你也可以忽略这些评论

RxJS shareReplay() does not emit updated value

情到浓时终转凉″ 提交于 2020-08-10 19:19:47
问题 I have a user service which allows login, logout and maintains data about the currently logged in user: user$ = this.http.get<User>('/api/user') .pipe( shareReplay(1), ); I am using shareReplay(1) because I do not want the webservice to be called several times. On one of the components, I have this (for simplicity), but I have several other things I want to do if a user is logged in: <div *ngIf="isUserLoggedIn$ | async">Logout</div> isUserLoggedIn$ = this.userService.user$ .pipe( map(user =>

RxJS: how to emit values of a certain buffer size with a delay between each group

非 Y 不嫁゛ 提交于 2020-08-10 10:51:52
问题 I have large observable of values, where I want to chunk it into fixed sizes, and then emit each chunk with a delay until finished. To be a bit more concrete, my scenario is where I may have a lot of data to send to a server via a http request, where each values needs a separate http request. So if I have 1000 pending bits of data, I don't want to do 1000 http request all at once, I may like to say do 10, and then delay by a short time (maybe a couple of seconds). I assume this must use the

RxJS: how to emit values of a certain buffer size with a delay between each group

◇◆丶佛笑我妖孽 提交于 2020-08-10 10:47:41
问题 I have large observable of values, where I want to chunk it into fixed sizes, and then emit each chunk with a delay until finished. To be a bit more concrete, my scenario is where I may have a lot of data to send to a server via a http request, where each values needs a separate http request. So if I have 1000 pending bits of data, I don't want to do 1000 http request all at once, I may like to say do 10, and then delay by a short time (maybe a couple of seconds). I assume this must use the

ramda 函数 Function

你离开我真会死。 提交于 2020-08-09 22:45:45
太多了... 去除废弃和不常用的也比rxjs多太多了 pipeWith 在管道中对每次流通的数据进行处理, 避免出现空值, 或者处理Promise const R = require('ramda') const pipeWhileNotNil = R.pipeWith((f, res) => { console.log('=========', res, f(res)) return R.isNil(res) ? res : f(res) }); const f2 = pipeWhileNotNil([Math.pow, R.negate, R.inc,R.identity,R.dec]) console.log( f2(3, 4) ); // ========= 81 -81 // ========= -81 -80 // ========= -80 -80 // ========= -80 -81 // -81 const R = require('ramda') // 科里化函数占位符 console.log( R.divide(10, R.__)(2), // 5 R.divide(R.__, 10)(2), // 0.2 ) // 通过向列表迭代函数的回调函数添加两个新的参数:当前索引、整个列表,创建新的列表迭代函数。 // 例如,addIndex 可以将 R.map

Old-style callbacks synchronisation using observables

社会主义新天地 提交于 2020-08-09 13:59:04
问题 I have following scenario - 4 callback functions A,B,C,D which are called form old-style like library (which use some API requests inside so execution time is unknown/random but proper order of results (by finished task time) is important for me) - and I want to synchronise data which they return to one obserwable result string using rxjs. function getData() { // --- BELOW Part can be EDIT --- let obs = new ReplaySubject(1); // this is example you can use an type function A(n) { let r= 'A'

Angular RXJS forkJoin completion progress

ぃ、小莉子 提交于 2020-08-08 06:39:05
问题 I would like to have a progress counter for bulk HTTP requests in my Angular app. I use forkJoin to execute an array of Observables. The pipe only executes once. It does not execute for the X number of requests in the obs variable. Is there a different way to get a complete Observable in a forkJoin? Here is what I have tried: let obs: Observable<any>[] = [...]; let counter: number = 0; // obs has 5 items here. forkJoin(obs) .pipe( tap(() => { counter++; }) ) .subscribe(res => { }) .add(() =>