Skip to content

Commit

Permalink
Don't store defaults, they'll be merged in the getter
Browse files Browse the repository at this point in the history
Closes #32
  • Loading branch information
fregante committed Jul 25, 2019
1 parent 05aa6a4 commit f66da00
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ class OptionsSync<TOptions extends Options> {
});
});

return this._parseNumbers(keys[this.storageName]);
return this._parseNumbers({
...this.defaults,
...keys[this.storageName]
});
}

/**
Expand All @@ -134,6 +137,13 @@ class OptionsSync<TOptions extends Options> {
@param newOptions - A map of default options as strings or booleans. The keys will have to match the form fields' `name` attributes.
*/
async setAll(newOptions: TOptions): Promise<void> {
// Don't store defaults, they'll be merged at runtime
for (const [key, value] of Object.entries(newOptions)) {
if (this.defaults[key] === value) {
delete newOptions[key];
}
}

return new Promise((resolve, reject) => {
chrome.storage.sync.set({
[this.storageName]: newOptions
Expand Down

0 comments on commit f66da00

Please sign in to comment.