Skip to content

docs(no-subject-unsubscribe): document add ban #112

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

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/rules/no-subject-unsubscribe.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,38 @@
This rule effects failures if the `unsubscribe` method is called on subjects.
The method behaves differently to the `unsubscribe` method on subscriptions and is often an error.

This rule also effects failures if a subject is passed to a subscription's `add` method.
Adding a subject to a subscription will cause the subject's `unsubscribe` method to get called
when the subscription is unsubscribed.

## Rule details

Examples of **incorrect** code for this rule:

```ts
import { Subject } from "rxjs";

const subject = new Subject<number>();
subject.unsubscribe();
```

```ts
import { Subject, Subscription } from "rxjs";

const subject = new Subject<number>();
const subscription = new Subscription();
subscription.add(subject);
```

Examples of **correct** code for this rule:

```ts
import { Subject } from "rxjs";

const subject = new Subject<number>();
subject.complete();
```

## When Not To Use It

If you intentionally use `unsubscribe` to cause errors when subjects are `next`-ed after closing,
Expand All @@ -19,6 +51,7 @@ Type checked lint rules are more powerful than traditional lint rules, but also
## Further reading

- [Closed Subjects](https://ncjamieson.com/closed-subjects/)
- [Composing Subscription](https://ncjamieson.com/composing-subscriptions/)

## Related To

Expand Down
Loading