2.1.0 • Published 6 years ago
take-until-destroy v2.1.0
take-until-destroy
A simple way to unsubscribe from an RxJs stream in Angular (6.0+) when the component is destroyed
For an overview of how this works see this post about unsubscription in angular
Installation
npm install take-until-destroy --save
|| yarn add take-until-destroy
Use
import { Destroyable, takeUntilDestroy } from 'take-until-destroy'
// If you have already implemented `OnDestroy`, you don't need the `@Destroyable` decorator.
@Destroyable
@Component({
...
})
export class ExampleComponent {
constructor(randomService: RandomService) {
randomService.getObservable
.pipe(takeUntilDestroy(this))
.subscribe(v => {
console.log(v)
})
}
}
Known Issues
The @Destroyable
decorator doesn't work in production. See https://github.com/jsdevtom/take-until-destroy/issues/7 for updates. The current fully working work around is to simply implement OnDestroy
for you component and it will work as expected. Example:
import { Destroyable, takeUntilDestroy } from 'take-until-destroy'
@Component({
...
})
export class ExampleComponent implements OnDestroy {
constructor(randomService: RandomService) {
randomService.getObservable
.pipe(takeUntilDestroy(this))
.subscribe(v => {
console.log(v)
})
}
ngOnDestroy() {/**/}
}
2.1.0
6 years ago
2.0.0
6 years ago
1.3.1
6 years ago
1.3.0
6 years ago
1.2.6
6 years ago
1.2.5
6 years ago
1.2.3
6 years ago
1.2.2
6 years ago
1.2.1
6 years ago
1.1.3
6 years ago
1.0.11
6 years ago
1.0.10
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago