import Backbone from 'backbone';

export default Backbone.Model.extend({
  defaults: {
    checkLocal: true
  },

  /**
   * @private
   */
  store(data, clb) {
    this.checkStorageEnvironment();

    for (var key in data) localStorage.setItem(key, data[key]);

    if (typeof clb == 'function') {
      clb();
    }
  },

  /**
   * @private
   */
  load(keys, clb) {
    this.checkStorageEnvironment();
    var result = {};

    for (var i = 0, len = keys.length; i < len; i++) {
      var value = localStorage.getItem(keys[i]);
      if (value) result[keys[i]] = value;
    }

    if (typeof clb == 'function') {
      clb(result);
    }

    return result;
  },

  /**
   * @private
   */
  remove(keys) {
    this.checkStorageEnvironment();

    for (var i = 0, len = keys.length; i < len; i++)
      localStorage.removeItem(keys[i]);
  },

  /**
   * Check storage environment
   * @private
   * */
  checkStorageEnvironment() {
    if (this.get('checkLocal') && !localStorage)
      console.warn("Your browser doesn't support localStorage");
  }
});

@@ -1,23 +1,24 @@
 import 
-Backbone
+%7B Model %7D
  from 'b
@@ -26,16 +26,55 @@
 ckbone';
+%0Aimport %7B hasWin %7D from 'utils/mixins';
 %0A%0Aexport
@@ -86,17 +86,8 @@
 ult 
-Backbone.
 Mode
@@ -177,32 +177,43 @@
 re(data, clb
+ = () =%3E %7B%7D
 ) %7B%0A    
 this.checkSt
@@ -204,41 +204,33 @@
     
+if (
 this.
-checkStorageEnvironment();%0A%0A
+hasLocal()) %7B%0A  
     
@@ -234,19 +234,19 @@
    for (
-var
+let
  key in 
@@ -293,58 +293,33 @@
 %5D);%0A
-%0A
     
-if (typeof clb == 'function') %7B%0A     
+%7D%0A%0A    clb &&
  clb();%0A
     
@@ -314,22 +314,16 @@
  clb();%0A
-    %7D%0A
   %7D,%0A%0A  
@@ -366,70 +366,76 @@
  clb
-) %7B%0A    this.checkStorageEnvironment();%0A    var result = %7B%7D;%0A%0A
+ = () =%3E %7B%7D) %7B%0A    const result = %7B%7D;%0A%0A    if (this.hasLocal()) %7B%0A  
     
@@ -431,35 +431,35 @@
 )) %7B%0A      for (
-var
+let
  i = 0, len = ke
@@ -491,19 +491,23 @@
 %7B%0A      
-var
+  const
  value =
@@ -534,24 +534,26 @@
 m(keys%5Bi%5D);%0A
+  
       if (va
@@ -590,52 +590,29 @@
     
+  
 %7D%0A
-%0A    if (typeof clb == 'function') %7B%0A     
+    %7D%0A%0A    clb &&
  clb
@@ -620,22 +620,16 @@
 result);
-%0A    %7D
 %0A%0A    re
@@ -698,38 +698,36 @@
     
-this.checkStorageEnvironment()
+if (!this.hasLocal()) return
 ;%0A%0A 
@@ -738,11 +738,11 @@
 or (
-var
+let
  i =
@@ -889,35 +889,47 @@
 /%0A  
-checkStorageEnvironment() %7B
+hasLocal() %7B%0A    const win = hasWin();%0A
 %0A   
@@ -958,16 +958,25 @@
 cal') &&
+ (!win %7C%7C
  !localS
@@ -982,22 +982,32 @@
 Storage)
-%0A     
+) %7B%0A      win &&
  console
@@ -1058,16 +1058,60 @@
 rage%22);%0A
+      return false;%0A    %7D%0A%0A    return true;%0A
   %7D%0A%7D);%0A

Refactor local Storage