angular2-take-until-destroy
Advanced tools
Comparing version 1.0.3 to 1.0.4
import { Subject } from "rxjs"; | ||
export function TakeUntilDestroy(constructor) { | ||
var original = constructor.prototype.ngOnDestroy; | ||
var subject = new Subject(); | ||
var originalDestroy = constructor.prototype.ngOnDestroy; | ||
constructor.prototype.componentDestroy = function () { | ||
return subject.asObservable(); | ||
this._takeUntilDestroy$ = this._takeUntilDestroy$ || new Subject(); | ||
return this._takeUntilDestroy$.asObservable(); | ||
}; | ||
constructor.prototype.ngOnDestroy = function () { | ||
original && typeof original === 'function' && original.apply(this, arguments); | ||
subject.next('ngOnDestroy'); | ||
subject.unsubscribe(); | ||
subject = new Subject(); | ||
originalDestroy && typeof originalDestroy === 'function' && originalDestroy.apply(this, arguments); | ||
this._takeUntilDestroy$ && this._takeUntilDestroy$.complete(); | ||
}; | ||
} | ||
//# sourceMappingURL=angular2-take-until-destroy.js.map |
{ | ||
"name": "angular2-take-until-destroy", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"main": "dist/index.js", | ||
@@ -8,3 +8,10 @@ "description": "Add take until component destroy for easy unsubscribe when the component destroyed", | ||
"scripts": { | ||
"prepublish": "rm -rf ./dist && tsc" | ||
"clearDist": "rm -rf ./dist", | ||
"clearTest": "rm -rf ./dist-test", | ||
"clear": "npm run clearDist && npm run clearTest", | ||
"compile": "tsc", | ||
"precompile": "npm run clearDist", | ||
"compileTest": "tsc -p tsconfig-test.json", | ||
"prepublish": "clear && npm run compile", | ||
"test": "npm run clear && npm run compile && npm run compileTest && tape ./dist-test/test/index.js" | ||
}, | ||
@@ -16,3 +23,4 @@ "typings": "./dist/index.d.ts", | ||
"maintainers": [ | ||
"Netanel Basal" | ||
"Netanel Basal", | ||
"Eduard Fidiles" | ||
], | ||
@@ -25,4 +33,5 @@ "repository": { | ||
"rxjs": "^5.0.0-rc.1", | ||
"tape": "^4.8.0", | ||
"typescript": "^2.0.6" | ||
} | ||
} |
@@ -18,8 +18,12 @@ # Angular 2 - easy unsubscribe when component destroyed | ||
export class InboxComponent { | ||
componentDestroy; | ||
constructor( ) { | ||
const timer$ = Observable.interval(1000) | ||
.takeUntil((<any>this).componentDestroy()) | ||
.takeUntil(this.componentDestroy()) | ||
.subscribe(val => console.log(val)) | ||
} | ||
// If you work with AOT this method must be present, even if empty! | ||
// Otherwise 'ng build --prod' will optimize away any calls to ngOnDestroy, | ||
// even if the method is added by the @TakeUntilDestroy decorator | ||
ngOnDestroy() { | ||
@@ -26,0 +30,0 @@ // You can also do whatever you need here |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3642
35
4
17