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
This commit is contained in:
Andrew Bonventre
2015-11-20 21:03:58 -05:00
parent 80bde79e0d
commit 05a7a5727c
3 changed files with 12 additions and 6 deletions

View File

@@ -76,7 +76,7 @@ limitations under the License.
<span class="positionIndicator">&#x25b6;</span>
</td>
<td>
<a href$="[[changeURL()]]">[[change.subject]]</a>
<a href$="[[changeURL]]">[[change.subject]]</a>
</td>
<td>[[_computeChangeStatusString(change)]]</td>
<td>
@@ -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) {

View File

@@ -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 '';
},

View File

@@ -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/');
});
});