regularjs/regular

当组件被destroy之后再调用$update是否应该执行更新

Closed this issue · 0 comments

碰到这样一个问题

var Nest = Regular.extend({
    name:"test",
    template:"<p>h3中的内容:{test}</p><h3 ref=test>regular测试demo</h3>",
    config: function(data){
        data.helloCopy = 100;
        data.htmlTest=130;
    },
    computed:{
        test:function () {
            //console.log(this.$refs);
            if(this.$refs.test){
                return this.$refs.test.innerHTML;
            }
            return "";
        }
    },
    startAjaxRequire:function () {
        setTimeout(function() {
            //模拟ajax的回调,并调用更新
            //这种操作感觉还是比较常见
            this.$update();
        }.bind(this),200);
    }
});
var test=new Nest();

test.$inject(document.body);
test.startAjaxRequire();
//在ajax回调前组件被销毁
test.destroy();

在ajax调用期间组件被销毁了,但是最终回调还是执行了$update,这样子computed中涉及parentNode ,$refs属性都会报错。是否应该在$update时判断一下$phase如果已经是销毁状态就不进行更新了。