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

Backfill/Focus Item Question #511

Open
robrez opened this issue Mar 9, 2018 · 2 comments
Open

Backfill/Focus Item Question #511

robrez opened this issue Mar 9, 2018 · 2 comments

Comments

@robrez
Copy link

robrez commented Mar 9, 2018

Description

We have a use-case here that is probably not typical... so you can tell me to get lost! If nothing else, maybe this will help someone in the future.

Our server sends rendered markup that we want to show within an iron-list... there isn't necessarily any definitive "template". So our list's template contains a custom-element whose role is to render the html received from the server. eg:

  items = [
    { markup: '<div>hello</div>' }
  ];
  this.$.list.items = items;

That works fine...

Then I think... "ah... I really don't want to innerHTML that markup every time a given item is re-bound". So I turn the markup into an html element:

  items = [
    { element: @type HTMLElement }
  ];

Performance is noticeably imrpoved. - but - I keep hitting some wierd problem: Often times, when scrolling back to the top of the list, the first element is empty. My implementation for the template element is something like this:

class HtmlEcho extends Polymer.Element {
  set item(item) {
    let p = this.shadowRoot;
    while(p && p.firstChild) { p.removeChild(p.firstChild); }
    p.appendChild(item.element);
  }

After some investigation, it seems that the model was bound to two separate template instances. One of them is the offscreen (translateY(-10000)) items. Since the dom element is appended to that offscreen thing, it was removed from the physical item where it's wanted.

The solution is simple... everyone gets a copy.

    p.appendChild(item.element.cloneNode(true));

I thought it might be worth reaching out to the team. The full scope of the backfillItem is beyond my grasp... I may have some of the details here wrong. Should it be given a copy of the model instead of a reference?

@robrez
Copy link
Author

robrez commented Mar 9, 2018

Edit: I realize after posting that a copy of the model for the backfill item wouldn't fix my particular issue since Im doubtful copying an Object would deep copy an html element member.

Some additional questions follow:

Can some property be exposed for a template instance "hey... You're not real". Is the backfill item used for computing metrics at all?

@hangdocgiatot
Copy link

thankkkk

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

No branches or pull requests

2 participants