/**
* Auto log
* Auto unsubscrible
*/
export function AutoComponent(obs$ = []) {
return function (constructor: Function) {
console.log(constructor, "log");
const original_Init = constructor.prototype.ngOnInit;
constructor.prototype.ngOnInit = function () {
console.log("Enter page " + this.name, "log");
if (original_Init) {
original_Init.apply(this);
}
};
const origial_Destroy = constructor.prototype.ngOnDestroy;
constructor.prototype.ngOnDestroy = function () {
for (const prop in this) {
const property = this[prop];
if (
property &&
typeof property.unsubscribe === "function" &&
!obs$.includes(property)
) {
obs$.push(property);
}
}
for (const ob$ of obs$) {
ob$.unsubscribe();
}
console.log(origial_Destroy, "log");
if (origial_Destroy) {
origial_Destroy.apply(this);
}
console.log("Exit page " + this.name, "log");
};
};
}
人生旅途,边走边看...