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

Side by Side Diff: ui/file_manager/audio_player/js/audio_player_model.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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global) { 5 (function(global) {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * List of values to be stored into the model. 9 * List of values to be stored into the model.
10 * @type {Object<string, *>} 10 * @type {Object<string, *>}
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 map(function(a) { 47 map(function(a) {
48 return STORAGE_PREFIX + a; 48 return STORAGE_PREFIX + a;
49 }); 49 });
50 50
51 chrome.storage.local.get(objectsToBeRead, function(result) { 51 chrome.storage.local.get(objectsToBeRead, function(result) {
52 for (var key in result) { 52 for (var key in result) {
53 // Strips the prefix. 53 // Strips the prefix.
54 model[key.substr(STORAGE_PREFIX.length)] = result[key]; 54 model[key.substr(STORAGE_PREFIX.length)] = result[key];
55 } 55 }
56 callback(); 56 callback();
57 }.bind(this)); 57 });
58 }; 58 };
59 59
60 /** 60 /**
61 * The model class for audio player. 61 * The model class for audio player.
62 * @constructor 62 * @constructor
63 */ 63 */
64 function AudioPlayerModel() { 64 function AudioPlayerModel() {
65 // Initializes values. 65 // Initializes values.
66 for (var key in VALUES) { 66 for (var key in VALUES) {
67 this[key] = VALUES[key]; 67 this[key] = VALUES[key];
68 } 68 }
69 Object.seal(this); 69 Object.seal(this);
70 70
71 // Restores the values from the storage 71 // Restores the values from the storage
72 loadModel(this, function() { 72 var target = this;
73 loadModel(target, function() {
73 // Installs observer to watch changes of the values. 74 // Installs observer to watch changes of the values.
74 var observer = new ObjectObserver(this); 75 Object.observe(target, function(changes) {
75 observer.open(function(added, removed, changed, getOldValueFn) { 76 saveModel(target);
76 saveModel(this); 77 });
77 }.bind(this)); 78 });
78 }.bind(this));
79 } 79 }
80 80
81 // Exports AudioPlayerModel class to the global. 81 // Exports AudioPlayerModel class to the global.
82 global.AudioPlayerModel = AudioPlayerModel; 82 global.AudioPlayerModel = AudioPlayerModel;
83 83
84 })(this || window); 84 })(this || window);
OLDNEW
« no previous file with comments | « ui/file_manager/audio_player/js/audio_player.js ('k') | ui/file_manager/audio_player/js/audio_player_scripts.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698