react-native-onyx 2.0.12 → 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 CHANGED
@@ -1,13 +1,18 @@
1
- declare type LogData = {
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: (data: LogData) => void): void;
12
-
13
- export {registerLogger};
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
- // Logging callback
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/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 {String} haystack The full string to be searched
5
- * @param {String} needle The case-sensitive string to search for
6
- * @return {Boolean} Returns true if the haystack starts with the needle.
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
- export function startsWith(haystack: string, needle: string): boolean;
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
- export function result(parameter: string | Function, ...args: any[]): any;
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 {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.
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 underscore_1.default.isString(haystack) && underscore_1.default.isString(needle) && haystack.startsWith(needle);
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 underscore_1.default.isFunction(parameter) ? parameter(...args) : parameter;
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<T>(): {
10
- resolve: (arg0: any) => any;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-onyx",
3
- "version": "2.0.12",
3
+ "version": "2.0.13",
4
4
  "author": "Expensify, Inc.",
5
5
  "homepage": "https://expensify.com",
6
6
  "description": "State management for React Native",
@@ -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;