Skip to content

Commit

Permalink
Check if localStorage exists before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
navdeepsinghkhalsa committed Apr 21, 2017
1 parent 600e3c5 commit 937a1d0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions www/js/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class Store {

// Write preferences to localStorage for viewers
this.combined = ldDefaultsDeep(this.data, this.defaults);
window.localStorage.setItem('prefs', JSON.stringify(this.combined.userPrefs));
if (typeof localStorage === 'object') {
localStorage.setItem('prefs', JSON.stringify(this.combined.userPrefs));
}
}

// This will just return the property on the `data` object
Expand All @@ -53,7 +55,9 @@ class Store {
fs.writeFileSync(this.path, JSON.stringify(this.data));

// Update localStorage for viewer
window.localStorage.setItem('prefs', JSON.stringify(this.combined.userPrefs));
if (typeof localStorage === 'object') {
localStorage.setItem('prefs', JSON.stringify(this.combined.userPrefs));
}
}

delete(key) {
Expand All @@ -63,7 +67,9 @@ class Store {
fs.writeFileSync(this.path, JSON.stringify(this.data));

// Update localStorage for viewer
window.localStorage.setItem('prefs', JSON.stringify(this.combined.userPrefs));
if (typeof localStorage === 'object') {
localStorage.setItem('prefs', JSON.stringify(this.combined.userPrefs));
}
}
}

Expand Down

0 comments on commit 937a1d0

Please sign in to comment.