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

Unified Diff: chrome/browser/resources/settings/prefs/prefs_types.js

Issue 1357183002: MD-Settings: convert cr-settings-prefs to a singleton model (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unnecessary parens Created 5 years, 3 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: chrome/browser/resources/settings/prefs/prefs_types.js
diff --git a/chrome/browser/resources/settings/prefs/prefs_types.js b/chrome/browser/resources/settings/prefs/prefs_types.js
index 3ac53ba967be5c3193a1b6b8a7087894c368ba4d..f8b1ad6a614001b0a89c3cec4a9583f2c840a774 100644
--- a/chrome/browser/resources/settings/prefs/prefs_types.js
+++ b/chrome/browser/resources/settings/prefs/prefs_types.js
@@ -6,22 +6,37 @@
* @fileoverview Types for CrSettingsPrefsElement.
*/
-/** @type {{INITIALIZED: string, isInitialized: boolean}} */
-var CrSettingsPrefs;
-
-// TODO(michaelpg): provide a Promise for initialization.
-if (CrSettingsPrefs === undefined) {
- CrSettingsPrefs = {
+/**
+ * Global state for prefs status.
+ */
+var CrSettingsPrefs = (function() {
+ var CrSettingsPrefsInternal = {
/**
- * The name of the event fired when prefs have been fetched and initialized.
- * @const {string}
+ * Resolves the CrSettingsPrefs.initialized promise.
*/
- INITIALIZED: 'cr-settings-prefs-initialized',
+ setInitialized: function() {
+ /** @public {boolean} */
+ CrSettingsPrefsInternal.isInitialized = true;
+ CrSettingsPrefsInternal.resolve_();
+ },
/**
- * Global boolean set to true when all settings have been initialized.
- * @type {boolean}
+ * Called to set up the promise and resolve methods, and to restore
+ * state for testing.
*/
- isInitialized: false,
+ reset: function() {
Dan Beam 2015/09/22 06:12:31 nit: resetForTesting, maybe?
michaelpg 2015/09/22 21:38:37 Done.
+ CrSettingsPrefsInternal.isInitialized = false;
+ /**
+ * Promise to be resolved when all settings have been initialized.
+ * @type {!Promise}
+ */
+ CrSettingsPrefsInternal.initialized = new Promise(function(resolve) {
+ CrSettingsPrefsInternal.resolve_ = resolve;
+ });
+ },
};
-}
+
+ CrSettingsPrefsInternal.reset();
+
+ return CrSettingsPrefsInternal;
+})();

Powered by Google App Engine
This is Rietveld 408576698