Skip to content

Commit 4140b21

Browse files
docs(no-exposed-subjects): when not to use it
1 parent 792e568 commit 4140b21

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

docs/rules/no-exposed-subjects.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ Examples of **correct** code for this rule:
2323

2424
```ts
2525
import { Subject } from "rxjs";
26+
2627
class Answers {
27-
private _answers: Subject<string>;
28-
get answers() {
29-
return this._answers.asObservable();
28+
private answersSubject = new Subject<string>();
29+
public answers$ = this.answersSubject.asObservable();
30+
31+
public nextAnswer(a: string) {
32+
this.answersSubject.next(a);
3033
}
3134
}
3235
```
@@ -51,3 +54,15 @@ This rule accepts a single option which is an object with an `allowProtected` pr
5154
]
5255
}
5356
```
57+
58+
## When Not To Use It
59+
60+
If you don't care about encapsulating subjects in your project, then you don't need this rule.
61+
However, be aware that anyone can call `next()` or `complete()` on the exposed subject, which may cause bugs or less readable code.
62+
63+
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.
64+
65+
## Resources
66+
67+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/no-exposed-subjects.ts)
68+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/no-exposed-subjects.test.ts)

0 commit comments

Comments
 (0)