Skip to content

Commit

Permalink
docs: Improve no-unsafe-takeuntil docs.
Browse files Browse the repository at this point in the history
Closes #55.
  • Loading branch information
cartant committed Mar 13, 2021
1 parent 41ad6d2 commit e3e8fed
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions docs/rules/no-unsafe-takeuntil.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
# Avoid `takeUntil` subscription leaks (`no-unsafe-takeuntil`)
# Avoid `takeUntil` subscription leaks (`no-unsafe-takeuntil`)

This rule effects failures whenever `takeUntil` is using in observable compositions that can leak subscriptions.
This rule effects failures whenever `takeUntil` is used in observable compositions that can leak subscriptions.

Although it's recommended that `takeUntil` be placed last - to ensure unsubscription from any inner observables - there are a number of operators that might _need_ to be placed after it - like `toArray` or any other operator that depends upon a `complete` notification. The rule is aware of these operators (see the rule's options, below) and will not effect failures if they are placed after `takeUntil`.

## Rule details

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

```ts
const combined = source
.pipe(
takeUntil(notifier),
combineLatest(b)
)
.subscribe((value) => console.log(value));
.pipe(takeUntil(notifier), combineLatest(b))
.subscribe((value) => console.log(value));
```

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

```ts
const combined = source
.pipe(
combineLatest(b),
takeUntil(notifier)
)
.subscribe((value) => console.log(value));
.pipe(combineLatest(b), takeUntil(notifier))
.subscribe((value) => console.log(value));
```

## Options
Expand All @@ -34,17 +30,17 @@ By default, the `allow` property contains all of the built-in operators that are

```json
{
"rxjs/no-unsafe-takeuntil": [
"error",
{
"alias": ["untilDestroyed"]
}
]
"rxjs/no-unsafe-takeuntil": [
"error",
{
"alias": ["untilDestroyed"]
}
]
}
```

The properties in the options object are themselves optional; they do not all have to be specified.

## Further reading

- [Avoiding takeUntil leaks](https://ncjamieson.com/avoiding-takeuntil-leaks/)
- [Avoiding takeUntil leaks](https://ncjamieson.com/avoiding-takeuntil-leaks/)

0 comments on commit e3e8fed

Please sign in to comment.