-
Notifications
You must be signed in to change notification settings - Fork 4
New feature: deferred ylcElementInit #7
Description
Hello!
This time it is not an issue but an idea of enhancement (note it would be great to add "enhancement" label to this "issue". I don't have write access so I can't do it myself).
Let say I want to use a jquery plugin called DataTable on:
<table data-ylcElementInit="initTable">
...
<tr data-ylcLoop="row: rows">
...
</tr>
</table>with:
initTable: function(...) {
$('table').DataTable(...);
}So I will use the ylcElementInit attribute to init the table. That works well.
Now, let say I want to init the DataTable after an ajax call in the future. As initTable is inconditionally called after the init method of the controller, the <table> has been rewritten by the plugin and ylc has no handle anymore on it => initTable will never be called from now on and the loop for the <tr> has disappeared.
Workaround: if I know I will populate the table only once in the future, I will not use ylcElementInit, but something like:
ajax(url, function(response) {
context.updateModel(function(model) {
model.rows = response.rows;
setTimeout(initTable, 1000); //ugly
});
});Proposal (for this case): add a new proto to updateModel, so we can do:
context.updateModel(...).then(...); //like a promiseBetter: internally make a template of the elements with the attribute ylcElementInit, and each time something in the children of the table has changed, recall the init element function.
What do you think?
Thank you for your time!