Skip to content

Commit aabcc24

Browse files
authored
V2.0.x (#11)
* updated * updated README * adds a beta target for publishing * updates to Angular 8.2.14 * upgrades to Angular 9.1.12 * upgrades to Angular 10.1.0 * audit fix * updated * updated * updated * updated * improves test quality * adds support for a mixin * updated * updated tests * updated tests * updated tests * updated * updated build * updated * updated
1 parent b9088be commit aabcc24

22 files changed

+8598
-6802
lines changed
File renamed without changes.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ node_js:
77

88
branches:
99
only:
10-
- master
10+
- develop
1111
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/
1212

1313
cache:

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 2.0.0
2+
3+
This release focuses on Angular compatibility and security patches for npm packages.
4+
5+
## Changes
6+
* This release targets Angular 10 and above.
7+
* Adds a mixin function for using destroyable with other base classes.
8+
9+
## Breaking Changes
10+
* `destroyed` read-only property has been removed. Use the protected `_destroyed$` property instead.
11+
* `destroyed$` read-only property has been removed. Use the protected `_destroyed$` property instead.
12+
13+
# 1.0.1
14+
15+
* This release targets Angular 8 and above.
16+
17+
# 1.0.0
18+
19+
* First release.

README.md

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
1-
[![Build Status](https://travis-ci.org/reactgular/destroyable.svg?branch=master)](https://travis-ci.org/reactgular/destroyable)
2-
[![Coverage Status](https://coveralls.io/repos/github/reactgular/destroyable/badge.svg?branch=master)](https://coveralls.io/github/reactgular/destroyable?branch=master)
1+
[![Build Status](https://travis-ci.org/reactgular/destroyable.svg?branch=develop)](https://travis-ci.org/reactgular/destroyable)
2+
[![Coverage Status](https://coveralls.io/repos/github/reactgular/destroyable/badge.svg?branch=develop)](https://coveralls.io/github/reactgular/destroyable?branch=develop)
33
[![npm version](https://badge.fury.io/js/%40reactgular%2Fdestroyable.svg)](https://badge.fury.io/js/%40reactgular%2Fdestroyable)
44

55
## What is Destroyable?
66

7-
Destroyable is an abstract class that implements the `OnDestroy` life-cycle hook in Angular, and when the hook is triggered an observable
8-
property named `destroyed$` will emit once and then complete.
7+
Destroyable is an abstract class which implements the `OnDestroy` life-cycle hook in Angular, and when the hook gets triggered a protected observable
8+
named `_destroyed$` will emit once and then complete.
99

10-
The usage of `takeUntil(destroyed$)` is a popular best practice for Angular projects. You can find a lot of tutorials online discussing the practice.
10+
You can then use `takeUntil(this._destroyed$)` when subscribing to observables from inside your component, and the subscription will automatically
11+
end when the component has been destroyed.
12+
13+
The usage of `takeUntil(this._destroyed$)` is a popular best practice for Angular projects. You can find a lot of tutorials online discussing the practice.
1114

1215
- [The Best Way To Unsubscribe RxJS Observables In The Angular Applications](https://blog.angularindepth.com/the-best-way-to-unsubscribe-rxjs-observable-in-the-angular-applications-d8f9aa42f6a0)
1316
- [The easiest way to unsubscribe from Observables in Angular](https://medium.com/thecodecampus-knowledge/the-easiest-way-to-unsubscribe-from-observables-in-angular-5abde80a5ae3)
1417

18+
## Changelog
19+
20+
For details on recent changes, releases and Angular version support, please see the change log.
21+
22+
[Learn about the latest improvements](https://github.com/reactgular/destroyable/blob/develop/CHANGELOG.md).
23+
1524
## Installation
1625

1726
To get started, install the package from npm.
1827

1928
```bash
20-
npm install --save @reactgular/destroyable
29+
npm install @reactgular/destroyable
2130
```
2231

32+
> To install Angular 8 or 9 versions `npm install @reactgular/[email protected]`
33+
2334
### Usage
2435

25-
Allows you to easily add `takeUntil(this.destroyed$)` to components, modules and services in an Angular application.
36+
Allows you to easily add `takeUntil(this._destroyed$)` to components, modules and services in an Angular application.
2637

2738
The following example component prints ascending numbers to the console for as long as the component lives.
2839

@@ -39,7 +50,50 @@ import {Destroyable} from '@reactgular/destroyable';
3950
export class ExampleComponent extends Destroyable implements OnInit {
4051
public ngOnInit(): void {
4152
interval(1000).pipe(
42-
takeUntil(this.destroyed$)
53+
takeUntil(this._destroyed$)
54+
).subscribe(value => console.log(value));
55+
}
56+
}
57+
```
58+
59+
When implementing `OnDestroy` it's very important to call `super.ngOnDestroy()` for the base class, but it's not necessary to implement
60+
the interface because `Destroyable` already implements it.
61+
62+
```
63+
export class ExampleComponent extends Destroyable implements OnDestroy {
64+
public constructor() {
65+
super();
66+
}
67+
68+
public ngOnDestroy() {
69+
super.ngOnDestroy();
70+
}
71+
}
72+
```
73+
74+
## Mixin
75+
76+
Destroyable supports mixins to use a different base class with your Angular components. The only limitation is that TypeScript doesn't
77+
currently support `abstract` classes for use with mixins.
78+
79+
```
80+
import {Component, OnInit} from '@angular/core';
81+
import {interval} from 'rxjs';
82+
import {takeUntil} from 'rxjs/operators';
83+
import {mixinDestroyable} from '@reactgular/destroyable';
84+
85+
@Directive()
86+
class BaseDirective {
87+
}
88+
89+
@Component({
90+
selector: 'example'
91+
template: ''
92+
})
93+
export class ExampleComponent extends mixinDestroyable(BaseDirective) implements OnInit {
94+
public ngOnInit(): void {
95+
interval(1000).pipe(
96+
takeUntil(this._destroyed$)
4397
).subscribe(value => console.log(value));
4498
}
4599
}

angular.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
"options": {
1515
"tsConfig": "projects/reactgular/destroyable/tsconfig.lib.json",
1616
"project": "projects/reactgular/destroyable/ng-package.json"
17+
},
18+
"configurations": {
19+
"production": {
20+
"tsConfig": "projects/reactgular/destroyable/tsconfig.lib.prod.json"
21+
}
1722
}
1823
},
1924
"test": {
2025
"builder": "@angular-devkit/build-angular:karma",
2126
"options": {
22-
"main": "projects/reactgular/destroyable/src/test.ts",
27+
"main": "projects/reactgular/destroyable/test/test.ts",
2328
"tsConfig": "projects/reactgular/destroyable/tsconfig.spec.json",
2429
"karmaConfig": "projects/reactgular/destroyable/karma.conf.js"
2530
}

0 commit comments

Comments
 (0)