marko-js-archive / marko-widgets

[LEGACY] Module to support binding of behavior to rendered UI components rendered on the server or client
http://v3.markojs.com/docs/marko-widgets/
MIT License
141 stars 40 forks source link

Allow to give a widgetId to the render() function #93

Open maberer opened 8 years ago

maberer commented 8 years ago

We need a way to reference a client side rendered child (inner) widget without the need to hold a reference to it from the parent...

Because holding a reference to a inner widgets requires to listen to its lifecycle events to prevent memory leaks (when holding a direct reference to the widget), or to invalidate the string ID (if that is stored) if the inner widget gets destroyed.

When there would be a way to give a name/id at render time, the inner widget could be easily be referenced later with this.getWidget("widgetID")

Something like that would do it (probably):

myComponent.render({ widgetId: this.getElId('foo' })

The this.getElId('foo') method would be used to generate the fully qualified DOM element ID for the newly rendered component that is then appended to the parent.