首页 > 其他 > 详细

A常用的装饰器

时间:2020-05-03 15:05:24      阅读:31      评论:0      收藏:0      [点我收藏+]
function AutoUnsub(obs$ = []) {
    return function(constructor: any) {
        const orig = constructor.prototype.ngOnDestroy
        constructor.prototype.ngOnDestroy = function() {
            for(const prop in this) {
                const property = this[prop]
                if(typeof property.unsubscribe === "function" && !obs$.includes(property))
                    obs$.push(property)
            }
            for(const ob$ of obs$) {
                  ob$.unsubscribe()
            }
            orig.apply()
        }
    }
}

  

A常用的装饰器

原文:https://www.cnblogs.com/dming4/p/12821845.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!