react-native-onyx 1.0.38 → 1.0.40
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 +78 -53
- 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 +34 -44
- package/lib/storage/WebStorage.js +9 -0
- package/lib/storage/__mocks__/index.js +78 -0
- package/lib/storage/providers/LocalForage.js +13 -0
- package/lib/storage/providers/SQLiteStorage.js +12 -0
- package/package.json +5 -6
- package/lib/storage/__mocks__/index.native.js +0 -8
- package/lib/storage/providers/AsyncStorage.js +0 -83
- package/lib/storage/providers/__mocks__/SQLiteStorage.js +0 -3
package/dist/web.development.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
2
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
-
module.exports = factory(require("underscore"), require("expensify-common/lib/str"), require("fast-equals"), require("lodash/get"), require("localforage"), require("lodash/transform"), require("react"));
|
|
3
|
+
module.exports = factory(require("underscore"), require("expensify-common/lib/str"), require("fast-equals"), require("lodash/get"), require("localforage"), require("localforage-removeitems"), require("lodash/transform"), require("react"));
|
|
4
4
|
else if(typeof define === 'function' && define.amd)
|
|
5
|
-
define(["underscore", "expensify-common/lib/str", "fast-equals", "lodash/get", "localforage", "lodash/transform", "react"], factory);
|
|
5
|
+
define(["underscore", "expensify-common/lib/str", "fast-equals", "lodash/get", "localforage", "localforage-removeitems", "lodash/transform", "react"], factory);
|
|
6
6
|
else if(typeof exports === 'object')
|
|
7
|
-
exports["react-native-onyx/web"] = factory(require("underscore"), require("expensify-common/lib/str"), require("fast-equals"), require("lodash/get"), require("localforage"), require("lodash/transform"), require("react"));
|
|
7
|
+
exports["react-native-onyx/web"] = factory(require("underscore"), require("expensify-common/lib/str"), require("fast-equals"), require("lodash/get"), require("localforage"), require("localforage-removeitems"), require("lodash/transform"), require("react"));
|
|
8
8
|
else
|
|
9
|
-
root["react-native-onyx/web"] = factory(root["underscore"], root["expensify-common/lib/str"], root["fast-equals"], root["lodash/get"], root["localforage"], root["lodash/transform"], root["react"]);
|
|
10
|
-
})(self, (__WEBPACK_EXTERNAL_MODULE_underscore__, __WEBPACK_EXTERNAL_MODULE_expensify_common_lib_str__, __WEBPACK_EXTERNAL_MODULE_fast_equals__, __WEBPACK_EXTERNAL_MODULE_lodash_get__, __WEBPACK_EXTERNAL_MODULE_localforage__, __WEBPACK_EXTERNAL_MODULE_lodash_transform__, __WEBPACK_EXTERNAL_MODULE_react__) => {
|
|
9
|
+
root["react-native-onyx/web"] = factory(root["underscore"], root["expensify-common/lib/str"], root["fast-equals"], root["lodash/get"], root["localforage"], root["localforage-removeitems"], root["lodash/transform"], root["react"]);
|
|
10
|
+
})(self, (__WEBPACK_EXTERNAL_MODULE_underscore__, __WEBPACK_EXTERNAL_MODULE_expensify_common_lib_str__, __WEBPACK_EXTERNAL_MODULE_fast_equals__, __WEBPACK_EXTERNAL_MODULE_lodash_get__, __WEBPACK_EXTERNAL_MODULE_localforage__, __WEBPACK_EXTERNAL_MODULE_localforage_removeitems__, __WEBPACK_EXTERNAL_MODULE_lodash_transform__, __WEBPACK_EXTERNAL_MODULE_react__) => {
|
|
11
11
|
return /******/ (() => { // webpackBootstrap
|
|
12
12
|
/******/ var __webpack_modules__ = ({
|
|
13
13
|
|
|
@@ -1132,55 +1132,46 @@ function initializeWithDefaultKeyStates() {
|
|
|
1132
1132
|
function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1133
1133
|
return getAllKeys().
|
|
1134
1134
|
then((keys) => {
|
|
1135
|
-
const
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
// Get all the values for the keys that need to be preserved. These key/value pairs will be set
|
|
1139
|
-
// in Onyx after the database is cleared().
|
|
1140
|
-
const keyValuesToPreserve = underscore__WEBPACK_IMPORTED_MODULE_0___default().map(keysToPreserve, (key) => [key, _OnyxCache__WEBPACK_IMPORTED_MODULE_5__["default"].getValue(key)]);
|
|
1135
|
+
const keysToBeClearedFromStorage = [];
|
|
1136
|
+
const keyValuesToResetAsCollection = {};
|
|
1137
|
+
const keyValuesToResetIndividually = {};
|
|
1141
1138
|
|
|
1142
1139
|
// The only keys that should not be cleared are:
|
|
1143
1140
|
// 1. Anything specifically passed in keysToPreserve (because some keys like language preferences, offline
|
|
1144
1141
|
// status, or activeClients need to remain in Onyx even when signed out)
|
|
1145
1142
|
// 2. Any keys with a default state (because they need to remain in Onyx as their default, and setting them
|
|
1146
1143
|
// to null would cause unknown behavior)
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
underscore__WEBPACK_IMPORTED_MODULE_0___default().each(keyValuesToReset, (keyValue) => {
|
|
1170
|
-
const key = keyValue[0];
|
|
1171
|
-
const value = keyValue[1];
|
|
1172
|
-
_OnyxCache__WEBPACK_IMPORTED_MODULE_5__["default"].set(key, value);
|
|
1173
|
-
|
|
1174
|
-
const collectionKey = key.substring(0, key.indexOf('_') + 1);
|
|
1175
|
-
if (collectionKey) {
|
|
1176
|
-
if (!keyValuesToResetAsCollection[collectionKey]) {
|
|
1177
|
-
keyValuesToResetAsCollection[collectionKey] = {};
|
|
1144
|
+
underscore__WEBPACK_IMPORTED_MODULE_0___default().each(keys, (key) => {
|
|
1145
|
+
const isKeyToPreserve = underscore__WEBPACK_IMPORTED_MODULE_0___default().contains(keysToPreserve, key);
|
|
1146
|
+
const isDefaultKey = underscore__WEBPACK_IMPORTED_MODULE_0___default().has(defaultKeyStates, key);
|
|
1147
|
+
|
|
1148
|
+
// If the key is being removed or reset to default:
|
|
1149
|
+
// 1. Update it in the cache
|
|
1150
|
+
// 2. Figure out whether it is a collection key or not,
|
|
1151
|
+
// since collection key subscribers need to be updated differently
|
|
1152
|
+
if (!isKeyToPreserve) {
|
|
1153
|
+
const oldValue = _OnyxCache__WEBPACK_IMPORTED_MODULE_5__["default"].getValue(key);
|
|
1154
|
+
const newValue = underscore__WEBPACK_IMPORTED_MODULE_0___default().get(defaultKeyStates, key, null);
|
|
1155
|
+
if (newValue !== oldValue) {
|
|
1156
|
+
_OnyxCache__WEBPACK_IMPORTED_MODULE_5__["default"].set(key, newValue);
|
|
1157
|
+
const collectionKey = key.substring(0, key.indexOf('_') + 1);
|
|
1158
|
+
if (collectionKey) {
|
|
1159
|
+
if (!keyValuesToResetAsCollection[collectionKey]) {
|
|
1160
|
+
keyValuesToResetAsCollection[collectionKey] = {};
|
|
1161
|
+
}
|
|
1162
|
+
keyValuesToResetAsCollection[collectionKey][key] = newValue;
|
|
1163
|
+
} else {
|
|
1164
|
+
keyValuesToResetIndividually[key] = newValue;
|
|
1165
|
+
}
|
|
1178
1166
|
}
|
|
1179
|
-
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
if (isKeyToPreserve || isDefaultKey) {
|
|
1180
1170
|
return;
|
|
1181
1171
|
}
|
|
1182
1172
|
|
|
1183
|
-
|
|
1173
|
+
// If it isn't preserved and doesn't have a default, we'll remove it
|
|
1174
|
+
keysToBeClearedFromStorage.push(key);
|
|
1184
1175
|
});
|
|
1185
1176
|
|
|
1186
1177
|
// Notify the subscribers for each key/value group so they can receive the new values
|
|
@@ -1191,11 +1182,10 @@ function clear() {let keysToPreserve = arguments.length > 0 && arguments[0] !==
|
|
|
1191
1182
|
notifyCollectionSubscribersOnNextTick(key, value);
|
|
1192
1183
|
});
|
|
1193
1184
|
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
//
|
|
1197
|
-
return _storage__WEBPACK_IMPORTED_MODULE_6__["default"].
|
|
1198
|
-
then(() => _storage__WEBPACK_IMPORTED_MODULE_6__["default"].multiSet([...defaultKeyValuePairs, ...keyValuesToPreserve]));
|
|
1185
|
+
const defaultKeyValuePairs = underscore__WEBPACK_IMPORTED_MODULE_0___default().pairs(underscore__WEBPACK_IMPORTED_MODULE_0___default().omit(defaultKeyStates, keysToPreserve));
|
|
1186
|
+
|
|
1187
|
+
// Remove only the items that we want cleared from storage, and reset others to default
|
|
1188
|
+
return _storage__WEBPACK_IMPORTED_MODULE_6__["default"].removeItems(keysToBeClearedFromStorage).then(() => _storage__WEBPACK_IMPORTED_MODULE_6__["default"].multiSet(defaultKeyValuePairs));
|
|
1199
1189
|
});
|
|
1200
1190
|
}
|
|
1201
1191
|
|
|
@@ -1996,6 +1986,12 @@ function raiseStorageSyncEvent(onyxKey) {
|
|
|
1996
1986
|
__webpack_require__.g.localStorage.removeItem(SYNC_ONYX, onyxKey);
|
|
1997
1987
|
}
|
|
1998
1988
|
|
|
1989
|
+
function raiseStorageSyncManyKeysEvent(onyxKeys) {
|
|
1990
|
+
underscore__WEBPACK_IMPORTED_MODULE_0___default().each(onyxKeys, (onyxKey) => {
|
|
1991
|
+
raiseStorageSyncEvent(onyxKey);
|
|
1992
|
+
});
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1999
1995
|
const webStorage = {
|
|
2000
1996
|
..._providers_LocalForage__WEBPACK_IMPORTED_MODULE_1__["default"],
|
|
2001
1997
|
|
|
@@ -2010,6 +2006,9 @@ const webStorage = {
|
|
|
2010
2006
|
this.removeItem = (key) => _providers_LocalForage__WEBPACK_IMPORTED_MODULE_1__["default"].removeItem(key).
|
|
2011
2007
|
then(() => raiseStorageSyncEvent(key));
|
|
2012
2008
|
|
|
2009
|
+
this.removeItems = (keys) => _providers_LocalForage__WEBPACK_IMPORTED_MODULE_1__["default"].removeItems(keys).
|
|
2010
|
+
then(() => raiseStorageSyncManyKeysEvent(keys));
|
|
2011
|
+
|
|
2013
2012
|
// If we just call Storage.clear other tabs will have no idea which keys were available previously
|
|
2014
2013
|
// so that they can call keysChanged for them. That's why we iterate over every key and raise a storage sync
|
|
2015
2014
|
// event for each one
|
|
@@ -2080,8 +2079,10 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2080
2079
|
/* harmony import */ var localforage__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(localforage__WEBPACK_IMPORTED_MODULE_0__);
|
|
2081
2080
|
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! underscore */ "underscore");
|
|
2082
2081
|
/* harmony import */ var underscore__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(underscore__WEBPACK_IMPORTED_MODULE_1__);
|
|
2083
|
-
/* harmony import */ var
|
|
2084
|
-
/* harmony import */ var
|
|
2082
|
+
/* harmony import */ var localforage_removeitems__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! localforage-removeitems */ "localforage-removeitems");
|
|
2083
|
+
/* harmony import */ var localforage_removeitems__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(localforage_removeitems__WEBPACK_IMPORTED_MODULE_2__);
|
|
2084
|
+
/* harmony import */ var _SyncQueue__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../SyncQueue */ "./lib/SyncQueue.js");
|
|
2085
|
+
/* harmony import */ var _fastMerge__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../fastMerge */ "./lib/fastMerge.js");
|
|
2085
2086
|
/**
|
|
2086
2087
|
* @file
|
|
2087
2088
|
* The storage provider based on localforage allows us to store most anything in its
|
|
@@ -2093,6 +2094,9 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
2093
2094
|
|
|
2094
2095
|
|
|
2095
2096
|
|
|
2097
|
+
|
|
2098
|
+
(0,localforage_removeitems__WEBPACK_IMPORTED_MODULE_2__.extendPrototype)((localforage__WEBPACK_IMPORTED_MODULE_0___default()));
|
|
2099
|
+
|
|
2096
2100
|
localforage__WEBPACK_IMPORTED_MODULE_0___default().config({
|
|
2097
2101
|
name: 'OnyxDB'
|
|
2098
2102
|
});
|
|
@@ -2103,7 +2107,7 @@ const provider = {
|
|
|
2103
2107
|
* So, we are slowing this process down by waiting until one write is complete before moving on
|
|
2104
2108
|
* to the next.
|
|
2105
2109
|
*/
|
|
2106
|
-
setItemQueue: new
|
|
2110
|
+
setItemQueue: new _SyncQueue__WEBPACK_IMPORTED_MODULE_3__["default"]((_ref) => {let { key, value, shouldMerge } = _ref;
|
|
2107
2111
|
if (shouldMerge) {
|
|
2108
2112
|
return localforage__WEBPACK_IMPORTED_MODULE_0___default().getItem(key).
|
|
2109
2113
|
then((existingValue) => {
|
|
@@ -2111,7 +2115,7 @@ const provider = {
|
|
|
2111
2115
|
|
|
2112
2116
|
// lodash adds a small overhead so we don't use it here
|
|
2113
2117
|
// eslint-disable-next-line prefer-object-spread, rulesdir/prefer-underscore-method
|
|
2114
|
-
? Object.assign({}, (0,
|
|
2118
|
+
? Object.assign({}, (0,_fastMerge__WEBPACK_IMPORTED_MODULE_4__["default"])(existingValue, value)) :
|
|
2115
2119
|
value;
|
|
2116
2120
|
return localforage__WEBPACK_IMPORTED_MODULE_0___default().setItem(key, newValue);
|
|
2117
2121
|
});
|
|
@@ -2187,6 +2191,16 @@ const provider = {
|
|
|
2187
2191
|
*/
|
|
2188
2192
|
removeItem: (localforage__WEBPACK_IMPORTED_MODULE_0___default().removeItem),
|
|
2189
2193
|
|
|
2194
|
+
/**
|
|
2195
|
+
* Remove given keys and their values from storage
|
|
2196
|
+
*
|
|
2197
|
+
* @param {Array} keys
|
|
2198
|
+
* @returns {Promise}
|
|
2199
|
+
*/
|
|
2200
|
+
removeItems(keys) {
|
|
2201
|
+
return localforage__WEBPACK_IMPORTED_MODULE_0___default().removeItems(keys);
|
|
2202
|
+
},
|
|
2203
|
+
|
|
2190
2204
|
/**
|
|
2191
2205
|
* Sets the value for a given key. The only requirement is that the value should be serializable to JSON string
|
|
2192
2206
|
* @param {String} key
|
|
@@ -3531,6 +3545,17 @@ module.exports = __WEBPACK_EXTERNAL_MODULE_localforage__;
|
|
|
3531
3545
|
|
|
3532
3546
|
/***/ }),
|
|
3533
3547
|
|
|
3548
|
+
/***/ "localforage-removeitems":
|
|
3549
|
+
/*!******************************************!*\
|
|
3550
|
+
!*** external "localforage-removeitems" ***!
|
|
3551
|
+
\******************************************/
|
|
3552
|
+
/***/ ((module) => {
|
|
3553
|
+
|
|
3554
|
+
"use strict";
|
|
3555
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_localforage_removeitems__;
|
|
3556
|
+
|
|
3557
|
+
/***/ }),
|
|
3558
|
+
|
|
3534
3559
|
/***/ "lodash/get":
|
|
3535
3560
|
/*!*****************************!*\
|
|
3536
3561
|
!*** external "lodash/get" ***!
|