Closed sorvell closed 10 years ago
/sub
So this is currently working as designed, but I agree it's somewhat surprising.
It's not really worth a long explantation, but this is basically a side-effect of how Node.bind() works (any sub-templates have had Node.bind() called on them, but they haven't reacted by building their instances yet).
It'd be helpful to understand more the use case for calling createInstance() and doing work synchronously with the result which requires all sub-instances to be stamped.
Take a look at these two jsBins for an example use case of what I am trying to do... at least what led us here.
In the first, I am passing the needed templates in as content, and then querying them. All works well, but its not exactly what I want to do: http://jsbin.com/ugikeDa/2/edit?html,output
In the second, I am trying to include the templates within the polymer component itself. This is more practical for my use case, but I can't seem to get the magic combination to get it to work. http://jsbin.com/ugikeDa/3/edit?html,output
Yes, I know for this simple example there are other ways to do this in the template with binding, etc. but my actual component is more complex. This shows the specific issue I am encountering well, which boils down to:
How does an element maintain templates for variable content without polymer stripping the content?
I think for this kind of use you don't want to use an instantiating template directive. there's no point in telling to bind since you never use the instance that it produces. you can get your hands on the content within a template via the ref property. e.g. something like
<polymer-element name="my-thing">
<template>
<template id="someStuff">
<div>My Stuff</div>
</template>
</template>
<script>
Polymer('my-thing', {
created: function() {
var instance = this.$.someStuff.ref.cloneNode(true);
}
}
</script>
</polymer-element>
This is now fixed. createInstance() will now synchronously return a fully-produced instance (including any sub-template instantiation)
See console output in this example: http://jsbin.com/OViviwi/1/edit
When cloneNode(true) is used on a template's content to stamp a nested template, the nested template content is intact. However, when createInstance is used, the nested template's content is blank.