I am new to DoneJS and any help is appreciated. I am trying to build an App that loads components dynamically in a tab-based widget. Every time the route changes the app should insert the component dynamically in the DOM.
I tried to declare a static property called “tabs” in the AppViewModel that holds an array of components names, like this:
const AppViewModel = Map.extend('AppViewModel',
{
tabs: []
},
{
define: {
message: {
value: 'Hello World!',
serialize: false
}
}
});
route(':page', { page: 'home' });
I also created a stache helper:
stache.registerHelper("tabsComponent", function(options){
options.context.constructor.tabs.push(options.context.attr('page'));
$.each(options.context.constructor.tabs, function(index, el) {
template += ' <can-import from="system/'+el+'/" can-tag="loading"><'+el+' /></can-import>';
});
return stache(template)(this,options.helpers, options.nodeList);
});
And then in the index.stache file:
{{{tabsComponent}}}
And it works, each time the route changes the tabComponents helper is executed adding the current page to the tabs static array, loops the array and renders each component. But the problem is that each time a route changes all components in the static tabs array are rendered again. I want just the last route called to be imported and rendered, because, usually components are forms and a user could be filling a form but clicked on another route and the “state” of the filled form is lost.
Im not sure if this approach is correct or if this is a good practice, but basically i need that on each route change a new component is loaded, but without “losing” the previous one. I pretend to put each component in a tab widget. Any advise is appreciated. THANKS!