react-native-onyx 1.0.32 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web.development.js +57 -17
- package/dist/web.development.js.map +1 -1
- package/dist/web.min.js +1 -1
- package/dist/web.min.js.map +1 -1
- package/lib/Onyx.js +14 -5
- package/lib/OnyxCache.js +2 -0
- package/lib/SyncQueue.js +8 -0
- package/lib/storage/WebStorage.js +22 -4
- package/lib/storage/providers/AsyncStorage.js +1 -1
- package/lib/storage/providers/LocalForage.js +5 -2
- package/package.json +1 -1
package/dist/web.development.js
CHANGED
|
@@ -856,8 +856,7 @@ function notifyCollectionSubscribersOnNextTick(key, value) {
|
|
|
856
856
|
* @return {Promise}
|
|
857
857
|
*/
|
|
858
858
|
function remove(key) {
|
|
859
|
-
|
|
860
|
-
_OnyxCache.default.set(key, null);
|
|
859
|
+
_OnyxCache.default.drop(key);
|
|
861
860
|
notifySubscribersOnNextTick(key, null);
|
|
862
861
|
return _storage.default.removeItem(key);
|
|
863
862
|
}
|
|
@@ -904,8 +903,9 @@ function evictStorageAndRetry(error, onyxMethod) {for (var _len = arguments.leng
|
|
|
904
903
|
* @returns {Promise}
|
|
905
904
|
*/
|
|
906
905
|
function set(key, value) {
|
|
907
|
-
|
|
908
|
-
|
|
906
|
+
if (_underscore.default.isNull(value)) {
|
|
907
|
+
return remove(key);
|
|
908
|
+
}
|
|
909
909
|
|
|
910
910
|
// eslint-disable-next-line no-use-before-define
|
|
911
911
|
if (hasPendingMergeForKey(key)) {
|
|
@@ -1107,6 +1107,10 @@ function clear() {var keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1107
1107
|
var keyValuesToReset = [];
|
|
1108
1108
|
var defaultKeys = _underscore.default.keys(defaultKeyStates);
|
|
1109
1109
|
|
|
1110
|
+
// Get all the values for the keys that need to be preserved. These key/value pairs will be set
|
|
1111
|
+
// in Onyx after the database is cleared().
|
|
1112
|
+
var keyValuesToPreserve = _underscore.default.map(keysToPreserve, function (key) {return [key, _OnyxCache.default.getValue(key)];});
|
|
1113
|
+
|
|
1110
1114
|
// The only keys that should not be cleared are:
|
|
1111
1115
|
// 1. Anything specifically passed in keysToPreserve (because some keys like language preferences, offline
|
|
1112
1116
|
// status, or activeClients need to remain in Onyx even when signed out)
|
|
@@ -1159,7 +1163,11 @@ function clear() {var keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1159
1163
|
notifyCollectionSubscribersOnNextTick(key, value);
|
|
1160
1164
|
});
|
|
1161
1165
|
|
|
1162
|
-
|
|
1166
|
+
// Call clear() and make sure that the default key/values and the key/values from the parameter
|
|
1167
|
+
// are preserved in storage. This makes sure to always leave storage in a state that contains
|
|
1168
|
+
// all the default values and any additional values that we want to remain after the database is cleared.
|
|
1169
|
+
return _storage.default.clear().
|
|
1170
|
+
then(function () {return _storage.default.multiSet([].concat((0, _toConsumableArray2.default)(defaultKeyValuePairs), (0, _toConsumableArray2.default)(keyValuesToPreserve)));});
|
|
1163
1171
|
});
|
|
1164
1172
|
}
|
|
1165
1173
|
|
|
@@ -1351,6 +1359,7 @@ var Onyx = {
|
|
|
1351
1359
|
mergeCollection: mergeCollection,
|
|
1352
1360
|
update: update,
|
|
1353
1361
|
clear: clear,
|
|
1362
|
+
getAllKeys: getAllKeys,
|
|
1354
1363
|
init: init,
|
|
1355
1364
|
registerLogger: Logger.registerLogger,
|
|
1356
1365
|
addToEvictionBlockList: addToEvictionBlockList,
|
|
@@ -1513,6 +1522,8 @@ OnyxCache = /*#__PURE__*/function () {
|
|
|
1513
1522
|
*/ }, { key: "drop", value:
|
|
1514
1523
|
function drop(key) {
|
|
1515
1524
|
delete this.storageMap[key];
|
|
1525
|
+
this.storageKeys.delete(key);
|
|
1526
|
+
this.recentKeys.delete(key);
|
|
1516
1527
|
}
|
|
1517
1528
|
|
|
1518
1529
|
/**
|
|
@@ -1649,7 +1660,15 @@ SyncQueue = /*#__PURE__*/function () {
|
|
|
1649
1660
|
this.queue = [];
|
|
1650
1661
|
this.isProcessing = false;
|
|
1651
1662
|
this.run = run;
|
|
1652
|
-
}
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
/**
|
|
1666
|
+
* Stop the queue from being processed and clear out any existing tasks
|
|
1667
|
+
*/(0, _createClass2.default)(SyncQueue, [{ key: "abort", value:
|
|
1668
|
+
function abort() {
|
|
1669
|
+
this.queue = [];
|
|
1670
|
+
this.isProcessing = false;
|
|
1671
|
+
} }, { key: "process", value:
|
|
1653
1672
|
|
|
1654
1673
|
function process() {var _this = this;
|
|
1655
1674
|
if (this.isProcessing || this.queue.length === 0) {
|
|
@@ -1874,12 +1893,17 @@ function resetMetrics() {}
|
|
|
1874
1893
|
\***********************************/
|
|
1875
1894
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1876
1895
|
|
|
1877
|
-
var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js");Object.defineProperty(exports, "__esModule", ({ value: true }));exports["default"] = void 0;
|
|
1878
|
-
var _LocalForage = _interopRequireDefault(__webpack_require__(/*! ./providers/LocalForage */ "./lib/storage/providers/LocalForage.js"));
|
|
1896
|
+
var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js");Object.defineProperty(exports, "__esModule", ({ value: true }));exports["default"] = void 0;
|
|
1879
1897
|
|
|
1880
|
-
var SYNC_ONYX = 'SYNC_ONYX';
|
|
1881
1898
|
|
|
1882
|
-
|
|
1899
|
+
|
|
1900
|
+
|
|
1901
|
+
var _underscore = _interopRequireDefault(__webpack_require__(/*! underscore */ "underscore"));
|
|
1902
|
+
var _LocalForage = _interopRequireDefault(__webpack_require__(/*! ./providers/LocalForage */ "./lib/storage/providers/LocalForage.js")); /**
|
|
1903
|
+
* This file is here to wrap LocalForage with a layer that provides data-changed events like the ones that exist
|
|
1904
|
+
* when using LocalStorage APIs in the browser. These events are great because multiple tabs can listen for when
|
|
1905
|
+
* data changes and then stay up-to-date with everything happening in Onyx.
|
|
1906
|
+
*/var SYNC_ONYX = 'SYNC_ONYX'; /**
|
|
1883
1907
|
* Raise an event thorough `localStorage` to let other tabs know a value changed
|
|
1884
1908
|
* @param {String} onyxKey
|
|
1885
1909
|
*/
|
|
@@ -1894,7 +1918,7 @@ _LocalForage.default, {
|
|
|
1894
1918
|
/**
|
|
1895
1919
|
* @param {Function} onStorageKeyChanged Storage synchronization mechanism keeping all opened tabs in sync
|
|
1896
1920
|
*/
|
|
1897
|
-
keepInstancesSync: function keepInstancesSync(onStorageKeyChanged) {
|
|
1921
|
+
keepInstancesSync: function keepInstancesSync(onStorageKeyChanged) {
|
|
1898
1922
|
// Override set, remove and clear to raise storage events that we intercept in other tabs
|
|
1899
1923
|
this.setItem = function (key, value) {return _LocalForage.default.setItem(key, value).
|
|
1900
1924
|
then(function () {return raiseStorageSyncEvent(key);});};
|
|
@@ -1903,10 +1927,23 @@ _LocalForage.default, {
|
|
|
1903
1927
|
then(function () {return raiseStorageSyncEvent(key);});};
|
|
1904
1928
|
|
|
1905
1929
|
// If we just call Storage.clear other tabs will have no idea which keys were available previously
|
|
1906
|
-
// so that they can call keysChanged for them. That's why we iterate and
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1930
|
+
// so that they can call keysChanged for them. That's why we iterate over every key and raise a storage sync
|
|
1931
|
+
// event for each one
|
|
1932
|
+
this.clear = function () {
|
|
1933
|
+
var allKeys;
|
|
1934
|
+
|
|
1935
|
+
// They keys must be retreived before storage is cleared or else the list of keys would be empty
|
|
1936
|
+
return _LocalForage.default.getAllKeys().
|
|
1937
|
+
then(function (keys) {
|
|
1938
|
+
allKeys = keys;
|
|
1939
|
+
}).
|
|
1940
|
+
then(function () {return _LocalForage.default.clear();}).
|
|
1941
|
+
then(function () {
|
|
1942
|
+
// Now that storage is cleared, the storage sync event can happen which is a more atomic action
|
|
1943
|
+
// for other browser tabs
|
|
1944
|
+
_underscore.default.each(allKeys, raiseStorageSyncEvent);
|
|
1945
|
+
});
|
|
1946
|
+
};
|
|
1910
1947
|
|
|
1911
1948
|
// This listener will only be triggered by events coming from other tabs
|
|
1912
1949
|
__webpack_require__.g.addEventListener('storage', function (event) {
|
|
@@ -2021,10 +2058,13 @@ var provider = {
|
|
|
2021
2058
|
},
|
|
2022
2059
|
|
|
2023
2060
|
/**
|
|
2024
|
-
* Clear
|
|
2061
|
+
* Clear everything from storage and also stops the SyncQueue from adding anything more to storage
|
|
2025
2062
|
* @returns {Promise<void>}
|
|
2026
2063
|
*/
|
|
2027
|
-
clear:
|
|
2064
|
+
clear: function clear() {
|
|
2065
|
+
this.setItemQueue.abort();
|
|
2066
|
+
return _localforage.default.clear();
|
|
2067
|
+
},
|
|
2028
2068
|
|
|
2029
2069
|
/**
|
|
2030
2070
|
* Returns all keys available in storage
|