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

dom-repeat doesn't stamp correctly #3946

Closed
valdrinkoshi opened this issue Sep 13, 2016 · 7 comments
Closed

dom-repeat doesn't stamp correctly #3946

valdrinkoshi opened this issue Sep 13, 2016 · 7 comments

Comments

@valdrinkoshi
Copy link
Member

Description

dom-repeat should update the values when setting t.items = t.items and update the dom with the new values. This currently happens only on the first setting of the array.

Live Demo

http://jsbin.com/rumiko/2/edit?html,console,output

Steps to Reproduce

  1. click add button

Expected Results

Dom should have 2 paragraphs with item 0, item 1...as many times as add was clicked

@valdrinkoshi
Copy link
Member Author

@kevinpschaaf FYI

@jfrazzano
Copy link

If only the items sub properties are changing, then the best way to trigger an update of the values that are changing is to use one of the notification apis, particularly on a sub-property of an item object:

. Example: for(var i=0; i<i.items.length; i++){ this.set([“t.items”, i, “name”], this.t.items[i].name); },

while a bit tedious it works. If you are interacting with the dom to change the item[properties], or the items proper, var model= modelForElement(e.target);var item= itemForElement(e.target)l; model.set(item, [newValue]);

if you know the id of the template repeater, and are in the local dom of the repeater, you can use the this.$.domRepeatId convenience method-- (note here if you are using a variable for the element id, you should use something like var theId=“#”+someValribleThatHoldsTheId; var theDomRepeat= this.$$(theId) to grab the domRepeat)—and then use: Polymer.dom( theDomRepeat).children, and step through the children yourself to check on the properties you think have changed and then use the modelForItem and Model for Element above. If you do it once or twice you will quickly want to write some convenience functions for the different use cases, it makes the mutation observing and updating more pleasant.

A js mutation observer could also do the trick. I am about to try using the templatizer and an native mutation observer to see if I can’t both compose complex elements on the fly, maintain the updates of deeper mutations, and just do something cool. Will let send a demo if anything works out.

Hope that helped.

Sincerely,

Jason

PS… the document get element will likely be a bust in shadow dom, and there were a few other little things from my quick look at your code, I didn’t go further only because i couldn’t run the demo.

I pulled the error log pasted below:

"ReferenceError: customElements is not defined
at https://polygit.org/polymer+Polymer+:2.0-preview/webcomponentsjs+webcomponents+:v1/components/polymer/src/legacy/dom-module.html:82:3
at https://polygit.org/polymer+Polymer+:2.0-preview/webcomponentsjs+webcomponents+:v1/components/polymer/src/legacy/dom-module.html:89:3"
"error"

On Sep 12, 2016, at 8:06 PM, Valdrin Koshi notifications@github.com wrote:

Description

dom-repeat should update the values when setting t.items = t.items and update the dom with the new values. This currently happens only on the first setting of the array.

Live Demo

http://jsbin.com/rumiko/2/edit?html,console,output http://jsbin.com/rumiko/2/edit?html,console,output
Steps to Reproduce

click add button
Expected Results

Dom should have 2 paragraphs with item 0, item 1...as many times as add was clicked


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub #3946, or mute the thread https://github.com/notifications/unsubscribe-auth/AHxnvl_CsWYCT9zW_QOres4ey54hN4x0ks5qpejugaJpZM4J7KV1.

@sjmiles
Copy link
Contributor

sjmiles commented Sep 13, 2016

Fwiw, in the repro, the additional elements are being created, but they each have (what appears to be) only a single-space as content.

Also, fwiw, I tried experiments which set t.items = []; and then t.items = items. I tried both sync and async forms of resetting t.items, the effect was unchanged from the repro (collections issue?).

@jfrazzano
Copy link

@ Scott J. Miles… That’s interesting, now I really wanna see it. Will find the link and look.

Thanks. Scott. You know why they are popping a single space?

On Sep 12, 2016, at 9:56 PM, Scott J. Miles notifications@github.com wrote:

Fwiw, in the repro, the additional elements are being created, but they each have (what appears to be) only a single-space as content.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub #3946 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AHxnvtcG5y5xkLait3916WE7IL0Ens7fks5qpgLUgaJpZM4J7KV1.

@kevinpschaaf
Copy link
Member

This is due to bad interaction between removal of 2.0's Object/Array dirty checking and the Collection abstraction's use of array identity for key tracking, which still needs to be resolved in the 2.0 codebase. For time being please revert to using the legacy array path API's for mutating array data, which should still work.

@sjmiles
Copy link
Contributor

sjmiles commented Sep 13, 2016

Fwiw, it's also possible to treat the array as an immutable data structure and create a fresh instance for each modification, ala:

var items = t.items.slice();
items.push({
  name: 'item ' + t.items.length
});
t.items = items;

https://jsbin.com/vamibu/edit?html,output

sorvell pushed a commit that referenced this issue Sep 23, 2016
@sorvell
Copy link
Contributor

sorvell commented Sep 23, 2016

Closed via #3970.

@sorvell sorvell closed this as completed Sep 23, 2016
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