什么是 tslint 黑名单,为什么 angular-cli 在 tslint.json 的列表中默认使用 rxjs? [英] What is the tslint blacklist and why does angular-cli default rxjs on the list in tslint.json?

查看:24
本文介绍了什么是 tslint 黑名单,为什么 angular-cli 在 tslint.json 的列表中默认使用 rxjs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,在 angular-cli 项目中,tslint 设置中充满了扭曲的东西.最近,一位新开发人员联系我,说我在 Atom 中配置了他们的 tslint 实例.

By default with an angular-cli project the tslint settings come packed with things that go squiggle. I recently was approached by a new developer that I had configure their tslint instance in Atom.

我被问及以下行:

import { Observable, BehaviorSubject } from 'rxjs';

TSLinter 说 rxjs 被列入黑名单.我去了 tslint.json 文件,果然,它被列出来了.

The TSLinter is saying that rxjs is blacklisted. I went to the tslint.json file and, sure enough, it was listed.

这个黑名单是什么?它是否可以保护应用免受某些攻击?

What is this blacklist and does it protect the app from something?

为什么默认将 rxjs 添加到列表中?

Why is rxjs added to the list by default?

在什么情况下我应该添加其他东西?

Under what conditions should I be adding something else to it?

我想指出我知道如何解决"问题::

I'd like to point out that I know how to 'fix' the problem ::

import { Observable } from 'rxjs/observable';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';

问题仍然在于TSLint上下文中黑名单的含义.

The question still lies in the meaning of the Blacklist in the context of TSLint.

推荐答案

这是因为你应该(至少在浏览器应用程序中)永远不要包含来自 'rxjs' 并且总是使用更具体的例如 'rxjs/Observable''rxjs/BehaviorSubject'.

This is because you should (at least in browser apps) never include from 'rxjs' and always use more specific for example 'rxjs/Observable' or 'rxjs/BehaviorSubject'.

当你包含 'rxjs' 时,你实际上包含了这个文件:https://github.com/ReactiveX/rxjs/blob/master/index.js,其中包括整个捆绑的 RxJS 库(所有运算符、调度程序等).所以你包含了很多你甚至不使用的东西,你的应用程序变得比必要的更大(我认为使用 webpack2 摇树并没有帮助,一旦包含代码,它就会成为最终包的一部分,但我可能错了).

When you include 'rxjs' you're in fact including this file: https://github.com/ReactiveX/rxjs/blob/master/index.js which includes the entire bundled RxJS library (all operators, schedulers, etc.). So you're including a lot of things you don't even use and your app grows bigger than necessary (I think tree-shaking with webpack2 doesn't help and once the code is included it'll be part of the final package, but I might be wrong).

我认为在 node 应用程序(例如后端应用程序)中直接从 'rxjs' 导入是可以的,其中包含代码并不重要你不会使用,这种方式更容易使用.

I think it's ok to import directly from 'rxjs' in node apps (eg. backend apps) where it doesn't matter that much that it contains also code you're not going to use and this way is just easier to use.

这篇关于什么是 tslint 黑名单,为什么 angular-cli 在 tslint.json 的列表中默认使用 rxjs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆