Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymer.Templatize issues. #4458

Closed
jonagh opened this issue Mar 24, 2017 · 4 comments
Closed

Polymer.Templatize issues. #4458

jonagh opened this issue Mar 24, 2017 · 4 comments
Assignees

Comments

@jonagh
Copy link

jonagh commented Mar 24, 2017

I'm upgrading to Polymer 2.0 and in that process decided to change a component from using Templatizer behaviour to using Poymer.Templatize, which seems to be the new thing to use... but I am having issues getting it to work as expected.

  1. The example in the docs fails outright due to the options object being undefined.
    https://www.polymer-project.org/2.0/docs/api/namespaces/Polymer.Templatize

Polymer.Templatize.templatize(template) errors due to no options object existing,
instead if I pass an empty options object (and owner/this) then it works. Eg: Polymer.Templatize.templatize(template, this, {}).
Should the docs be fixed? or should Templatize deal with undefined options?

  1. The initial data values are not reflected in the generated template. Am I misunderstanding how this is supposed to work? Setting the values on the instance directly works, but not the initial values!?
    For example this won't output 'initial' as expected:
let instance = new TemplateClass({myProp: 'initial'});
this.shadowRoot.appendChild(instance.root);

but then if you do the following it will output 'new value' correctly:
instance.myProp = 'new value';

JSBin example: https://jsbin.com/zimewuf/edit?html,output

PS. Templatize in Polymer.Tempaltize.templatize is misspelled in the docs.

Chrome 58
Polymer: 2.0-preview

@dfreedm
Copy link
Member

dfreedm commented Mar 24, 2017

It looks like both owner and options are required, contrary to the docs.

The options argument should just fall back to an empty object, but the owner most certainly has to be set, probably to an element instance.

@kevinpschaaf or @sorvell, I'm not sure exactly what owner has to be here, can you comment?

@RoXuS
Copy link

RoXuS commented Mar 27, 2017

Same behavior since Polymer 2.0, I have to reset the properties on the instance, see https://github.com/RoXuS/paper-datatable-api/blob/2.0-preview/src/paper-datatable-api-column.js#L119.

👍

@sorvell
Copy link
Contributor

sorvell commented Dec 21, 2017

Sorry for the delay on this. We definitely still need to update the docs here:

  • the 2nd owner argument to templatize is required.
  • templatized content is "bound" by default to the owner object and the initial values are only for populating instance properties as specified by passing instanceProps in the options (3rd) argument to templatize (example)

@kevinpschaaf
Copy link
Member

After looking back at the code, seems like use of templatizer without an owner & host property forwarding was just a missed use case. I'm making a PR that allows this to work, since it's so basic and easy to support:

<template id="myTemplate">
  <div>[[prop]]</div>
</template>

<script>
  const MyTemplate = Polymer.Templatize.templatize(myTemplate);
  const inst = new MyTemplate({prop: 0});
  document.body.appendChild(inst.root);
  setInterval(_ => inst.prop++, 1000);
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants