瀏覽代碼

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

Ryan Chandler 4 年之前
父節點
當前提交
2ef872e9d3
共有 1 個文件被更改,包括 14 次插入4 次删除
  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!)
             }
         }