{"action":"created","issue":{"url":"https://api.github.com/repos/PolymerElements/iron-list/issues/131","labels_url":"https://api.github.com/repos/PolymerElements/iron-list/issues/131/labels{/name}","comments_url":"https://api.github.com/repos/PolymerElements/iron-list/issues/131/comments","events_url":"https://api.github.com/repos/PolymerElements/iron-list/issues/131/events","html_url":"https://github.com/PolymerElements/iron-list/issues/131","id":114114796,"number":131,"title":"Selected item becomes deselected when updated in firebase","user":{"login":"albertolobrano","id":930785,"avatar_url":"https://avatars.githubusercontent.com/u/930785?v=3","gravatar_id":"","url":"https://api.github.com/users/albertolobrano","html_url":"https://github.com/albertolobrano","followers_url":"https://api.github.com/users/albertolobrano/followers","following_url":"https://api.github.com/users/albertolobrano/following{/other_user}","gists_url":"https://api.github.com/users/albertolobrano/gists{/gist_id}","starred_url":"https://api.github.com/users/albertolobrano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/albertolobrano/subscriptions","organizations_url":"https://api.github.com/users/albertolobrano/orgs","repos_url":"https://api.github.com/users/albertolobrano/repos","events_url":"https://api.github.com/users/albertolobrano/events{/privacy}","received_events_url":"https://api.github.com/users/albertolobrano/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/PolymerElements/iron-list/labels/pending-response","name":"pending-response","color":"333333"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-10-29T18:23:25Z","updated_at":"2015-11-14T08:40:42Z","closed_at":null,"body":"Steps to reproduce the issue:\r\n\r\n1) create an iron-list binded to  a firebase collection element \r\n2) select an item \r\n3) update the item in firebase \r\n4) the selected item becomes unselected \r\n\r\n\r\nFirebase collection uses : this.splice('data', this.data.indexOf(oldValue), 1, value); when it needs to update a value.   Iron list as a result will delete and add the element to the list and in the process it will deselect. \r\n\r\nI am not sure if this is an issue with the list or if the firebase component that maybe should use something more clever then splice.     I am not an expert so i will live you this decision to you. \r\n"},"comment":{"url":"https://api.github.com/repos/PolymerElements/iron-list/issues/comments/156670616","html_url":"https://github.com/PolymerElements/iron-list/issues/131#issuecomment-156670616","issue_url":"https://api.github.com/repos/PolymerElements/iron-list/issues/131","id":156670616,"user":{"login":"albertolobrano","id":930785,"avatar_url":"https://avatars.githubusercontent.com/u/930785?v=3","gravatar_id":"","url":"https://api.github.com/users/albertolobrano","html_url":"https://github.com/albertolobrano","followers_url":"https://api.github.com/users/albertolobrano/followers","following_url":"https://api.github.com/users/albertolobrano/following{/other_user}","gists_url":"https://api.github.com/users/albertolobrano/gists{/gist_id}","starred_url":"https://api.github.com/users/albertolobrano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/albertolobrano/subscriptions","organizations_url":"https://api.github.com/users/albertolobrano/orgs","repos_url":"https://api.github.com/users/albertolobrano/repos","events_url":"https://api.github.com/users/albertolobrano/events{/privacy}","received_events_url":"https://api.github.com/users/albertolobrano/received_events","type":"User","site_admin":false},"created_at":"2015-11-14T08:40:42Z","updated_at":"2015-11-14T08:40:42Z","body":"This is what i did to solve the issue. It is ugly but it works until the issue will be fixed upstream         \r\n\r\n        oldSpySelection: Object,\r\n        oldSpySelectedIndex: Number,\r\n\r\n_updateSelectedItem: function(item, old) {\r\n\r\n          this.trace('Item notification received item value is ', {\r\n            item: item,\r\n            oldSpyItem: this.oldSpySelection,\r\n            oldSpyIndex: this.oldSpySelectedIndex,\r\n            old: old\r\n          });\r\n\r\n          //this happens the first time we lunch the app. We do not trow any envent\r\n          if (!item && !old) {\r\n            return;\r\n          }\r\n\r\n          //this happen when we deselect an item in the detail view. we do not need to do anything\r\n          if (!item && !this.oldSpySelection) {\r\n            return;\r\n          }\r\n\r\n          //item is null and old is populated\r\n          //this is either a case where\r\n          // 1) the selected item was updated in firebase or\r\n          // 2) we deselected the item\r\n          // 3) we are selecting another element.  in the next interaction\r\n          // the indexes will be different and we will deselect this\r\n          //in both case we do not allow it so we need to reselect it our selfs\r\n          // here using the spy index\r\n          if (!item && old) {\r\n            this.$.itemsList.selectItem(this.oldSpySelectedIndex);\r\n            return;\r\n          }\r\n\r\n          //this is the very first thing it will happen when we click an item\r\n          if (item && !old) {\r\n            this.oldSpySelectedIndex = this.items.indexOf(item);\r\n            this.oldSpySelection = item;\r\n            this.trace('Fire ItemSelected event');\r\n            this.fire('itemSelected', {item: item});\r\n            return;\r\n          }\r\n\r\n          var itemIndex = this.items.indexOf(item);\r\n\r\n          //if the spy index and the item index is the same then we update the item\r\n          // or deselected and reselected.\r\n          if (this.oldSpySelectedIndex === itemIndex) {\r\n            this.oldSpySelection = item;\r\n          } else {\r\n            var oldIndex = this.oldSpySelectedIndex;\r\n            this.oldSpySelectedIndex = itemIndex;\r\n\r\n            this.$.itemsList.deselectItem(oldIndex);\r\n          }\r\n\r\n        }"}}