I have created a widget in Aikau and the idea is that inside of it, there is only one widget in any moment and it swaps from one type to another dynamically.
My procedure is the follow:
Right now my code works, but I don't know if I am eliminating all the widgets children properly. I didn't find any function in the documentation to do it:
swapWidget: function myPackage_myWidget__swapWidget(event) {
// REMOVE ALL THE CHILDREN
// is it this ok?
$(this.domNode).find('div').remove();
var widgetId = event.widgetId
, widget = this.widgetsPosibilities[widgetId]
, clonedWidgets = lang.clone([widget])
;
this.processWidgets(clonedWidgets, this.domNode);
},
postCreate : function myPackage_myWidget__postCreate() {
var event = {widgetId: this.initWidgetId};
this.jumpWidget(event);
this.alfSubscribe('MY_CUSTOM_EVENT', lang.hitch(this, this.swapWidget));
this.inherited(arguments);
}
It is enough "$(this.domNode).find('div').remove();" to eliminate all the children widgets?
In general I prefer to use JQuery, but maybe the right way is to using Dojo.
What is best way?
What will last for longer with in new releases of Aikau?
You should try using the DynamicWidgets. This widget allows you to configure a subscription topic that can be published on with a widgets model. The DynamicWidgets widget will automatically delete the displayed widgets and render the requested widgets.
I definitely wouldn't recommend the approach that you're currently taking as it's unlikely to be future proof. If you need I can provide some examples of using this widget, or you can review the examples in the unit test application.