-
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
Array observer delivers incorrect changeRecord.path index after deleting item in array #2007
Comments
Notifications for arrays use unique "keys" for rather than index, so what you are seeing is expected, although possibly unintuitive and not yet well documented. This is done to ensure path linkage between objects in arrays are maintained despite possible insertions or deletions in the array. If you need the index, for now you can do this to workaround, using the var collection = Polymer.Collection.get(changeRecord.base);
var idx = changeRecord.base.indexOf(collection.getItem(key)); Where We'll keep this issue open to consider how to improve the API. |
Thanks. It might be nice also to have a helper method that would simplify parsing keys from pathes. Perhaps you could provide the key as |
One thought is to disambiguate keys from indices in paths by using a token like Aside from needing to parse the base path (e.g. |
Forgive me being paranoid, but how about escaping both |
I register an array observer:
sightChanged is then called argument changeRecord = {path: 'sights.2.description', ...}. If I remove something from the sights array before index 2, the path 'sights.2.description' remains the same, even though it should now be decremented by one. This results in index out of bound problems:
Seems like a bug to me. For the time being, is there a workaround to observing arrays?
The text was updated successfully, but these errors were encountered: