diff options
| author | Stephen Blott | 2017-10-29 12:08:51 +0000 |
|---|---|---|
| committer | Stephen Blott | 2017-10-29 12:08:51 +0000 |
| commit | 7f51eb26f5a5536ba81d4dea3cf92cc30087ddc7 (patch) | |
| tree | d72482729a8cb5d439aea5a623133b9dd1d7cf79 /pages | |
| parent | 1660d1fce8ae357e95ebb7f525be992290715f8f (diff) | |
| download | vimium-7f51eb26f5a5536ba81d4dea3cf92cc30087ddc7.tar.bz2 | |
Refacator restore/save code.
Some the long-reach code here is ugly. Things are too spread around.
This refactors the code called on "save" to a callback. Thus, the code
related to backup and restore is localised.
Diffstat (limited to 'pages')
| -rw-r--r-- | pages/options.coffee | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/pages/options.coffee b/pages/options.coffee index 091c2fd0..86b6122d 100644 --- a/pages/options.coffee +++ b/pages/options.coffee @@ -1,7 +1,6 @@ $ = (id) -> document.getElementById id bgExclusions = chrome.extension.getBackgroundPage().Exclusions -restoreSettingsVersion = null # We have to use Settings from the background page here (not Settings, directly) to avoid a race condition for # the page popup. Specifically, we must ensure that the settings have been updated on the background page @@ -40,17 +39,14 @@ class Option bgSettings.clear @field @fetch() + @onSaveCallbacks: [] + @onSave: (callback) -> + @onSaveCallbacks.push callback + # Static method. @saveOptions: -> Option.all.map (option) -> option.save() - # If we're restoring a backup, then restore the backed up settingsVersion. - if restoreSettingsVersion? - bgSettings.set "settingsVersion", restoreSettingsVersion - restoreSettingsVersion = null - # Reset the restore-backup input. - $("chooseFile").value = "" - # We need to apply migrations in case we are restoring an old backup. - bgSettings.applyMigrations() + callback() for callback in @onSaveCallbacks # Abstract method; only implemented in sub-classes. # Populate the option's DOM element (@element) with the setting's current value. @@ -337,6 +333,8 @@ document.addEventListener "DOMContentLoaded", -> # # Backup and restore. "?" is for the tests." DomUtils?.documentReady -> + restoreSettingsVersion = null + populateBackupLinkUrl = -> backup = settingsVersion: bgSettings.get "settingsVersion" for option in Option.all @@ -368,6 +366,16 @@ DomUtils?.documentReady -> option.populateElement backup[option.field] option.onUpdated() + Option.onSave -> + # If we're restoring a backup, then restore the backed up settingsVersion. + if restoreSettingsVersion? + bgSettings.set "settingsVersion", restoreSettingsVersion + restoreSettingsVersion = null + # Reset the restore-backup input. + $("chooseFile").value = "" + # We need to apply migrations in case we are restoring an old backup. + bgSettings.applyMigrations() + # Exported for tests. root = exports ? window extend root, {Options, isVimiumOptionsPage: true} |
