Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: ui/file_manager/audio_player/elements/track_list.js

Issue 984593002: Use Object.observe() instead of Polyfills (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/audio_player/elements/track_list.js
diff --git a/ui/file_manager/audio_player/elements/track_list.js b/ui/file_manager/audio_player/elements/track_list.js
index 353083d88bf56f5c53ccf59d7e12d5208c4e726d..0e4508aac9463e20fc0bfeb1e9785f7aaf8d97e2 100644
--- a/ui/file_manager/audio_player/elements/track_list.js
+++ b/ui/file_manager/audio_player/elements/track_list.js
@@ -11,13 +11,26 @@
* element is ready.
*/
ready: function() {
- this.tracksObserver_ = new ArrayObserver(
- this.tracks,
- this.tracksValueChanged_.bind(this));
+ this.observeTrackList();
window.addEventListener('resize', this.onWindowResize_.bind(this));
},
+ observeTrackList: function() {
+ // Unobserve the previous track list.
+ if (this.unobserveTrackList_)
+ this.unobserveTrackList_();
+
+ // Observe the new track list.
+ var observer = this.tracksValueChanged_.bind(this);
+ Array.observe(this.tracks, observer);
+
+ // Set the function to unobserve it.
+ this.unobserveTrackList_ = function(tracks, observer) {
+ Array.unobserve(tracks, observer);
+ }.bind(null, this.tracks, observer);
+ },
+
/**
* Registers handlers for changing of external variables
*/
@@ -101,9 +114,7 @@
// values are not null. Maybe it's a bug of Polymer.
// Re-register the observer of 'this.tracks'.
- this.tracksObserver_.close();
- this.tracksObserver_ = new ArrayObserver(this.tracks);
- this.tracksObserver_.open(this.tracksValueChanged_.bind(this));
+ this.observeTrackList();
if (this.tracks.length !== 0) {
// Restore the active track.
@@ -122,9 +133,9 @@
/**
* Invoked when the value in the 'tracks' is changed.
- * @param {Array.<Object>} splices The detail of the change.
+ * @param {Array.<Object>} changes The detail of the change.
*/
- tracksValueChanged_: function(splices) {
+ tracksValueChanged_: function(changes) {
if (this.tracks.length === 0)
this.currentTrackIndex = -1;
else
« no previous file with comments | « ui/file_manager/audio_player/elements/audio_player.js ('k') | ui/file_manager/audio_player/js/audio_player.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698