Famous / engine

MIT License
1.75k stars 250 forks source link

[BUG?] removeComponent does not stop onUpdate. #482

Closed elinfante closed 8 years ago

elinfante commented 8 years ago

I have an onUpdate Component attached to the NODE but when I remove the component keeps firing onUpdate.

Have you experiences something similar?

This is the code:

function _renderDigitCount () {

    this.BZ_onUpdate_COMP = this.addComponent({
        onUpdate: function(time) {
            _onRenderDigitCount.call(this)
        }.bind(this)
    });
    this.requestUpdate(this.BZ_onUpdate_COMP);

    this.BZ_copyCountTransitionable = new FA_TRANSITIONABLE(Number(this.BZ_font_MO.BZ_COPY_animation.startVal));
    this.BZ_copyCountTransitionable.delay(BZ_DisplayGlobals_SRV.timeRatio(this.BZ_font_MO.BZ_COPY_animation.delay));
    this.BZ_copyCountTransitionable.set(Number(this.BZ_font_MO.BZ_COPY_animation.endVal), {duration:BZ_DisplayGlobals_SRV.timeRatio(this.BZ_font_MO.BZ_COPY_animation.time), curve: "outQuint" }, _onRenderDigitCountCompleted.call(this));

}

function _onRenderDigitCount () {

    if (this.BZ_copyCountTransitionable === undefined) {
        _onRenderDigitCountCompleted.call(this);
    } else {
        var val = _numberFormat.call(this, this.BZ_copyCountTransitionable.get() );
        this.BZNO_FA_EL_DOM.setContent(val);
        this.requestUpdateOnNextTick(this.BZ_onUpdate_COMP);
    }

}

function _onRenderDigitCountCompleted () {

    this.removeComponent(this.BZ_onUpdate_COMP);

}
elinfante commented 8 years ago

After few more tests I came up with the idea of setting the component to null. That seemed to do the trick.

function _onRenderDigitCountCompleted () {

    this.BZ_bzCopy_delay.clear();
    this.removeComponent(this.BZ_onUpdate_COMP);
    this.BZ_onUpdate_COMP = null;

}
trusktr commented 8 years ago

@elinfante Can you please re-open this? This is for sure a bug and should be addressed without requiring workarounds.