Skip to content

Commit

Permalink
V2.0.x (#11)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
codemile authored Sep 16, 2020
1 parent b9088be commit aabcc24
Show file tree
Hide file tree
Showing 22 changed files with 8,598 additions and 6,802 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ node_js:

branches:
only:
- master
- develop
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/

cache:
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 2.0.0

This release focuses on Angular compatibility and security patches for npm packages.

## Changes
* This release targets Angular 10 and above.
* Adds a mixin function for using destroyable with other base classes.

## Breaking Changes
* `destroyed` read-only property has been removed. Use the protected `_destroyed$` property instead.
* `destroyed$` read-only property has been removed. Use the protected `_destroyed$` property instead.

# 1.0.1

* This release targets Angular 8 and above.

# 1.0.0

* First release.
70 changes: 62 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
[![Build Status](https://travis-ci.org/reactgular/destroyable.svg?branch=master)](https://travis-ci.org/reactgular/destroyable)
[![Coverage Status](https://coveralls.io/repos/github/reactgular/destroyable/badge.svg?branch=master)](https://coveralls.io/github/reactgular/destroyable?branch=master)
[![Build Status](https://travis-ci.org/reactgular/destroyable.svg?branch=develop)](https://travis-ci.org/reactgular/destroyable)
[![Coverage Status](https://coveralls.io/repos/github/reactgular/destroyable/badge.svg?branch=develop)](https://coveralls.io/github/reactgular/destroyable?branch=develop)
[![npm version](https://badge.fury.io/js/%40reactgular%2Fdestroyable.svg)](https://badge.fury.io/js/%40reactgular%2Fdestroyable)

## What is Destroyable?

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

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

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.

- [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)
- [The easiest way to unsubscribe from Observables in Angular](https://medium.com/thecodecampus-knowledge/the-easiest-way-to-unsubscribe-from-observables-in-angular-5abde80a5ae3)

## Changelog

For details on recent changes, releases and Angular version support, please see the change log.

[Learn about the latest improvements](https://github.com/reactgular/destroyable/blob/develop/CHANGELOG.md).

## Installation

To get started, install the package from npm.

```bash
npm install --save @reactgular/destroyable
npm install @reactgular/destroyable
```

> To install Angular 8 or 9 versions `npm install @reactgular/destroyable@1.0.1`
### Usage

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

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

Expand All @@ -39,7 +50,50 @@ import {Destroyable} from '@reactgular/destroyable';
export class ExampleComponent extends Destroyable implements OnInit {
public ngOnInit(): void {
interval(1000).pipe(
takeUntil(this.destroyed$)
takeUntil(this._destroyed$)
).subscribe(value => console.log(value));
}
}
```

When implementing `OnDestroy` it's very important to call `super.ngOnDestroy()` for the base class, but it's not necessary to implement
the interface because `Destroyable` already implements it.

```
export class ExampleComponent extends Destroyable implements OnDestroy {
public constructor() {
super();
}
public ngOnDestroy() {
super.ngOnDestroy();
}
}
```

## Mixin

Destroyable supports mixins to use a different base class with your Angular components. The only limitation is that TypeScript doesn't
currently support `abstract` classes for use with mixins.

```
import {Component, OnInit} from '@angular/core';
import {interval} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {mixinDestroyable} from '@reactgular/destroyable';
@Directive()
class BaseDirective {
}
@Component({
selector: 'example'
template: ''
})
export class ExampleComponent extends mixinDestroyable(BaseDirective) implements OnInit {
public ngOnInit(): void {
interval(1000).pipe(
takeUntil(this._destroyed$)
).subscribe(value => console.log(value));
}
}
Expand Down
7 changes: 6 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
"options": {
"tsConfig": "projects/reactgular/destroyable/tsconfig.lib.json",
"project": "projects/reactgular/destroyable/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "projects/reactgular/destroyable/tsconfig.lib.prod.json"
}
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/reactgular/destroyable/src/test.ts",
"main": "projects/reactgular/destroyable/test/test.ts",
"tsConfig": "projects/reactgular/destroyable/tsconfig.spec.json",
"karmaConfig": "projects/reactgular/destroyable/karma.conf.js"
}
Expand Down
Loading

0 comments on commit aabcc24

Please sign in to comment.