ibm-js / delite

HTML Custom Element / Widget infrastructure
http://ibm-js.github.io/delite/
Other
68 stars 28 forks source link

To dynamically specifying a template upon instantiation of a widget #416

Closed martinfitzg closed 9 years ago

martinfitzg commented 9 years ago

Hello all, Don't really think this qualifies as an issue, but I'm having this problem any help would be appreciated...... I need to be able to specify a template externally as a parameter to a widget when it is instantiated. In the life cycle of the Widget, the mixin phase happens after the Render function so this rules this out. Then trying to extend the widget something like the like this

_buildWidget: function(templateInput){

    var AlteredWidget = dcl([MyWidget], {               
            render : function () {
                                      this.template =templateInput;
                if (this.template) {
                        this._templateHandle = this.template(this.ownerDocument, register);
                         }
            }});
return AlteredWidget;

}

But when this is done, the "new" Render function never gets called.

Any advice is appreciated........

cjolif commented 9 years ago

Isn't it related to #414?

martinfitzg commented 9 years ago

Hey Christophe, I taught that two initially, but to me #414 would seem to want to be able to change the template of a widget during "run time" not at the initial instantiation of a widget. I'm open to correction.....

wkeese commented 9 years ago

I think this is the same as #414, because initial parameters are handled in the same way as properties changed during "run time". In other words, both initial parameters and properties changed during run time are handled in computeProperties() or refreshRendering().) So, setting the template like:

new MyWidget({ template: ... })

is no different than setting the template like:

var x = new MyWidget();
x.template = ...;

or even:

var x = new MyWidget();
setTimeout(function () { x.template = ...; }, 100);

Also, "setting" the template and "changing" the template are essentially the same thing. The only difference is whether the template was initially set, or whether it was null. In the examples above, the widget prototype presumably doesn't specify a template, so there's no template until the application specifies one.

martinfitzg commented 9 years ago

I stand corrected!