-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New rule: disallow full import of RxJS operators #498
New rule: disallow full import of RxJS operators #498
Conversation
The reason behind this PR is better described in my article: https://medium.com/p/prevent-coding-mistakes-write-a-tslint-rule-specific-for-your-own-project-987d26f91647 Shortly: it can decrease a size of a bundle when RxJS operators are imported in a wrong way
I was under the impression this was ok: |
@intellix Let me try this once more in the evening but when I checked on the codebase of https://github.com/erento with The advantage is that it has a fixer as well, so it can automatically fix the imports. |
ng new rxjs-test && cd rxjs-test
npm i source-map-explorer
ng build -prod -sm -oh=false
./node_modules/.bin/source-map-explorer dist/main.bundle.js app.component.ts: import { Component } from '@angular/core';
import { timer } from 'rxjs/observable/timer';
import { tap } from 'rxjs/operators';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
timer = timer(100, 100).pipe(tap(console.log));
} |
I don't think this belongs to codelyzer. Check out |
@intellix I don't know what you mean with before and after... but from curiosity I run the same example you posted and these are my results: So I have a bit different number then you in the first line — it shows it is better to import directly from @lazarljubenovic I still think it would be valuable for other angular users but I'm not pushing for it hard, so when you agree I should close it I will :) |
But Angular users can install the other module which already exists for the similar (same?) purpose. It's not like you're scoped on one linter plugin. |
ok so it seems more stuff is pulled in. I was thinking it was more a case of importing all vs a single operator. All operators would probably be something like 150kb+ |
I'm not sure this rule is durable. There are two things:
import { map, filter, mergeMap, tap } from 'rxjs/operators'; see : ReactiveX/rxjs#3018 (comment)
see: angular/angular-cli#9069 (comment) So, using the deep import is a workaround. I'm not sure that a provisional rule has its place in codelyzer. |
They will remove the deep imports in rxjs 6, so don't think this rule should become a thing. See here: https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#600-alpha1-2018-01-12
|
Thank you @wKoza and @lucasvanhalst for great arguments, I will close this PR as it really doesn't make sense when RxJS@6 will not have this problem anymore... |
The reason behind this PR is better described in my article:
https://medium.com/p/prevent-coding-mistakes-write-a-tslint-rule-specific-for-your-own-project-987d26f91647
Shortly: it can decrease a size of a bundle when RxJS operators are imported in a wrong way
I know it is not exactly Angular related, but Angular requires RxJS as a dependency. Therefore I think it could be part of the Styleguide.