I've recently created what I thought was a page-based application which is now being used embedded as a control. The 'control' needs to unload/reload multiple times. This is causing problems do to subscriptions and dijit controls that were not destroyed. I've worked out the necessary disconnect, registry.destroy logic but it's tedious. Are there any best-practices for making a collection of controls destroy-able?
Here's sample code showing what can be done with basic logic: http://pastebin.com/bUUBUMP9
I'm asking if a framework exists analogous to an AppDomain where anything created in that context can be cleaned up. Similar to embedding the control in an IFRAME...but not.
I can see two practices that will make your life easier:
Dijit widgets extend dijit/_WidgetBase
and therefore a widget provides (dis)connect
and (un)subscribe
methods. You should use them instead of general purpose aspect.connect()
and topic.subscribe()
when wiring widgets, because this way the widget disconnects and unsubscribes automatically when being destroyed, so you do not have to.
Organize your widgets via dijit/layout
, e.g. use dijit/layout/ContentPane
instead of placing widgets just into the DOM, because this way you'll need to call destroyRecursive()
just on the ContentPane
and it will properly destroy all its children. Nest containers according to your needs to achieve proper granularity and visual appeal (it's the same concept as Java's JPanel
).
Applying the aforementioned principles you might only need to call destroyRecursive()
on the container highest in the hierarchy to destroy dijits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With