react-native-onyx 1.0.131 → 2.0.2
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/API.md +83 -22
- package/README.md +3 -5
- package/dist/DevTools.d.ts +23 -0
- package/{lib → dist}/DevTools.js +16 -18
- package/dist/Logger.js +32 -0
- package/dist/MDTable.d.ts +36 -0
- package/{lib → dist}/MDTable.js +12 -17
- package/{lib → dist}/Onyx.js +278 -477
- package/dist/OnyxCache.d.ts +121 -0
- package/{lib → dist}/OnyxCache.js +16 -53
- package/{lib/Str.js → dist/Str.d.ts} +2 -11
- package/dist/Str.js +31 -0
- package/dist/SyncQueue.d.ts +32 -0
- package/{lib → dist}/SyncQueue.js +9 -11
- package/dist/batch.d.ts +2 -0
- package/dist/batch.js +4 -0
- package/dist/batch.native.d.ts +2 -0
- package/dist/batch.native.js +4 -0
- package/dist/compose.d.ts +19 -0
- package/{lib → dist}/compose.js +5 -8
- package/dist/createDeferredTask.d.ts +12 -0
- package/{lib → dist}/createDeferredTask.js +4 -2
- package/dist/index.d.ts +6 -0
- package/dist/index.js +10 -0
- package/dist/metrics/PerformanceUtils.d.ts +14 -0
- package/{lib → dist}/metrics/PerformanceUtils.js +16 -16
- package/dist/metrics/index.d.ts +4 -0
- package/dist/metrics/index.js +14 -0
- package/dist/metrics/index.native.d.ts +43 -0
- package/{lib → dist}/metrics/index.native.js +80 -102
- package/{lib/storage/NativeStorage.js → dist/storage/NativeStorage.d.ts} +1 -2
- package/dist/storage/NativeStorage.js +7 -0
- package/dist/storage/WebStorage.d.ts +19 -0
- package/{lib → dist}/storage/WebStorage.js +24 -34
- package/dist/storage/__mocks__/index.d.ts +23 -0
- package/{lib → dist}/storage/__mocks__/index.js +17 -19
- package/{lib/storage/index.web.js → dist/storage/index.d.ts} +1 -2
- package/dist/storage/index.js +7 -0
- package/{lib/storage/index.native.js → dist/storage/index.native.d.ts} +1 -2
- package/dist/storage/index.native.js +7 -0
- package/dist/storage/providers/IDBKeyVal.d.ts +26 -0
- package/{lib → dist}/storage/providers/IDBKeyVal.js +38 -52
- package/dist/storage/providers/SQLiteStorage.d.ts +52 -0
- package/{lib → dist}/storage/providers/SQLiteStorage.js +27 -42
- package/{lib → dist}/utils.js +14 -27
- package/{lib → dist}/withOnyx.js +122 -159
- package/package.json +23 -54
- package/dist/web.development.js +0 -4308
- package/dist/web.development.js.map +0 -1
- package/dist/web.min.js +0 -2
- package/dist/web.min.js.map +0 -1
- package/lib/Logger.js +0 -31
- package/lib/batch.js +0 -3
- package/lib/batch.native.js +0 -3
- package/lib/index.d.ts +0 -6
- package/lib/index.js +0 -5
- package/lib/metrics/index.web.js +0 -10
- package/native.js +0 -11
- package/web.js +0 -12
- /package/{lib → dist}/Logger.d.ts +0 -0
- /package/{lib → dist}/Onyx.d.ts +0 -0
- /package/{lib → dist}/types.d.ts +0 -0
- /package/{lib → dist}/utils.d.ts +0 -0
- /package/{lib → dist}/withOnyx.d.ts +0 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export default instance;
|
|
2
|
+
declare const instance: OnyxCache;
|
|
3
|
+
/**
|
|
4
|
+
* In memory cache providing data by reference
|
|
5
|
+
* Encapsulates Onyx cache related functionality
|
|
6
|
+
*/
|
|
7
|
+
declare class OnyxCache {
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
* Cache of all the storage keys available in persistent storage
|
|
11
|
+
* @type {Set<string>}
|
|
12
|
+
*/
|
|
13
|
+
private storageKeys;
|
|
14
|
+
/**
|
|
15
|
+
* @private
|
|
16
|
+
* Unique list of keys maintained in access order (most recent at the end)
|
|
17
|
+
* @type {Set<string>}
|
|
18
|
+
*/
|
|
19
|
+
private recentKeys;
|
|
20
|
+
/**
|
|
21
|
+
* @private
|
|
22
|
+
* A map of cached values
|
|
23
|
+
* @type {Record<string, *>}
|
|
24
|
+
*/
|
|
25
|
+
private storageMap;
|
|
26
|
+
/**
|
|
27
|
+
* @private
|
|
28
|
+
* Captured pending tasks for already running storage methods
|
|
29
|
+
* Using a map yields better performance on operations such a delete
|
|
30
|
+
* https://www.zhenghao.io/posts/object-vs-map
|
|
31
|
+
* @type {Map<string, Promise>}
|
|
32
|
+
*/
|
|
33
|
+
private pendingPromises;
|
|
34
|
+
/**
|
|
35
|
+
* Get all the storage keys
|
|
36
|
+
* @returns {string[]}
|
|
37
|
+
*/
|
|
38
|
+
getAllKeys(): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Get a cached value from storage
|
|
41
|
+
* @param {string} key
|
|
42
|
+
* @returns {*}
|
|
43
|
+
*/
|
|
44
|
+
getValue(key: string): any;
|
|
45
|
+
/**
|
|
46
|
+
* Check whether cache has data for the given key
|
|
47
|
+
* @param {string} key
|
|
48
|
+
* @returns {boolean}
|
|
49
|
+
*/
|
|
50
|
+
hasCacheForKey(key: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Saves a key in the storage keys list
|
|
53
|
+
* Serves to keep the result of `getAllKeys` up to date
|
|
54
|
+
* @param {string} key
|
|
55
|
+
*/
|
|
56
|
+
addKey(key: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Set's a key value in cache
|
|
59
|
+
* Adds the key to the storage keys list as well
|
|
60
|
+
* @param {string} key
|
|
61
|
+
* @param {*} value
|
|
62
|
+
* @returns {*} value - returns the cache value
|
|
63
|
+
*/
|
|
64
|
+
set(key: string, value: any): any;
|
|
65
|
+
/**
|
|
66
|
+
* Forget the cached value for the given key
|
|
67
|
+
* @param {string} key
|
|
68
|
+
*/
|
|
69
|
+
drop(key: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* Deep merge data to cache, any non existing keys will be created
|
|
72
|
+
* @param {Record<string, *>} data - a map of (cache) key - values
|
|
73
|
+
*/
|
|
74
|
+
merge(data: Record<string, any>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Check whether the given task is already running
|
|
77
|
+
* @param {string} taskName - unique name given for the task
|
|
78
|
+
* @returns {*}
|
|
79
|
+
*/
|
|
80
|
+
hasPendingTask(taskName: string): any;
|
|
81
|
+
/**
|
|
82
|
+
* Use this method to prevent concurrent calls for the same thing
|
|
83
|
+
* Instead of calling the same task again use the existing promise
|
|
84
|
+
* provided from this function
|
|
85
|
+
* @template T
|
|
86
|
+
* @param {string} taskName - unique name given for the task
|
|
87
|
+
* @returns {Promise<T>}
|
|
88
|
+
*/
|
|
89
|
+
getTaskPromise<T>(taskName: string): Promise<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Capture a promise for a given task so other caller can
|
|
92
|
+
* hook up to the promise if it's still pending
|
|
93
|
+
* @template T
|
|
94
|
+
* @param {string} taskName - unique name for the task
|
|
95
|
+
* @param {Promise<T>} promise
|
|
96
|
+
* @returns {Promise<T>}
|
|
97
|
+
*/
|
|
98
|
+
captureTask<T_1>(taskName: string, promise: Promise<T_1>): Promise<T_1>;
|
|
99
|
+
/**
|
|
100
|
+
* @private
|
|
101
|
+
* Adds a key to the top of the recently accessed keys
|
|
102
|
+
* @param {string} key
|
|
103
|
+
*/
|
|
104
|
+
private addToAccessedKeys;
|
|
105
|
+
/**
|
|
106
|
+
* Remove keys that don't fall into the range of recently used keys
|
|
107
|
+
*/
|
|
108
|
+
removeLeastRecentlyUsedKeys(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Set the recent keys list size
|
|
111
|
+
* @param {number} limit
|
|
112
|
+
*/
|
|
113
|
+
setRecentKeysLimit(limit: number): void;
|
|
114
|
+
maxRecentKeysSize: number | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* @param {String} key
|
|
117
|
+
* @param {*} value
|
|
118
|
+
* @returns {Boolean}
|
|
119
|
+
*/
|
|
120
|
+
hasValueChanged(key: string, value: any): boolean;
|
|
121
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const underscore_1 = __importDefault(require("underscore"));
|
|
7
|
+
const fast_equals_1 = require("fast-equals");
|
|
8
|
+
const utils_1 = __importDefault(require("./utils"));
|
|
9
|
+
const isDefined = underscore_1.default.negate(underscore_1.default.isUndefined);
|
|
7
10
|
/**
|
|
8
11
|
* In memory cache providing data by reference
|
|
9
12
|
* Encapsulates Onyx cache related functionality
|
|
@@ -16,21 +19,18 @@ class OnyxCache {
|
|
|
16
19
|
* @type {Set<string>}
|
|
17
20
|
*/
|
|
18
21
|
this.storageKeys = new Set();
|
|
19
|
-
|
|
20
22
|
/**
|
|
21
23
|
* @private
|
|
22
24
|
* Unique list of keys maintained in access order (most recent at the end)
|
|
23
25
|
* @type {Set<string>}
|
|
24
26
|
*/
|
|
25
27
|
this.recentKeys = new Set();
|
|
26
|
-
|
|
27
28
|
/**
|
|
28
29
|
* @private
|
|
29
30
|
* A map of cached values
|
|
30
31
|
* @type {Record<string, *>}
|
|
31
32
|
*/
|
|
32
33
|
this.storageMap = {};
|
|
33
|
-
|
|
34
34
|
/**
|
|
35
35
|
* @private
|
|
36
36
|
* Captured pending tasks for already running storage methods
|
|
@@ -39,25 +39,9 @@ class OnyxCache {
|
|
|
39
39
|
* @type {Map<string, Promise>}
|
|
40
40
|
*/
|
|
41
41
|
this.pendingPromises = new Map();
|
|
42
|
-
|
|
43
42
|
// bind all public methods to prevent problems with `this`
|
|
44
|
-
|
|
45
|
-
this,
|
|
46
|
-
'getAllKeys',
|
|
47
|
-
'getValue',
|
|
48
|
-
'hasCacheForKey',
|
|
49
|
-
'addKey',
|
|
50
|
-
'set',
|
|
51
|
-
'drop',
|
|
52
|
-
'merge',
|
|
53
|
-
'hasPendingTask',
|
|
54
|
-
'getTaskPromise',
|
|
55
|
-
'captureTask',
|
|
56
|
-
'removeLeastRecentlyUsedKeys',
|
|
57
|
-
'setRecentKeysLimit',
|
|
58
|
-
);
|
|
43
|
+
underscore_1.default.bindAll(this, 'getAllKeys', 'getValue', 'hasCacheForKey', 'addKey', 'set', 'drop', 'merge', 'hasPendingTask', 'getTaskPromise', 'captureTask', 'removeLeastRecentlyUsedKeys', 'setRecentKeysLimit');
|
|
59
44
|
}
|
|
60
|
-
|
|
61
45
|
/**
|
|
62
46
|
* Get all the storage keys
|
|
63
47
|
* @returns {string[]}
|
|
@@ -65,7 +49,6 @@ class OnyxCache {
|
|
|
65
49
|
getAllKeys() {
|
|
66
50
|
return Array.from(this.storageKeys);
|
|
67
51
|
}
|
|
68
|
-
|
|
69
52
|
/**
|
|
70
53
|
* Get a cached value from storage
|
|
71
54
|
* @param {string} key
|
|
@@ -75,7 +58,6 @@ class OnyxCache {
|
|
|
75
58
|
this.addToAccessedKeys(key);
|
|
76
59
|
return this.storageMap[key];
|
|
77
60
|
}
|
|
78
|
-
|
|
79
61
|
/**
|
|
80
62
|
* Check whether cache has data for the given key
|
|
81
63
|
* @param {string} key
|
|
@@ -84,7 +66,6 @@ class OnyxCache {
|
|
|
84
66
|
hasCacheForKey(key) {
|
|
85
67
|
return isDefined(this.storageMap[key]);
|
|
86
68
|
}
|
|
87
|
-
|
|
88
69
|
/**
|
|
89
70
|
* Saves a key in the storage keys list
|
|
90
71
|
* Serves to keep the result of `getAllKeys` up to date
|
|
@@ -93,7 +74,6 @@ class OnyxCache {
|
|
|
93
74
|
addKey(key) {
|
|
94
75
|
this.storageKeys.add(key);
|
|
95
76
|
}
|
|
96
|
-
|
|
97
77
|
/**
|
|
98
78
|
* Set's a key value in cache
|
|
99
79
|
* Adds the key to the storage keys list as well
|
|
@@ -105,10 +85,8 @@ class OnyxCache {
|
|
|
105
85
|
this.addKey(key);
|
|
106
86
|
this.addToAccessedKeys(key);
|
|
107
87
|
this.storageMap[key] = value;
|
|
108
|
-
|
|
109
88
|
return value;
|
|
110
89
|
}
|
|
111
|
-
|
|
112
90
|
/**
|
|
113
91
|
* Forget the cached value for the given key
|
|
114
92
|
* @param {string} key
|
|
@@ -118,26 +96,22 @@ class OnyxCache {
|
|
|
118
96
|
this.storageKeys.delete(key);
|
|
119
97
|
this.recentKeys.delete(key);
|
|
120
98
|
}
|
|
121
|
-
|
|
122
99
|
/**
|
|
123
100
|
* Deep merge data to cache, any non existing keys will be created
|
|
124
101
|
* @param {Record<string, *>} data - a map of (cache) key - values
|
|
125
102
|
*/
|
|
126
103
|
merge(data) {
|
|
127
|
-
if (!
|
|
104
|
+
if (!underscore_1.default.isObject(data) || underscore_1.default.isArray(data)) {
|
|
128
105
|
throw new Error('data passed to cache.merge() must be an Object of onyx key/value pairs');
|
|
129
106
|
}
|
|
130
|
-
|
|
131
107
|
// lodash adds a small overhead so we don't use it here
|
|
132
108
|
// eslint-disable-next-line prefer-object-spread, rulesdir/prefer-underscore-method
|
|
133
|
-
this.storageMap = Object.assign({},
|
|
134
|
-
|
|
109
|
+
this.storageMap = Object.assign({}, utils_1.default.fastMerge(this.storageMap, data, false));
|
|
135
110
|
const storageKeys = this.getAllKeys();
|
|
136
|
-
const mergedKeys =
|
|
111
|
+
const mergedKeys = underscore_1.default.keys(data);
|
|
137
112
|
this.storageKeys = new Set([...storageKeys, ...mergedKeys]);
|
|
138
|
-
|
|
113
|
+
underscore_1.default.each(mergedKeys, (key) => this.addToAccessedKeys(key));
|
|
139
114
|
}
|
|
140
|
-
|
|
141
115
|
/**
|
|
142
116
|
* Check whether the given task is already running
|
|
143
117
|
* @param {string} taskName - unique name given for the task
|
|
@@ -146,7 +120,6 @@ class OnyxCache {
|
|
|
146
120
|
hasPendingTask(taskName) {
|
|
147
121
|
return isDefined(this.pendingPromises.get(taskName));
|
|
148
122
|
}
|
|
149
|
-
|
|
150
123
|
/**
|
|
151
124
|
* Use this method to prevent concurrent calls for the same thing
|
|
152
125
|
* Instead of calling the same task again use the existing promise
|
|
@@ -158,7 +131,6 @@ class OnyxCache {
|
|
|
158
131
|
getTaskPromise(taskName) {
|
|
159
132
|
return this.pendingPromises.get(taskName);
|
|
160
133
|
}
|
|
161
|
-
|
|
162
134
|
/**
|
|
163
135
|
* Capture a promise for a given task so other caller can
|
|
164
136
|
* hook up to the promise if it's still pending
|
|
@@ -171,12 +143,9 @@ class OnyxCache {
|
|
|
171
143
|
const returnPromise = promise.finally(() => {
|
|
172
144
|
this.pendingPromises.delete(taskName);
|
|
173
145
|
});
|
|
174
|
-
|
|
175
146
|
this.pendingPromises.set(taskName, returnPromise);
|
|
176
|
-
|
|
177
147
|
return returnPromise;
|
|
178
148
|
}
|
|
179
|
-
|
|
180
149
|
/**
|
|
181
150
|
* @private
|
|
182
151
|
* Adds a key to the top of the recently accessed keys
|
|
@@ -187,7 +156,6 @@ class OnyxCache {
|
|
|
187
156
|
this.recentKeys.delete(key);
|
|
188
157
|
this.recentKeys.add(key);
|
|
189
158
|
}
|
|
190
|
-
|
|
191
159
|
/**
|
|
192
160
|
* Remove keys that don't fall into the range of recently used keys
|
|
193
161
|
*/
|
|
@@ -203,13 +171,11 @@ class OnyxCache {
|
|
|
203
171
|
temp.push(value);
|
|
204
172
|
numKeysToRemove--;
|
|
205
173
|
}
|
|
206
|
-
|
|
207
174
|
for (let i = 0; i < temp.length; ++i) {
|
|
208
175
|
delete this.storageMap[temp[i]];
|
|
209
176
|
this.recentKeys.delete(temp[i]);
|
|
210
177
|
}
|
|
211
178
|
}
|
|
212
|
-
|
|
213
179
|
/**
|
|
214
180
|
* Set the recent keys list size
|
|
215
181
|
* @param {number} limit
|
|
@@ -217,17 +183,14 @@ class OnyxCache {
|
|
|
217
183
|
setRecentKeysLimit(limit) {
|
|
218
184
|
this.maxRecentKeysSize = limit;
|
|
219
185
|
}
|
|
220
|
-
|
|
221
186
|
/**
|
|
222
187
|
* @param {String} key
|
|
223
188
|
* @param {*} value
|
|
224
189
|
* @returns {Boolean}
|
|
225
190
|
*/
|
|
226
191
|
hasValueChanged(key, value) {
|
|
227
|
-
return !deepEqual(this.storageMap[key], value);
|
|
192
|
+
return !(0, fast_equals_1.deepEqual)(this.storageMap[key], value);
|
|
228
193
|
}
|
|
229
194
|
}
|
|
230
|
-
|
|
231
195
|
const instance = new OnyxCache();
|
|
232
|
-
|
|
233
|
-
export default instance;
|
|
196
|
+
exports.default = instance;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _ from 'underscore';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Returns true if the haystack begins with the needle
|
|
5
3
|
*
|
|
@@ -7,10 +5,7 @@ import _ from 'underscore';
|
|
|
7
5
|
* @param {String} needle The case-sensitive string to search for
|
|
8
6
|
* @return {Boolean} Returns true if the haystack starts with the needle.
|
|
9
7
|
*/
|
|
10
|
-
function startsWith(haystack, needle)
|
|
11
|
-
return _.isString(haystack) && _.isString(needle) && haystack.startsWith(needle);
|
|
12
|
-
}
|
|
13
|
-
|
|
8
|
+
export function startsWith(haystack: string, needle: string): boolean;
|
|
14
9
|
/**
|
|
15
10
|
* Checks if parameter is a string or function.
|
|
16
11
|
* If it is a string, then we will just return it.
|
|
@@ -20,8 +15,4 @@ function startsWith(haystack, needle) {
|
|
|
20
15
|
* @param {String|Function} parameter
|
|
21
16
|
* @returns {*}
|
|
22
17
|
*/
|
|
23
|
-
function result(parameter, ...args)
|
|
24
|
-
return _.isFunction(parameter) ? parameter(...args) : parameter;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export {startsWith, result};
|
|
18
|
+
export function result(parameter: string | Function, ...args: any[]): any;
|
package/dist/Str.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.result = exports.startsWith = void 0;
|
|
7
|
+
const underscore_1 = __importDefault(require("underscore"));
|
|
8
|
+
/**
|
|
9
|
+
* Returns true if the haystack begins with the needle
|
|
10
|
+
*
|
|
11
|
+
* @param {String} haystack The full string to be searched
|
|
12
|
+
* @param {String} needle The case-sensitive string to search for
|
|
13
|
+
* @return {Boolean} Returns true if the haystack starts with the needle.
|
|
14
|
+
*/
|
|
15
|
+
function startsWith(haystack, needle) {
|
|
16
|
+
return underscore_1.default.isString(haystack) && underscore_1.default.isString(needle) && haystack.startsWith(needle);
|
|
17
|
+
}
|
|
18
|
+
exports.startsWith = startsWith;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if parameter is a string or function.
|
|
21
|
+
* If it is a string, then we will just return it.
|
|
22
|
+
* If it is a function, then we will call it with
|
|
23
|
+
* any additional arguments and return the result.
|
|
24
|
+
*
|
|
25
|
+
* @param {String|Function} parameter
|
|
26
|
+
* @returns {*}
|
|
27
|
+
*/
|
|
28
|
+
function result(parameter, ...args) {
|
|
29
|
+
return underscore_1.default.isFunction(parameter) ? parameter(...args) : parameter;
|
|
30
|
+
}
|
|
31
|
+
exports.result = result;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous queue that can be used to ensure promise based tasks are run in sequence.
|
|
3
|
+
* Pass to the constructor a function that returns a promise to run the task then add data.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* const queue = new SyncQueue(({key, val}) => {
|
|
8
|
+
* return someAsyncProcess(key, val);
|
|
9
|
+
* });
|
|
10
|
+
*
|
|
11
|
+
* queue.push({key: 1, val: '1'});
|
|
12
|
+
* queue.push({key: 2, val: '2'});
|
|
13
|
+
*/
|
|
14
|
+
export default class SyncQueue {
|
|
15
|
+
/**
|
|
16
|
+
* @param {Function} run - must return a promise
|
|
17
|
+
*/
|
|
18
|
+
constructor(run: Function);
|
|
19
|
+
queue: any[];
|
|
20
|
+
isProcessing: boolean;
|
|
21
|
+
run: Function;
|
|
22
|
+
/**
|
|
23
|
+
* Stop the queue from being processed and clear out any existing tasks
|
|
24
|
+
*/
|
|
25
|
+
abort(): void;
|
|
26
|
+
process(): void;
|
|
27
|
+
/**
|
|
28
|
+
* @param {*} data
|
|
29
|
+
* @returns {Promise}
|
|
30
|
+
*/
|
|
31
|
+
push(data: any): Promise<any>;
|
|
32
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
3
|
/**
|
|
2
4
|
* Synchronous queue that can be used to ensure promise based tasks are run in sequence.
|
|
3
5
|
* Pass to the constructor a function that returns a promise to run the task then add data.
|
|
@@ -11,7 +13,7 @@
|
|
|
11
13
|
* queue.push({key: 1, val: '1'});
|
|
12
14
|
* queue.push({key: 2, val: '2'});
|
|
13
15
|
*/
|
|
14
|
-
|
|
16
|
+
class SyncQueue {
|
|
15
17
|
/**
|
|
16
18
|
* @param {Function} run - must return a promise
|
|
17
19
|
*/
|
|
@@ -20,7 +22,6 @@ export default class SyncQueue {
|
|
|
20
22
|
this.isProcessing = false;
|
|
21
23
|
this.run = run;
|
|
22
24
|
}
|
|
23
|
-
|
|
24
25
|
/**
|
|
25
26
|
* Stop the queue from being processed and clear out any existing tasks
|
|
26
27
|
*/
|
|
@@ -28,32 +29,29 @@ export default class SyncQueue {
|
|
|
28
29
|
this.queue = [];
|
|
29
30
|
this.isProcessing = false;
|
|
30
31
|
}
|
|
31
|
-
|
|
32
32
|
process() {
|
|
33
33
|
if (this.isProcessing || this.queue.length === 0) {
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
36
|
this.isProcessing = true;
|
|
38
|
-
|
|
39
|
-
const {data, resolve, reject} = this.queue.shift();
|
|
37
|
+
const { data, resolve, reject } = this.queue.shift();
|
|
40
38
|
this.run(data)
|
|
41
39
|
.then(resolve)
|
|
42
40
|
.catch(reject)
|
|
43
41
|
.finally(() => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
this.isProcessing = false;
|
|
43
|
+
this.process();
|
|
44
|
+
});
|
|
47
45
|
}
|
|
48
|
-
|
|
49
46
|
/**
|
|
50
47
|
* @param {*} data
|
|
51
48
|
* @returns {Promise}
|
|
52
49
|
*/
|
|
53
50
|
push(data) {
|
|
54
51
|
return new Promise((resolve, reject) => {
|
|
55
|
-
this.queue.push({resolve, reject, data});
|
|
52
|
+
this.queue.push({ resolve, reject, data });
|
|
56
53
|
this.process();
|
|
57
54
|
});
|
|
58
55
|
}
|
|
59
56
|
}
|
|
57
|
+
exports.default = SyncQueue;
|
package/dist/batch.d.ts
ADDED
package/dist/batch.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a utility function taken directly from Redux. (We don't want to add Redux as a dependency)
|
|
3
|
+
* It enables functional composition, useful for the chaining/composition of HOCs.
|
|
4
|
+
*
|
|
5
|
+
* For example, instead of:
|
|
6
|
+
*
|
|
7
|
+
* export default hoc1(config1, hoc2(config2, hoc3(config3)))(Component);
|
|
8
|
+
*
|
|
9
|
+
* Use this instead:
|
|
10
|
+
*
|
|
11
|
+
* export default compose(
|
|
12
|
+
* hoc1(config1),
|
|
13
|
+
* hoc2(config2),
|
|
14
|
+
* hoc3(config3),
|
|
15
|
+
* )(Component)
|
|
16
|
+
*
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
*/
|
|
19
|
+
export default function compose(...funcs: any[]): Function;
|
package/{lib → dist}/compose.js
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
3
|
/**
|
|
2
4
|
* This is a utility function taken directly from Redux. (We don't want to add Redux as a dependency)
|
|
3
5
|
* It enables functional composition, useful for the chaining/composition of HOCs.
|
|
@@ -16,19 +18,14 @@
|
|
|
16
18
|
*
|
|
17
19
|
* @returns {Function}
|
|
18
20
|
*/
|
|
19
|
-
|
|
21
|
+
function compose(...funcs) {
|
|
20
22
|
if (funcs.length === 0) {
|
|
21
23
|
return (arg) => arg;
|
|
22
24
|
}
|
|
23
|
-
|
|
24
25
|
if (funcs.length === 1) {
|
|
25
26
|
return funcs[0];
|
|
26
27
|
}
|
|
27
|
-
|
|
28
28
|
// eslint-disable-next-line rulesdir/prefer-underscore-method
|
|
29
|
-
return funcs.reduce(
|
|
30
|
-
(a, b) =>
|
|
31
|
-
(...args) =>
|
|
32
|
-
a(b(...args)),
|
|
33
|
-
);
|
|
29
|
+
return funcs.reduce((a, b) => (...args) => a(b(...args)));
|
|
34
30
|
}
|
|
31
|
+
exports.default = compose;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a deferred task that can be resolved when we call `resolve()`
|
|
3
|
+
* The returned promise will complete when we call `resolve`
|
|
4
|
+
* Useful when we want to wait for a tasks that is resolved from an external action
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @returns {{ resolve: function(*), promise: Promise<T|void> }}
|
|
8
|
+
*/
|
|
9
|
+
export default function createDeferredTask<T>(): {
|
|
10
|
+
resolve: (arg0: any) => any;
|
|
11
|
+
promise: Promise<void | T>;
|
|
12
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
3
|
/**
|
|
2
4
|
* Create a deferred task that can be resolved when we call `resolve()`
|
|
3
5
|
* The returned promise will complete when we call `resolve`
|
|
@@ -6,11 +8,11 @@
|
|
|
6
8
|
* @template T
|
|
7
9
|
* @returns {{ resolve: function(*), promise: Promise<T|void> }}
|
|
8
10
|
*/
|
|
9
|
-
|
|
11
|
+
function createDeferredTask() {
|
|
10
12
|
const deferred = {};
|
|
11
13
|
deferred.promise = new Promise((res) => {
|
|
12
14
|
deferred.resolve = res;
|
|
13
15
|
});
|
|
14
|
-
|
|
15
16
|
return deferred;
|
|
16
17
|
}
|
|
18
|
+
exports.default = createDeferredTask;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import Onyx, {OnyxUpdate, ConnectOptions} from './Onyx';
|
|
2
|
+
import {CustomTypeOptions, OnyxCollection, OnyxEntry, NullishDeep, KeyValueMapping, OnyxKey, Selector, WithOnyxInstanceState} from './types';
|
|
3
|
+
import withOnyx from './withOnyx';
|
|
4
|
+
|
|
5
|
+
export default Onyx;
|
|
6
|
+
export {CustomTypeOptions, OnyxCollection, OnyxEntry, OnyxUpdate, withOnyx, ConnectOptions, NullishDeep, KeyValueMapping, OnyxKey, Selector, WithOnyxInstanceState};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.withOnyx = void 0;
|
|
7
|
+
const Onyx_1 = __importDefault(require("./Onyx"));
|
|
8
|
+
const withOnyx_1 = __importDefault(require("./withOnyx"));
|
|
9
|
+
exports.withOnyx = withOnyx_1.default;
|
|
10
|
+
exports.default = Onyx_1.default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provide insights into why a setState() call occurred by diffing the before and after values.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} mapping
|
|
5
|
+
* @param {*} previousValue
|
|
6
|
+
* @param {*} newValue
|
|
7
|
+
* @param {String} caller
|
|
8
|
+
* @param {String} [keyThatChanged]
|
|
9
|
+
*/
|
|
10
|
+
export function logSetStateCall(mapping: Object, previousValue: any, newValue: any, caller: string, keyThatChanged?: string | undefined): void;
|
|
11
|
+
/**
|
|
12
|
+
* @param {Boolean} debug
|
|
13
|
+
*/
|
|
14
|
+
export function setShouldDebugSetState(debug: boolean): void;
|