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

[1.0.2] Setting property treated as idempotent, but isn't #1768

Closed
hawkett opened this issue Jun 6, 2015 · 3 comments
Closed

[1.0.2] Setting property treated as idempotent, but isn't #1768

hawkett opened this issue Jun 6, 2015 · 3 comments
Assignees
Labels

Comments

@hawkett
Copy link

hawkett commented Jun 6, 2015

Originally raised this issue: PolymerElements/iron-selector#16 - but the root of that problem is more appropriate here. From that issue:

The first jsbin still highlights some issues though. Basically, when setting a property value, polymer checks the current value, and does a no-op if they're the same (i.e. assumes idempotence). However, in situations where one of the values a complex observer depends on is undefined, the observer is not executed. Subsequent attempts to set that same value are no-op'd and the observer is never called, despite the property having been set.

@hawkett
Copy link
Author

hawkett commented Jun 7, 2015

Actually... the observer at issue in the example above is _updateSelected(attrForSelected, selected) - shouldn't that observer be correctly executed when attrForSelected has it's value set to null by the property default?

@kevinpschaaf
Copy link
Member

There is special handling in the data layer to queue data notification handling from clients in a given element until all of its clients (local DOM custom elements) have initialized. This happens for free when using things like observers that run based on data-changed listeners set up by Polymer. In your example where you set up your own on-data-change handler manually, this queueing does not happen, and so (as you pointed out), you end up setting values to one of the children before it has initialized (which is bad).

Probably the easiest option is to simply "use the system", as in the following jsBin, where I've replaced your on-data-change handler with an observer for the same property:
http://jsbin.com/xoqamu/2/edit

Can you confirm whether you can use this approach, and we'll close the issue?

@kevinpschaaf kevinpschaaf self-assigned this Jun 8, 2015
@kevinpschaaf kevinpschaaf added p2 and removed 0.5 labels Jun 8, 2015
@hawkett
Copy link
Author

hawkett commented Jun 9, 2015

Yep, can confirm - that's equivalent to the second jsbin I posted (preferred approach/solution).

The "Don't use events, use observers" pattern is definitely one to hang onto :)

@hawkett hawkett closed this as completed Jun 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants