ariatemplates / hashspace

JavaScript client-side template engine
http://hashspace.ariatemplates.com
Apache License 2.0
14 stars 18 forks source link

Impossible to know when a component has been added to the actual DOM #319

Closed flongo closed 9 years ago

flongo commented 9 years ago

In the controller of a component it is possible to define

The latter is called after the template using an instance of the component has been rendered, which means that the component markup has been added to the DOM.

But when the component is not shown upon the render because some conditions are not met, when these conditions are satisfied and the component gets finally created, the $afterRender of the new instance is not called, and when the $refresh is called the corresponding element has not been added to the DOM yet.

This means that is is impossible to know when the component markup has been added to the DOM.

Here is a plunker that shows the scenario: http://plnkr.co/edit/ddorECLgMFujbNoca5hc?p=preview

When you click on the button to add a second placeholder, you can see that the $afterRender has not been called, and when the $refresh is called it is impossible to access the generated element.

b-laporte commented 9 years ago

Indeed $afterRender doesn't make sense, as render is only done once, whereas element creation/deletion can be made multiple times. I think we need something like $onDOMInsert() that should be called when the component is insertered in the real DOM (i.e. not in a DOM fragment).

flongo commented 9 years ago

Ok, I will replace the $afterRender method with $onDomInsert