Browse Source

fix(persistence): wrap in try/catch for safari

Ryan Chandler 4 years ago
parent
commit
2ef872e9d3
1 changed files with 14 additions and 4 deletions
  1. 14 4
      src/index.js

+ 14 - 4
src/index.js

@@ -24,7 +24,13 @@ const Spruce = {
                 this.updateSubscribers()
 
                 this.disableReactivity = true
-                this.persisted.forEach(this.updateLocalStorage.bind(this))
+
+                try {
+                    this.persisted.forEach(this.updateLocalStorage.bind(this))    
+                } catch (e) {
+                    // Do nothing here (thanks Safari!)
+                }
+                
                 this.disableReactivity = false
             }
         })
@@ -46,10 +52,14 @@ const Spruce = {
 
     store(name, state, persist = false) {
         if (persist) {
-            this.stores[name] = this.retrieveFromLocalStorage(name, getMethods(state))
+            try {
+                this.stores[name] = this.retrieveFromLocalStorage(name, getMethods(state))
 
-            if (! this.persisted.includes(name)) {
-                this.persisted.push(name)
+                if (! this.persisted.includes(name)) {
+                    this.persisted.push(name)
+                }
+            } catch (e) {
+                // Do nothing here (thanks Safari!)
             }
         }