react-native-onyx 2.0.11 → 2.0.13
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/Logger.d.ts +12 -7
- package/dist/Logger.js +1 -7
- package/dist/Onyx.js +64 -7
- package/dist/Str.d.ts +7 -8
- package/dist/Str.js +5 -18
- package/dist/createDeferredTask.d.ts +6 -7
- package/dist/createDeferredTask.js +0 -3
- package/package.json +1 -1
- package/dist/SyncQueue.d.ts +0 -32
- package/dist/SyncQueue.js +0 -57
- package/dist/compose.d.ts +0 -19
- package/dist/compose.js +0 -31
package/dist/Logger.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
type LogData = {
|
|
2
2
|
message: string;
|
|
3
3
|
level: 'alert' | 'info';
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
type LoggerCallback = (data: LogData) => void;
|
|
6
6
|
/**
|
|
7
7
|
* Register the logging callback
|
|
8
|
-
*
|
|
9
|
-
* @param callback
|
|
10
8
|
*/
|
|
11
|
-
declare function registerLogger(callback:
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
declare function registerLogger(callback: LoggerCallback): void;
|
|
10
|
+
/**
|
|
11
|
+
* Send an alert message to the logger
|
|
12
|
+
*/
|
|
13
|
+
declare function logAlert(message: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Send an info message to the logger
|
|
16
|
+
*/
|
|
17
|
+
declare function logInfo(message: string): void;
|
|
18
|
+
export { registerLogger, logInfo, logAlert };
|
package/dist/Logger.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.logAlert = exports.logInfo = exports.registerLogger = void 0;
|
|
4
|
-
//
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
5
5
|
let logger = () => { };
|
|
6
6
|
/**
|
|
7
7
|
* Register the logging callback
|
|
8
|
-
*
|
|
9
|
-
* @param {Function} callback
|
|
10
8
|
*/
|
|
11
9
|
function registerLogger(callback) {
|
|
12
10
|
logger = callback;
|
|
@@ -14,8 +12,6 @@ function registerLogger(callback) {
|
|
|
14
12
|
exports.registerLogger = registerLogger;
|
|
15
13
|
/**
|
|
16
14
|
* Send an alert message to the logger
|
|
17
|
-
*
|
|
18
|
-
* @param {String} message
|
|
19
15
|
*/
|
|
20
16
|
function logAlert(message) {
|
|
21
17
|
logger({ message: `[Onyx] ${message}`, level: 'alert' });
|
|
@@ -23,8 +19,6 @@ function logAlert(message) {
|
|
|
23
19
|
exports.logAlert = logAlert;
|
|
24
20
|
/**
|
|
25
21
|
* Send an info message to the logger
|
|
26
|
-
*
|
|
27
|
-
* @param {String} message
|
|
28
22
|
*/
|
|
29
23
|
function logInfo(message) {
|
|
30
24
|
logger({ message: `[Onyx] ${message}`, level: 'info' });
|
package/dist/Onyx.js
CHANGED
|
@@ -694,13 +694,70 @@ function addKeyToRecentlyAccessedIfNeeded(mapping) {
|
|
|
694
694
|
* @param {Object} mapping
|
|
695
695
|
*/
|
|
696
696
|
function getCollectionDataAndSendAsObject(matchingKeys, mapping) {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
697
|
+
// Keys that are not in the cache
|
|
698
|
+
const missingKeys = [];
|
|
699
|
+
// Tasks that are pending
|
|
700
|
+
const pendingTasks = [];
|
|
701
|
+
// Keys for the tasks that are pending
|
|
702
|
+
const pendingKeys = [];
|
|
703
|
+
// We are going to combine all the data from the matching keys into a single object
|
|
704
|
+
const data = {};
|
|
705
|
+
/**
|
|
706
|
+
* We are going to iterate over all the matching keys and check if we have the data in the cache.
|
|
707
|
+
* If we do then we add it to the data object. If we do not then we check if there is a pending task
|
|
708
|
+
* for the key. If there is then we add the promise to the pendingTasks array and the key to the pendingKeys
|
|
709
|
+
* array. If there is no pending task then we add the key to the missingKeys array.
|
|
710
|
+
*
|
|
711
|
+
* These missingKeys will be later to use to multiGet the data from the storage.
|
|
712
|
+
*/
|
|
713
|
+
matchingKeys.forEach((key) => {
|
|
714
|
+
const cacheValue = OnyxCache_1.default.getValue(key);
|
|
715
|
+
if (cacheValue) {
|
|
716
|
+
data[key] = cacheValue;
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const pendingKey = `get:${key}`;
|
|
720
|
+
if (OnyxCache_1.default.hasPendingTask(pendingKey)) {
|
|
721
|
+
pendingTasks.push(OnyxCache_1.default.getTaskPromise(pendingKey));
|
|
722
|
+
pendingKeys.push(key);
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
missingKeys.push(key);
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
Promise.all(pendingTasks)
|
|
729
|
+
// We are going to wait for all the pending tasks to resolve and then add the data to the data object.
|
|
730
|
+
.then((values) => {
|
|
731
|
+
values.forEach((value, index) => {
|
|
732
|
+
data[pendingKeys[index]] = value;
|
|
733
|
+
});
|
|
734
|
+
return Promise.resolve();
|
|
735
|
+
})
|
|
736
|
+
// We are going to get the missing keys using multiGet from the storage.
|
|
737
|
+
.then(() => {
|
|
738
|
+
if (missingKeys.length === 0) {
|
|
739
|
+
return Promise.resolve();
|
|
740
|
+
}
|
|
741
|
+
return storage_1.default.multiGet(missingKeys);
|
|
742
|
+
})
|
|
743
|
+
// We are going to add the data from the missing keys to the data object and also merge it to the cache.
|
|
744
|
+
.then((values) => {
|
|
745
|
+
if (!values || values.length === 0) {
|
|
746
|
+
return Promise.resolve();
|
|
747
|
+
}
|
|
748
|
+
// temp object is used to merge the missing data into the cache
|
|
749
|
+
const temp = {};
|
|
750
|
+
values.forEach((value) => {
|
|
751
|
+
data[value[0]] = value[1];
|
|
752
|
+
temp[value[0]] = value[1];
|
|
753
|
+
});
|
|
754
|
+
OnyxCache_1.default.merge(temp);
|
|
755
|
+
return Promise.resolve();
|
|
756
|
+
})
|
|
757
|
+
// We are going to send the data to the subscriber.
|
|
758
|
+
.finally(() => {
|
|
759
|
+
sendDataToConnection(mapping, data, undefined, true);
|
|
760
|
+
});
|
|
704
761
|
}
|
|
705
762
|
/**
|
|
706
763
|
* Subscribes a react component's state directly to a store key
|
package/dist/Str.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns true if the haystack begins with the needle
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
5
|
-
* @param
|
|
6
|
-
* @return
|
|
4
|
+
* @param haystack The full string to be searched
|
|
5
|
+
* @param needle The case-sensitive string to search for
|
|
6
|
+
* @return Returns true if the haystack starts with the needle.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
declare function startsWith(haystack: string, needle: string): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Checks if parameter is a string or function.
|
|
11
11
|
* If it is a string, then we will just return it.
|
|
12
12
|
* If it is a function, then we will call it with
|
|
13
13
|
* any additional arguments and return the result.
|
|
14
|
-
*
|
|
15
|
-
* @param {String|Function} parameter
|
|
16
|
-
* @returns {*}
|
|
17
14
|
*/
|
|
18
|
-
|
|
15
|
+
declare function result(parameter: string): string;
|
|
16
|
+
declare function result<TFunction extends (...a: TArgs) => unknown, TArgs extends unknown[]>(parameter: TFunction, ...args: TArgs): ReturnType<TFunction>;
|
|
17
|
+
export { startsWith, result };
|
package/dist/Str.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.result = exports.startsWith = void 0;
|
|
7
|
-
const underscore_1 = __importDefault(require("underscore"));
|
|
8
4
|
/**
|
|
9
5
|
* Returns true if the haystack begins with the needle
|
|
10
6
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @return
|
|
7
|
+
* @param haystack The full string to be searched
|
|
8
|
+
* @param needle The case-sensitive string to search for
|
|
9
|
+
* @return Returns true if the haystack starts with the needle.
|
|
14
10
|
*/
|
|
15
11
|
function startsWith(haystack, needle) {
|
|
16
|
-
return
|
|
12
|
+
return typeof haystack === 'string' && typeof needle === 'string' && haystack.startsWith(needle);
|
|
17
13
|
}
|
|
18
14
|
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
15
|
function result(parameter, ...args) {
|
|
29
|
-
return
|
|
16
|
+
return typeof parameter === 'function' ? parameter(...args) : parameter;
|
|
30
17
|
}
|
|
31
18
|
exports.result = result;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
type DeferredTask = {
|
|
2
|
+
promise: Promise<void>;
|
|
3
|
+
resolve?: () => void;
|
|
4
|
+
};
|
|
1
5
|
/**
|
|
2
6
|
* Create a deferred task that can be resolved when we call `resolve()`
|
|
3
7
|
* The returned promise will complete when we call `resolve`
|
|
4
8
|
* 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
|
*/
|
|
9
|
-
export default function createDeferredTask
|
|
10
|
-
|
|
11
|
-
promise: Promise<void | T>;
|
|
12
|
-
};
|
|
10
|
+
export default function createDeferredTask(): DeferredTask;
|
|
11
|
+
export {};
|
|
@@ -4,9 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
* Create a deferred task that can be resolved when we call `resolve()`
|
|
5
5
|
* The returned promise will complete when we call `resolve`
|
|
6
6
|
* Useful when we want to wait for a tasks that is resolved from an external action
|
|
7
|
-
*
|
|
8
|
-
* @template T
|
|
9
|
-
* @returns {{ resolve: function(*), promise: Promise<T|void> }}
|
|
10
7
|
*/
|
|
11
8
|
function createDeferredTask() {
|
|
12
9
|
const deferred = {};
|
package/package.json
CHANGED
package/dist/SyncQueue.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/SyncQueue.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Synchronous queue that can be used to ensure promise based tasks are run in sequence.
|
|
5
|
-
* Pass to the constructor a function that returns a promise to run the task then add data.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
*
|
|
9
|
-
* const queue = new SyncQueue(({key, val}) => {
|
|
10
|
-
* return someAsyncProcess(key, val);
|
|
11
|
-
* });
|
|
12
|
-
*
|
|
13
|
-
* queue.push({key: 1, val: '1'});
|
|
14
|
-
* queue.push({key: 2, val: '2'});
|
|
15
|
-
*/
|
|
16
|
-
class SyncQueue {
|
|
17
|
-
/**
|
|
18
|
-
* @param {Function} run - must return a promise
|
|
19
|
-
*/
|
|
20
|
-
constructor(run) {
|
|
21
|
-
this.queue = [];
|
|
22
|
-
this.isProcessing = false;
|
|
23
|
-
this.run = run;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Stop the queue from being processed and clear out any existing tasks
|
|
27
|
-
*/
|
|
28
|
-
abort() {
|
|
29
|
-
this.queue = [];
|
|
30
|
-
this.isProcessing = false;
|
|
31
|
-
}
|
|
32
|
-
process() {
|
|
33
|
-
if (this.isProcessing || this.queue.length === 0) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
this.isProcessing = true;
|
|
37
|
-
const { data, resolve, reject } = this.queue.shift();
|
|
38
|
-
this.run(data)
|
|
39
|
-
.then(resolve)
|
|
40
|
-
.catch(reject)
|
|
41
|
-
.finally(() => {
|
|
42
|
-
this.isProcessing = false;
|
|
43
|
-
this.process();
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @param {*} data
|
|
48
|
-
* @returns {Promise}
|
|
49
|
-
*/
|
|
50
|
-
push(data) {
|
|
51
|
-
return new Promise((resolve, reject) => {
|
|
52
|
-
this.queue.push({ resolve, reject, data });
|
|
53
|
-
this.process();
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.default = SyncQueue;
|
package/dist/compose.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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/dist/compose.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* This is a utility function taken directly from Redux. (We don't want to add Redux as a dependency)
|
|
5
|
-
* It enables functional composition, useful for the chaining/composition of HOCs.
|
|
6
|
-
*
|
|
7
|
-
* For example, instead of:
|
|
8
|
-
*
|
|
9
|
-
* export default hoc1(config1, hoc2(config2, hoc3(config3)))(Component);
|
|
10
|
-
*
|
|
11
|
-
* Use this instead:
|
|
12
|
-
*
|
|
13
|
-
* export default compose(
|
|
14
|
-
* hoc1(config1),
|
|
15
|
-
* hoc2(config2),
|
|
16
|
-
* hoc3(config3),
|
|
17
|
-
* )(Component)
|
|
18
|
-
*
|
|
19
|
-
* @returns {Function}
|
|
20
|
-
*/
|
|
21
|
-
function compose(...funcs) {
|
|
22
|
-
if (funcs.length === 0) {
|
|
23
|
-
return (arg) => arg;
|
|
24
|
-
}
|
|
25
|
-
if (funcs.length === 1) {
|
|
26
|
-
return funcs[0];
|
|
27
|
-
}
|
|
28
|
-
// eslint-disable-next-line rulesdir/prefer-underscore-method
|
|
29
|
-
return funcs.reduce((a, b) => (...args) => a(b(...args)));
|
|
30
|
-
}
|
|
31
|
-
exports.default = compose;
|