react-native-onyx 1.0.62 → 1.0.63

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.
@@ -13,7 +13,15 @@ import {
13
13
  import _ from 'underscore';
14
14
  import fastMerge from '../../fastMerge';
15
15
 
16
- const customStore = createStore('OnyxDB', 'keyvaluepairs');
16
+ // We don't want to initialize the store while the JS bundle loads as idb-keyval will try to use global.indexedDB
17
+ // which might not be available in certain environments that load the bundle (e.g. electron main process).
18
+ let customStoreInstance;
19
+ const getCustomStore = () => {
20
+ if (!customStoreInstance) {
21
+ customStoreInstance = createStore('OnyxDB', 'keyvaluepairs');
22
+ }
23
+ return customStoreInstance;
24
+ };
17
25
 
18
26
  const provider = {
19
27
  /**
@@ -22,7 +30,7 @@ const provider = {
22
30
  * @param {*} value
23
31
  * @return {Promise<void>}
24
32
  */
25
- setItem: (key, value) => set(key, value, customStore),
33
+ setItem: (key, value) => set(key, value, getCustomStore()),
26
34
 
27
35
  /**
28
36
  * Get multiple key-value pairs for the give array of keys in a batch.
@@ -30,7 +38,7 @@ const provider = {
30
38
  * @param {String[]} keysParam
31
39
  * @return {Promise<Array<[key, value]>>}
32
40
  */
33
- multiGet: keysParam => getMany(keysParam, customStore)
41
+ multiGet: keysParam => getMany(keysParam, getCustomStore())
34
42
  .then(values => _.map(values, (value, index) => [keysParam[index], value])),
35
43
 
36
44
  /**
@@ -38,7 +46,7 @@ const provider = {
38
46
  * @param {Array<[key, value]>} pairs
39
47
  * @return {Promise<void>}
40
48
  */
41
- multiMerge: pairs => customStore('readwrite', (store) => {
49
+ multiMerge: pairs => getCustomStore()('readwrite', (store) => {
42
50
  // Note: we are using the manual store transaction here, to fit the read and update
43
51
  // of the items in one transaction to achieve best performance.
44
52
 
@@ -70,33 +78,33 @@ const provider = {
70
78
  * @param {Array<[key, value]>} pairs
71
79
  * @return {Promise<void>}
72
80
  */
73
- multiSet: pairs => setMany(pairs, customStore),
81
+ multiSet: pairs => setMany(pairs, getCustomStore()),
74
82
 
75
83
  /**
76
84
  * Clear everything from storage and also stops the SyncQueue from adding anything more to storage
77
85
  * @returns {Promise<void>}
78
86
  */
79
- clear: () => clear(customStore),
87
+ clear: () => clear(getCustomStore()),
80
88
 
81
89
  /**
82
90
  * Returns all keys available in storage
83
91
  * @returns {Promise<String[]>}
84
92
  */
85
- getAllKeys: () => keys(customStore),
93
+ getAllKeys: () => keys(getCustomStore()),
86
94
 
87
95
  /**
88
96
  * Get the value of a given key or return `null` if it's not available in storage
89
97
  * @param {String} key
90
98
  * @return {Promise<*>}
91
99
  */
92
- getItem: key => get(key, customStore),
100
+ getItem: key => get(key, getCustomStore()),
93
101
 
94
102
  /**
95
103
  * Remove given key and it's value from storage
96
104
  * @param {String} key
97
105
  * @returns {Promise<void>}
98
106
  */
99
- removeItem: key => del(key, customStore),
107
+ removeItem: key => del(key, getCustomStore()),
100
108
 
101
109
  /**
102
110
  * Remove given keys and their values from storage
@@ -104,7 +112,7 @@ const provider = {
104
112
  * @param {Array} keysParam
105
113
  * @returns {Promise}
106
114
  */
107
- removeItems: keysParam => delMany(keysParam, customStore),
115
+ removeItems: keysParam => delMany(keysParam, getCustomStore()),
108
116
  };
109
117
 
110
118
  export default provider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "1.0.62",
3
+ "version": "1.0.63",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",