Chromium Code Reviews| Index: chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js |
| diff --git a/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js b/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js |
| index e84f96c4f5ab6107fb92ec31b8c1e7e6936d1ca7..bce31335b581b53217ce3be8e38b7bd62517fcfa 100644 |
| --- a/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js |
| +++ b/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js |
| @@ -32,20 +32,33 @@ settings.BluetoothAddDeviceBehavior = { |
| value: /** @return {Array} */ function() { |
| return []; |
| }, |
| - observer: 'deviceListChanged_', |
| + }, |
| + |
| + /** |
| + * The ordered list of unpaired bluetooth devices. |
| + * @type {!Array<!chrome.bluetooth.Device>} |
| + */ |
| + unpairedDeviceList_: { |
| + type: Array, |
| + value: /** @return {Array} */ function() { |
| + return []; |
| + }, |
| }, |
| /** |
| * Reflects the iron-list selecteditem property. |
| * @type {!chrome.bluetooth.Device} |
| */ |
| - selectedItem: { |
| + selectedItem_: { |
| type: Object, |
| observer: 'selectedItemChanged_', |
| }, |
| }, |
| - /** @type {boolean} */ itemWasFocused_: false, |
| + observers: ['deviceListChanged_(deviceList.*)'], |
| + |
| + /** @type {boolean} */ |
| + itemWasFocused_: false, |
| /** @private */ |
| adapterStateChanged_: function() { |
| @@ -55,8 +68,15 @@ settings.BluetoothAddDeviceBehavior = { |
| /** @private */ |
| deviceListChanged_: function() { |
| + var devices = this.$.devices; |
| + this.saveScroll(devices); |
| + this.unpairedDeviceList_ = this.deviceList.filter(function(device) { |
| + return !device.paired; |
| + }); |
|
Dan Beam
2017/01/24 06:15:18
can't we just make this do a diff instead?
iron-l
|
| this.updateScrollableContents(); |
| - if (this.itemWasFocused_ || !this.getUnpaired_().length) |
| + this.restoreScroll(devices); |
| + |
| + if (this.itemWasFocused_ || !this.unpairedDeviceList_.length) |
| return; |
| // If the iron-list is populated with at least one visible item then |
| // focus it. |
| @@ -72,26 +92,17 @@ settings.BluetoothAddDeviceBehavior = { |
| /** @private */ |
| selectedItemChanged_: function() { |
| - if (this.selectedItem) |
| - this.fire('device-event', {action: 'connect', device: this.selectedItem}); |
| - }, |
| - |
| - /** |
| - * @return {!Array<!chrome.bluetooth.Device>} |
| - * @private |
| - */ |
| - getUnpaired_: function() { |
| - return this.deviceList.filter(function(device) { |
| - return !device.paired; |
| - }); |
| + if (!this.selectedItem_) |
| + return; |
| + this.fire('device-event', {action: 'connect', device: this.selectedItem_}); |
| }, |
| /** |
| - * @return {boolean} True if deviceList contains any unpaired devices. |
| + * @return {boolean} |
| * @private |
| */ |
| - haveUnpaired_: function(deviceList) { |
| - return this.getUnpaired_().length > 0; |
| + haveUnpaired_: function() { |
| + return this.unpairedDeviceList_.length > 0; |
| }, |
| }; |