From 05a7a5727cd406dbde1516175b7aad1e224165bb Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Fri, 20 Nov 2015 21:03:58 -0500 Subject: [PATCH] Fix bug where changeURL was not updating to reflect its change object Computed bindings are recomputed (say, on a model update), when the arguments to the computation function change. Since no arguments were being passed to changeURL(), it was only being computed once. In order to maintain a clean API for external callers, move changeURL from a function to a computed property. This way the caller doesn't have to pass in the change number but it still updates when the change number does. Bug: Issue 3689 Change-Id: I92a659b3c917f77d4e212c98af7c763174756074 --- polygerrit-ui/app/elements/gr-change-list-item.html | 12 ++++++++---- polygerrit-ui/app/elements/gr-change-list.html | 2 +- polygerrit-ui/app/test/gr-change-list-item-test.html | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/polygerrit-ui/app/elements/gr-change-list-item.html b/polygerrit-ui/app/elements/gr-change-list-item.html index 374333744b..87d7fc6692 100644 --- a/polygerrit-ui/app/elements/gr-change-list-item.html +++ b/polygerrit-ui/app/elements/gr-change-list-item.html @@ -76,7 +76,7 @@ limitations under the License. - [[change.subject]] + [[change.subject]] [[_computeChangeStatusString(change)]] @@ -118,11 +118,15 @@ limitations under the License. reflectToAttribute: true, }, change: Object, + changeURL: { + type: String, + computed: '_computeChangeURL(change._number)', + } }, - changeURL: function() { - if (!this.change) { return ''; } - return '/c/' + this.change._number + '/'; + _computeChangeURL: function(changeNum) { + if (!changeNum) { return ''; } + return '/c/' + changeNum + '/'; }, _computeChangeStatusString: function(change) { diff --git a/polygerrit-ui/app/elements/gr-change-list.html b/polygerrit-ui/app/elements/gr-change-list.html index f3f3ca202c..c2418be7ad 100644 --- a/polygerrit-ui/app/elements/gr-change-list.html +++ b/polygerrit-ui/app/elements/gr-change-list.html @@ -111,7 +111,7 @@ limitations under the License. _changeURLForIndex: function(index) { var changeEls = this._getNonHeaderListItems(); if (index < changeEls.length && changeEls[index]) { - return changeEls[index].changeURL(); + return changeEls[index].changeURL; } return ''; }, diff --git a/polygerrit-ui/app/test/gr-change-list-item-test.html b/polygerrit-ui/app/test/gr-change-list-item-test.html index d9cf2b640f..1d3c9e32ca 100644 --- a/polygerrit-ui/app/test/gr-change-list-item-test.html +++ b/polygerrit-ui/app/test/gr-change-list-item-test.html @@ -82,7 +82,9 @@ limitations under the License. '/q/status:open+project:combustible-stuff+branch:lemons'); element.change = { _number: 42 }; - assert.equal(element.changeURL(), '/c/42/'); + assert.equal(element.changeURL, '/c/42/'); + element.change = { _number: 43 }; + assert.equal(element.changeURL, '/c/43/'); }); });