react-native-onyx 1.0.33 → 1.0.35
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 +50 -13
- 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 +9 -1
- 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/lib/storage/providers/SQLiteStorage.js +1 -1
- package/package.json +1 -1
package/dist/web.development.js
CHANGED
|
@@ -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
|
|
|
@@ -1652,7 +1660,15 @@ SyncQueue = /*#__PURE__*/function () {
|
|
|
1652
1660
|
this.queue = [];
|
|
1653
1661
|
this.isProcessing = false;
|
|
1654
1662
|
this.run = run;
|
|
1655
|
-
}
|
|
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:
|
|
1656
1672
|
|
|
1657
1673
|
function process() {var _this = this;
|
|
1658
1674
|
if (this.isProcessing || this.queue.length === 0) {
|
|
@@ -1877,12 +1893,17 @@ function resetMetrics() {}
|
|
|
1877
1893
|
\***********************************/
|
|
1878
1894
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
1879
1895
|
|
|
1880
|
-
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;
|
|
1881
|
-
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;
|
|
1882
1897
|
|
|
1883
|
-
var SYNC_ONYX = 'SYNC_ONYX';
|
|
1884
1898
|
|
|
1885
|
-
|
|
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'; /**
|
|
1886
1907
|
* Raise an event thorough `localStorage` to let other tabs know a value changed
|
|
1887
1908
|
* @param {String} onyxKey
|
|
1888
1909
|
*/
|
|
@@ -1897,7 +1918,7 @@ _LocalForage.default, {
|
|
|
1897
1918
|
/**
|
|
1898
1919
|
* @param {Function} onStorageKeyChanged Storage synchronization mechanism keeping all opened tabs in sync
|
|
1899
1920
|
*/
|
|
1900
|
-
keepInstancesSync: function keepInstancesSync(onStorageKeyChanged) {
|
|
1921
|
+
keepInstancesSync: function keepInstancesSync(onStorageKeyChanged) {
|
|
1901
1922
|
// Override set, remove and clear to raise storage events that we intercept in other tabs
|
|
1902
1923
|
this.setItem = function (key, value) {return _LocalForage.default.setItem(key, value).
|
|
1903
1924
|
then(function () {return raiseStorageSyncEvent(key);});};
|
|
@@ -1906,10 +1927,23 @@ _LocalForage.default, {
|
|
|
1906
1927
|
then(function () {return raiseStorageSyncEvent(key);});};
|
|
1907
1928
|
|
|
1908
1929
|
// If we just call Storage.clear other tabs will have no idea which keys were available previously
|
|
1909
|
-
// so that they can call keysChanged for them. That's why we iterate and
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
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
|
+
};
|
|
1913
1947
|
|
|
1914
1948
|
// This listener will only be triggered by events coming from other tabs
|
|
1915
1949
|
__webpack_require__.g.addEventListener('storage', function (event) {
|
|
@@ -2024,10 +2058,13 @@ var provider = {
|
|
|
2024
2058
|
},
|
|
2025
2059
|
|
|
2026
2060
|
/**
|
|
2027
|
-
* Clear
|
|
2061
|
+
* Clear everything from storage and also stops the SyncQueue from adding anything more to storage
|
|
2028
2062
|
* @returns {Promise<void>}
|
|
2029
2063
|
*/
|
|
2030
|
-
clear:
|
|
2064
|
+
clear: function clear() {
|
|
2065
|
+
this.setItemQueue.abort();
|
|
2066
|
+
return _localforage.default.clear();
|
|
2067
|
+
},
|
|
2031
2068
|
|
|
2032
2069
|
/**
|
|
2033
2070
|
* Returns all keys available in storage
|