-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Only the first instance of a dom-repeat template gets notified with linkPaths #5590
Comments
Very helpful. Thanks. |
That definitely seems like a bug. Stranger still, if you call |
You mean like this? I expect this not to work:
Because I believe the implementation does something like this:
|
Also, notice that this bug isn't present in Polymer 1. |
@trevordixon that is what I meant. It looks to me from the code in https://github.com/Polymer/polymer/blob/master/lib/mixins/property-effects.js#L453 ... but that doesn't seem to be the case. |
Yes, notifications go both ways once linked. But order matters when linking. https://github.com/Polymer/polymer/blob/master/lib/mixins/property-effects.js#L1759 |
Thanks for the patience. I confirmed the bug and root caused it to the effect de-duping introduced in Polymer 2, which is a detail of how we introduced batching. Since this construction results in a batch of paths through the same object ( |
@trevordixon you're right, I totally missed that. @kevinpschaaf this detail of linkPaths isn't documented anywhere that I can see--certainly not in the API docs, which list target path and source path args, but don't describe what that means. Maybe we should add text to the API doc? Something like: Path notifications are forwarded both directions (source to target and target to source). The target path must be unique. If you need to link a path more than once, specify that path as the source. For example: linkPaths(target1, source);
linkPaths(target2, source); |
Yeah, agree on adding docs for noting that the target must be unique (this is to make unlinking |
I keep running into issues that I think are caused by this bug. I add a call to |
This keeps causing me problems. I'll probably have to refactor a couple of components that rely on two-way binding and linkPaths to instead just use one-way binding, unless there are plans to address this bug. @kevinpschaaf How hairy is the code? Could somebody with little knowledge of Polymer internals fix this bug? |
@trevordixon It's unfortunately probably the hairiest part of the Polymer codebase. I had looked into this a little after it was filed, and finding a solution seemed seemed pretty over-constrained (i.e., a fix would risk changing an invariant that would break other things). Eliminating the two-way bindings is likely just going to be better overall for your codebase's health, so if that's possible, I'd recommend that. But, in thinking about the problem a little more this morning, I think I may have made some progress on a possible solution, so wanted to note that here so it's not lost: The crux of the issue can be reduced to a question of what happens under these conditions: observers: ['stuffChanged(stuff.*)'] el.setProperties({
'stuff.x': 'x'
'stuff.y': 'y'
}); (Note, the API docs note that batching paths in The question is: How should We can't simply not dedupe, since batching & deduplication is how we were able to remove the ill-fated "undefined rule" from 1.x where we didn't call observers if an argument was properties: {
a: { value: 'a' },
b: { value: 'b' },
},
observers: ['stuffChanged(a, b)'] However, after thinking a bit more about it this morning, it does seem like we could specifically treat paths matching a wildcard specially and not de-duplicate those effects. The rule would be "if a path matches a wildcard argument, we always call (or re-call) the observer for that, to avoid the information about a path change to be lost". While this would fix the original issue noted here, it would cause a minor change to an observer like this: observers: ['stuffChanged(a, stuff.*)'] el.setProperties({
a: 'a',
'stuff.x': 'x'
'stuff.y': 'y'
});
// Current (called once, path information lost):
// stuffChanged('a', {base: stuff, path: 'stuff', value: stuff})
// With change (called for each path):
// stuffChanged('a', {base: stuff, path: 'stuff', value: stuff})
// stuffChanged('a', {base: stuff, path: 'stuff.x', value: stuff.x})
// stuffChanged('a', {base: stuff, path: 'stuff.y', value: stuff.y}) The change, of course, is that we'd potentially be calling observers/effects more than we previously did, which could break users. I think that might generally be fine, since the setup with batching above can only technically be caused by |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Live Demo
https://jsbin.com/laqilozaci/4/edit?html,output
Steps to Reproduce
Use linkPaths to link subproperties of multiple array elements to an object.
Use dom-repeat with the array.
Change a property of the object.
Expected Results
Each of the dom-repeat instances should be updated according to the new value.
Actual Results
Only the first instance is updated. Without dom-repeat, it works properly:
Browsers Affected
Tested in Chrome.
Versions
The text was updated successfully, but these errors were encountered: