how to unsubscribe in a widget

0
In a new widget I create a menu and subscribe for events in the applyContext mx.data.subscribe({ guid: context.getGuid(), callback: dojo.hitch(this, this.updateButtonLabel) }); In my uninitialize function the widget is destroyed this.mlMenuButton && this.mlMenuButton.destroyRecursive(); this.domNode && dojo.destroy(this.domNode); But the widget still get callback, and because the widgets is already destroyed it generate errors. Even unsubscribing in the uninitialize function does not help var guid = this.context.getGuid(); mx.data.unsubscribe({guid : guid}); Can someone tell me how to properly destroy and unsubscibe a widget?
asked
2 answers
2

By using this.subscribe instead of mx.data.subscribe, the subscriptions are automatically removed when the widget is destroyed.

answered
1

The correct way is to unsubscribe with a handler. See treeview.js

this._subscription = mx.processor.subscribe({ 

if (this._subscription)
                mx.processor.unsubscribe(this._subscription);

Edit:

Also available is:

this.removeSubscriptions();
answered