rxjs

rxjs6 使用 fromEventPattern 封装 readline 逐行读取文件

笑着哭i 提交于 2020-02-27 04:10:23
使用场景 有一个很大的文件500M左右, 需要将里面的数据读出来, 进行处理, python有直接可以读行的函数, js的回调方式写起来很不舒服, 在这里使用rxjs封装一下 封装一个函数, 传入文件地址, 然后返回一个流, 流中的数据就是每行数据的结果 注意要在流结束的时候关闭流和取消事件监听 const fs = require('fs') const readline = require('readline') const {fromEventPattern} = require('rxjs') const {take, finalize} = require('rxjs/operators') function getLines(filePath) { const stream = fs.createReadStream(filePath) const rl = readline.createInterface({ input: stream }); return fromEventPattern( handler => { rl.on('line', (...args) => { console.log('read line') handler(...args) }); }, handler => { rl.on('close', (...args) => {

自学前端不用慌张!零基础学习前端必备手册 ,学成月薪12K

蹲街弑〆低调 提交于 2020-02-26 16:44:11
随着互联网的深入发展,前端开发工程师一跃成为市场上非常抢手的人才。很多同学,包括以前做UI的、Java的、或者对于IT完全零基础的同学都想学习前端。下图是网上流传甚广的一张前端学习思维导图,很多初学者表示看到这些密密麻麻的知识点就已经晕了。确实,前端是一门涵盖面很广的学科。但是想学前端的你也不用慌张,内容虽多但有迹可循,只要循序渐进就不怕学不好前端! 那么对于零基础的一个学员该怎么学习前端呢? 工具篇 工欲善其事,必先利其器,所以在开始之前选择一个合适好用的编辑器是很重要的,工具不再多,在于好用就行,除了编辑器,我们也要掌握其他的一些工具,才能够让我们在学习的道路上更加的顺畅。 WebStorm 不必多说,前端最强大的编辑器,特别是那无敌的智能提示,但是它的缺点在于如果项目多于大时,出现的卡顿让很多人苦恼。 Google 在使用「Google」之前必须学会***,不然无法访问,学会使用搜索可以帮助我们解决很多问题,一个人的知识是有限的,掌握了搜索的技巧才能以不变应万变,很多时候百度出来的东西重复性很大,最重要的是垃圾信息很多,在百度找不到的答案,在这里很容易找到,Google 是我的必备搜索。 Github 全球最大的「同性」开源交流社区,没有账号的赶紧注册,在这有很多优秀的资源项目,各种大神。观摩优秀代码是我们学习的很好路径。另外在开发过程中,很多时候任务重、时间紧

How to test timeout() in a rxjs pipe with jasmine-marbles

て烟熏妆下的殇ゞ 提交于 2020-02-25 13:36:38
问题 I have written a pipe that filters an input observable. In the pipe I specify a timeout with the timeout() operator to abort waiting if the expected value is not emitted by the source in time. I want to test the timeout case with jasmine-marbles, but I can't get it to work. I believe that expect(source).toBeObservable() evaluates before the source emits. see Stackblitz The pipe to be tested: source = cold('a', { a: { id: 'a' } }).pipe( timeout(500), filter((a) => false), catchError((err) => {

How to test timeout() in a rxjs pipe with jasmine-marbles

﹥>﹥吖頭↗ 提交于 2020-02-25 13:36:30
问题 I have written a pipe that filters an input observable. In the pipe I specify a timeout with the timeout() operator to abort waiting if the expected value is not emitted by the source in time. I want to test the timeout case with jasmine-marbles, but I can't get it to work. I believe that expect(source).toBeObservable() evaluates before the source emits. see Stackblitz The pipe to be tested: source = cold('a', { a: { id: 'a' } }).pipe( timeout(500), filter((a) => false), catchError((err) => {

How to test timeout() in a rxjs pipe with jasmine-marbles

女生的网名这么多〃 提交于 2020-02-25 13:36:07
问题 I have written a pipe that filters an input observable. In the pipe I specify a timeout with the timeout() operator to abort waiting if the expected value is not emitted by the source in time. I want to test the timeout case with jasmine-marbles, but I can't get it to work. I believe that expect(source).toBeObservable() evaluates before the source emits. see Stackblitz The pipe to be tested: source = cold('a', { a: { id: 'a' } }).pipe( timeout(500), filter((a) => false), catchError((err) => {

Angular 6 & RxJS 6 Breaking Changes

无人久伴 提交于 2020-02-24 05:32:49
问题 I've google the crap out of this and I can't find a solution. I've been using code like this for some time now. http is the angular HttpClient. forgotPassword(email: string): Observable<ApiReturn> { const url = `${this.apiURL}/ForgotPassword`; const params = { email }; return this.http .post<ApiReturn>(url, params, this.requestOptions) .pipe(catchError(e => this.handleError(e))); } I updated to the latest Angular 6.x version and RxJS 6 (from 5.5). Now the code is complaining about the

Angular 6 & RxJS 6 Breaking Changes

為{幸葍}努か 提交于 2020-02-24 05:32:19
问题 I've google the crap out of this and I can't find a solution. I've been using code like this for some time now. http is the angular HttpClient. forgotPassword(email: string): Observable<ApiReturn> { const url = `${this.apiURL}/ForgotPassword`; const params = { email }; return this.http .post<ApiReturn>(url, params, this.requestOptions) .pipe(catchError(e => this.handleError(e))); } I updated to the latest Angular 6.x version and RxJS 6 (from 5.5). Now the code is complaining about the

React - Communication and routing between components published as npm packages

ぃ、小莉子 提交于 2020-02-22 05:44:46
问题 I am trying to setup micro-frontend architecture for the project. The project contains multiple react apps. Following is the project structure: container header (npm package) dashboard (npm package) app1 (npm package) app2 (npm package) app3 (npm package) Here, container works as wrapper for the other apps. Dashboard apps shows links to the other apps such as app1, app2, app3 etc... Once user logs in header and dashboard app renders on a page. From dashboard user can navigate to other apps.

Do you have to unsubscribe from a QueryList in a component?

。_饼干妹妹 提交于 2020-02-21 11:06:21
问题 When using the @ContentChildren or @ViewChildren decorators to listen for changes to DOM elements. Do I have to unsubscribe from the QueryList ? For example: @Component({...}) export class ParentComponent implements AfterContentInit { @ContentChildren(ChildComponent) public children: QueryList<ChildComponent>; public ngAfterContentInit(): void { this.children.changes.subscribe(() => ....); } } Would the above be a problem? Updated: The reason I'm asking is that we don't have to unsubscribe to

Do you have to unsubscribe from a QueryList in a component?

只愿长相守 提交于 2020-02-21 11:06:15
问题 When using the @ContentChildren or @ViewChildren decorators to listen for changes to DOM elements. Do I have to unsubscribe from the QueryList ? For example: @Component({...}) export class ParentComponent implements AfterContentInit { @ContentChildren(ChildComponent) public children: QueryList<ChildComponent>; public ngAfterContentInit(): void { this.children.changes.subscribe(() => ....); } } Would the above be a problem? Updated: The reason I'm asking is that we don't have to unsubscribe to