Skip to content

Commit

Permalink
bobi: update dist file
Browse files Browse the repository at this point in the history
  • Loading branch information
cbbfcd committed Dec 19, 2018
1 parent c80f47d commit 3fa6428
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 95 deletions.
85 changes: 54 additions & 31 deletions dist/store.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,59 @@

'use strict';

var storage = window.localStorage;
var storage = window.localStorage,
_inMemoryStorage = {},
_length = 0; // deal QuotaExceededError if user use incognito mode in browser

(function () {
function isSupported() {
var _KEY = '_Is_Incognit',
_VALUE = 'yes';

try {
storage.setItem(_KEY, _VALUE);
storage.removeItem(_KEY);
return true;
} catch (error) {
return false;
}
}

if (!isSupported()) {
storage.__proto__ = {
setItem: function setItem(key, value) {
_inMemoryStorage[key] = '' + value;

if (!_inMemoryStorage.hasOwnProperty(key)) {
_length++;
}
},
getItem: function getItem(key) {
if (key in _inMemoryStorage) {
return _inMemoryStorage[key];
}

return null;
},
removeItem: function removeItem(key) {
if (_inMemoryStorage.hasOwnProperty(key)) {
delete _inMemoryStorage[key];
_length--;
}
},
clear: function clear() {
_inMemoryStorage = {};
_length = 0;
},
length: function length() {
return _length;
},
key: function key(index) {
return Object.keys(_inMemoryStorage)[index] || null;
}
};
}
})();

function isJSON(obj) {
obj = JSON.stringify(obj);
Expand Down Expand Up @@ -44,36 +96,7 @@ function isFunction(value) {

function isArray(value) {
return Object.prototype.toString.call(value) === "[object Array]";
} // https://github.com/jaywcjlove/store.js/pull/8
// Error: QuotaExceededError


function dealIncognito(storage) {
var _KEY = '_Is_Incognit',
_VALUE = 'yes';

try {
storage.setItem(_KEY, _VALUE);
} catch (e) {
if (e.name === 'QuotaExceededError') {
var _nothing = function _nothing() {};

storage.__proto__ = {
setItem: _nothing,
getItem: _nothing,
removeItem: _nothing,
clear: _nothing
};
}
} finally {
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY);
}

return storage;
} // deal QuotaExceededError if user use incognito mode in browser


storage = dealIncognito(storage);
}

function Store() {
if (!(this instanceof Store)) {
Expand Down
2 changes: 1 addition & 1 deletion dist/store.common.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 54 additions & 31 deletions dist/store.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,59 @@
* Licensed under the MIT license.
*/

var storage = window.localStorage;
var storage = window.localStorage,
_inMemoryStorage = {},
_length = 0; // deal QuotaExceededError if user use incognito mode in browser

(function () {
function isSupported() {
var _KEY = '_Is_Incognit',
_VALUE = 'yes';

try {
storage.setItem(_KEY, _VALUE);
storage.removeItem(_KEY);
return true;
} catch (error) {
return false;
}
}

if (!isSupported()) {
storage.__proto__ = {
setItem: function setItem(key, value) {
_inMemoryStorage[key] = '' + value;

if (!_inMemoryStorage.hasOwnProperty(key)) {
_length++;
}
},
getItem: function getItem(key) {
if (key in _inMemoryStorage) {
return _inMemoryStorage[key];
}

return null;
},
removeItem: function removeItem(key) {
if (_inMemoryStorage.hasOwnProperty(key)) {
delete _inMemoryStorage[key];
_length--;
}
},
clear: function clear() {
_inMemoryStorage = {};
_length = 0;
},
length: function length() {
return _length;
},
key: function key(index) {
return Object.keys(_inMemoryStorage)[index] || null;
}
};
}
})();

function isJSON(obj) {
obj = JSON.stringify(obj);
Expand Down Expand Up @@ -42,36 +94,7 @@ function isFunction(value) {

function isArray(value) {
return Object.prototype.toString.call(value) === "[object Array]";
} // https://github.com/jaywcjlove/store.js/pull/8
// Error: QuotaExceededError


function dealIncognito(storage) {
var _KEY = '_Is_Incognit',
_VALUE = 'yes';

try {
storage.setItem(_KEY, _VALUE);
} catch (e) {
if (e.name === 'QuotaExceededError') {
var _nothing = function _nothing() {};

storage.__proto__ = {
setItem: _nothing,
getItem: _nothing,
removeItem: _nothing,
clear: _nothing
};
}
} finally {
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY);
}

return storage;
} // deal QuotaExceededError if user use incognito mode in browser


storage = dealIncognito(storage);
}

function Store() {
if (!(this instanceof Store)) {
Expand Down
85 changes: 54 additions & 31 deletions dist/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,59 @@
(global.store = factory());
}(this, (function () { 'use strict';

var storage = window.localStorage;
var storage = window.localStorage,
_inMemoryStorage = {},
_length = 0; // deal QuotaExceededError if user use incognito mode in browser

(function () {
function isSupported() {
var _KEY = '_Is_Incognit',
_VALUE = 'yes';

try {
storage.setItem(_KEY, _VALUE);
storage.removeItem(_KEY);
return true;
} catch (error) {
return false;
}
}

if (!isSupported()) {
storage.__proto__ = {
setItem: function setItem(key, value) {
_inMemoryStorage[key] = '' + value;

if (!_inMemoryStorage.hasOwnProperty(key)) {
_length++;
}
},
getItem: function getItem(key) {
if (key in _inMemoryStorage) {
return _inMemoryStorage[key];
}

return null;
},
removeItem: function removeItem(key) {
if (_inMemoryStorage.hasOwnProperty(key)) {
delete _inMemoryStorage[key];
_length--;
}
},
clear: function clear() {
_inMemoryStorage = {};
_length = 0;
},
length: function length() {
return _length;
},
key: function key(index) {
return Object.keys(_inMemoryStorage)[index] || null;
}
};
}
})();

function isJSON(obj) {
obj = JSON.stringify(obj);
Expand Down Expand Up @@ -48,36 +100,7 @@

function isArray(value) {
return Object.prototype.toString.call(value) === "[object Array]";
} // https://github.com/jaywcjlove/store.js/pull/8
// Error: QuotaExceededError


function dealIncognito(storage) {
var _KEY = '_Is_Incognit',
_VALUE = 'yes';

try {
storage.setItem(_KEY, _VALUE);
} catch (e) {
if (e.name === 'QuotaExceededError') {
var _nothing = function _nothing() {};

storage.__proto__ = {
setItem: _nothing,
getItem: _nothing,
removeItem: _nothing,
clear: _nothing
};
}
} finally {
if (storage.getItem(_KEY) === _VALUE) storage.removeItem(_KEY);
}

return storage;
} // deal QuotaExceededError if user use incognito mode in browser


storage = dealIncognito(storage);
}

function Store() {
if (!(this instanceof Store)) {
Expand Down
2 changes: 1 addition & 1 deletion dist/store.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3fa6428

Please sign in to comment.