Chromium Code Reviews| Index: ui/file_manager/audio_player/js/audio_player_model.js |
| diff --git a/ui/file_manager/audio_player/js/audio_player_model.js b/ui/file_manager/audio_player/js/audio_player_model.js |
| index 3927b2a9c687188f81bf03b59bcb327fc2db107f..6bb1616f08302e3ef827448705af728e9e74e354 100644 |
| --- a/ui/file_manager/audio_player/js/audio_player_model.js |
| +++ b/ui/file_manager/audio_player/js/audio_player_model.js |
| @@ -2,20 +2,29 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -(function(global) { |
| +/** |
| + * The model class for audio player. |
| + * @constructor |
| + */ |
| +function AudioPlayerModel() { |
| 'use strict'; |
| /** |
| * List of values to be stored into the model. |
| - * @type {Object<string, *>} |
| + * @type {!Object<string, *>} |
| * @const |
| */ |
| - var VALUES = Object.freeze({ |
| - shuffle: false, |
| - repeat: false, |
| - volume: 100, |
| - expanded: false, |
| - }); |
| + var VALUES = Object.freeze( |
| + /** |
| + * They will be used as properties of AudioPlayerModel. |
| + * @lends {AudioPlayerModel.prototype} |
| + */ |
| + { |
| + shuffle: false, |
| + repeat: false, |
| + volume: 100, |
| + expanded: false, |
| + }); |
| /** |
| * Prefix of the stored values in the storage. |
| @@ -23,15 +32,15 @@ |
| */ |
| var STORAGE_PREFIX = 'audioplayer-'; |
| - /** |
| - * Save the values in the model into the storage. |
| - * @param {AudioPlayerModel} model The model. |
| - */ |
| - function saveModel(model) { |
| - var objectToBeSaved = {}; |
| - for (var key in VALUES) { |
| - objectToBeSaved[STORAGE_PREFIX + key] = model[key]; |
| - } |
| + /** |
| + * Save the values in the model into the storage. |
| + * @param {AudioPlayerModel} model The model. |
| + */ |
| + function saveModel(model) { |
| + var objectToBeSaved = {}; |
|
fukino
2015/03/17 06:32:44
nit: incorrect indentation
yoshiki
2015/03/17 08:28:06
Done.
|
| + for (var key in VALUES) { |
| + objectToBeSaved[STORAGE_PREFIX + key] = model[key]; |
| + } |
| chrome.storage.local.set(objectToBeSaved); |
| }; |
| @@ -54,31 +63,21 @@ |
| model[key.substr(STORAGE_PREFIX.length)] = result[key]; |
| } |
| callback(); |
| - }); |
| + }.bind(this)); |
|
fukino
2015/03/17 06:32:44
nit: is this bind() necessary?
yoshiki
2015/03/17 08:28:06
Done.
|
| }; |
| - /** |
| - * The model class for audio player. |
| - * @constructor |
| - */ |
| - function AudioPlayerModel() { |
| - // Initializes values. |
| - for (var key in VALUES) { |
| - this[key] = VALUES[key]; |
| - } |
| - Object.seal(this); |
| - |
| - // Restores the values from the storage |
| - var target = this; |
| - loadModel(target, function() { |
| - // Installs observer to watch changes of the values. |
| - Object.observe(target, function(changes) { |
| - saveModel(target); |
| - }); |
| - }); |
| + // Initializes values. |
| + for (var key in VALUES) { |
| + this[key] = VALUES[key]; |
| } |
| + Object.seal(this); |
| - // Exports AudioPlayerModel class to the global. |
| - global.AudioPlayerModel = AudioPlayerModel; |
| - |
| -})(this || window); |
| + // Restores the values from the storage |
| + var target = this; |
| + loadModel(target, function() { |
| + // Installs observer to watch changes of the values. |
| + Object.observe(target, function(changes) { |
| + saveModel(target); |
| + }); |
| + }); |
| +} |