react-native-onyx 2.0.19 → 2.0.20
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/DevTools.d.ts +31 -13
- package/dist/DevTools.js +15 -14
- package/dist/index.d.ts +6 -21
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/dist/MDTable.d.ts +0 -36
- package/dist/MDTable.js +0 -61
package/dist/DevTools.d.ts
CHANGED
|
@@ -1,23 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type DevtoolsOptions = {
|
|
2
|
+
maxAge?: number;
|
|
3
|
+
name?: string;
|
|
4
|
+
postTimelineUpdate?: () => void;
|
|
5
|
+
preAction?: () => void;
|
|
6
|
+
logTrace?: boolean;
|
|
7
|
+
remote?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type DevtoolsSubscriber = (message: {
|
|
10
|
+
type: string;
|
|
11
|
+
payload: unknown;
|
|
12
|
+
state: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
type DevtoolsConnection = {
|
|
15
|
+
send(data: Record<string, unknown>, state: Record<string, unknown>): void;
|
|
16
|
+
init(state: Record<string, unknown>): void;
|
|
17
|
+
unsubscribe(): void;
|
|
18
|
+
subscribe(cb: DevtoolsSubscriber): () => void;
|
|
19
|
+
};
|
|
3
20
|
declare class DevTools {
|
|
4
|
-
remoteDev
|
|
5
|
-
state
|
|
6
|
-
defaultState
|
|
7
|
-
|
|
21
|
+
private remoteDev?;
|
|
22
|
+
private state;
|
|
23
|
+
private defaultState;
|
|
24
|
+
constructor();
|
|
25
|
+
connectViaExtension(options?: DevtoolsOptions): DevtoolsConnection | undefined;
|
|
8
26
|
/**
|
|
9
27
|
* Registers an action that updated the current state of the storage
|
|
10
28
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
29
|
+
* @param type - name of the action
|
|
30
|
+
* @param payload - data written to the storage
|
|
31
|
+
* @param stateChanges - partial state that got updated after the changes
|
|
14
32
|
*/
|
|
15
|
-
registerAction(type: string, payload
|
|
16
|
-
initState(initialState?:
|
|
33
|
+
registerAction(type: string, payload: unknown, stateChanges?: Record<string, unknown>): void;
|
|
34
|
+
initState(initialState?: Record<string, unknown>): void;
|
|
17
35
|
/**
|
|
18
36
|
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
|
|
19
|
-
*
|
|
20
|
-
* @param {string[]} keysToPreserve
|
|
21
37
|
*/
|
|
22
38
|
clearState(keysToPreserve?: string[]): void;
|
|
23
39
|
}
|
|
40
|
+
declare const _default: DevTools;
|
|
41
|
+
export default _default;
|
package/dist/DevTools.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
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
|
-
const underscore_1 = __importDefault(require("underscore"));
|
|
7
3
|
const ERROR_LABEL = 'Onyx DevTools - Error: ';
|
|
8
|
-
/* eslint-disable no-underscore-dangle */
|
|
9
4
|
class DevTools {
|
|
10
5
|
constructor() {
|
|
11
6
|
this.remoteDev = this.connectViaExtension();
|
|
@@ -14,10 +9,14 @@ class DevTools {
|
|
|
14
9
|
}
|
|
15
10
|
connectViaExtension(options) {
|
|
16
11
|
try {
|
|
17
|
-
|
|
12
|
+
// We don't want to augment the window type in a library code, so we use type assertion instead
|
|
13
|
+
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-explicit-any
|
|
14
|
+
const reduxDevtools = window.__REDUX_DEVTOOLS_EXTENSION__;
|
|
15
|
+
if ((options && options.remote) || typeof window === 'undefined' || !reduxDevtools) {
|
|
18
16
|
return;
|
|
19
17
|
}
|
|
20
|
-
|
|
18
|
+
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-explicit-any
|
|
19
|
+
return reduxDevtools.connect(options);
|
|
21
20
|
}
|
|
22
21
|
catch (e) {
|
|
23
22
|
console.error(ERROR_LABEL, e);
|
|
@@ -26,11 +25,11 @@ class DevTools {
|
|
|
26
25
|
/**
|
|
27
26
|
* Registers an action that updated the current state of the storage
|
|
28
27
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
28
|
+
* @param type - name of the action
|
|
29
|
+
* @param payload - data written to the storage
|
|
30
|
+
* @param stateChanges - partial state that got updated after the changes
|
|
32
31
|
*/
|
|
33
|
-
registerAction(type, payload
|
|
32
|
+
registerAction(type, payload, stateChanges = {}) {
|
|
34
33
|
try {
|
|
35
34
|
if (!this.remoteDev) {
|
|
36
35
|
return;
|
|
@@ -58,11 +57,13 @@ class DevTools {
|
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
60
59
|
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
|
|
61
|
-
*
|
|
62
|
-
* @param {string[]} keysToPreserve
|
|
63
60
|
*/
|
|
64
61
|
clearState(keysToPreserve = []) {
|
|
65
|
-
const newState =
|
|
62
|
+
const newState = Object.entries(this.state).reduce((obj, [key, value]) => {
|
|
63
|
+
// eslint-disable-next-line no-param-reassign
|
|
64
|
+
obj[key] = keysToPreserve.includes(key) ? value : this.defaultState[key];
|
|
65
|
+
return obj;
|
|
66
|
+
}, {});
|
|
66
67
|
this.registerAction('CLEAR', undefined, newState);
|
|
67
68
|
}
|
|
68
69
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
import Onyx
|
|
2
|
-
import {
|
|
1
|
+
import Onyx from './Onyx';
|
|
2
|
+
import type { OnyxUpdate, ConnectOptions } from './Onyx';
|
|
3
|
+
import type { CustomTypeOptions, OnyxCollection, OnyxEntry, NullishDeep, KeyValueMapping, OnyxKey, Selector, WithOnyxInstanceState } from './types';
|
|
4
|
+
import useOnyx from './useOnyx';
|
|
3
5
|
import withOnyx from './withOnyx';
|
|
4
|
-
import useOnyx, {UseOnyxResult, FetchStatus} from './useOnyx';
|
|
5
|
-
|
|
6
6
|
export default Onyx;
|
|
7
|
-
export {
|
|
8
|
-
|
|
9
|
-
OnyxCollection,
|
|
10
|
-
OnyxEntry,
|
|
11
|
-
OnyxUpdate,
|
|
12
|
-
withOnyx,
|
|
13
|
-
ConnectOptions,
|
|
14
|
-
NullishDeep,
|
|
15
|
-
KeyValueMapping,
|
|
16
|
-
OnyxKey,
|
|
17
|
-
Selector,
|
|
18
|
-
WithOnyxInstanceState,
|
|
19
|
-
useOnyx,
|
|
20
|
-
UseOnyxResult,
|
|
21
|
-
OnyxValue,
|
|
22
|
-
FetchStatus,
|
|
23
|
-
};
|
|
7
|
+
export { withOnyx, useOnyx };
|
|
8
|
+
export type { CustomTypeOptions, OnyxCollection, OnyxEntry, OnyxUpdate, ConnectOptions, NullishDeep, KeyValueMapping, OnyxKey, Selector, WithOnyxInstanceState };
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.useOnyx = exports.withOnyx = void 0;
|
|
7
7
|
const Onyx_1 = __importDefault(require("./Onyx"));
|
|
8
|
-
const withOnyx_1 = __importDefault(require("./withOnyx"));
|
|
9
|
-
exports.withOnyx = withOnyx_1.default;
|
|
10
8
|
const useOnyx_1 = __importDefault(require("./useOnyx"));
|
|
11
9
|
exports.useOnyx = useOnyx_1.default;
|
|
10
|
+
const withOnyx_1 = __importDefault(require("./withOnyx"));
|
|
11
|
+
exports.withOnyx = withOnyx_1.default;
|
|
12
12
|
exports.default = Onyx_1.default;
|
package/package.json
CHANGED
package/dist/MDTable.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export default MDTable;
|
|
2
|
-
declare class MDTable {
|
|
3
|
-
/**
|
|
4
|
-
* Create a CSV string from the table data
|
|
5
|
-
* @returns {string}
|
|
6
|
-
*/
|
|
7
|
-
toCSV(): string;
|
|
8
|
-
/**
|
|
9
|
-
* Create a JSON string from the table data
|
|
10
|
-
* @returns {string}
|
|
11
|
-
*/
|
|
12
|
-
toJSON(): string;
|
|
13
|
-
/**
|
|
14
|
-
* Create a MD string from the table data
|
|
15
|
-
* @returns {string}
|
|
16
|
-
*/
|
|
17
|
-
toString(): string;
|
|
18
|
-
}
|
|
19
|
-
declare namespace MDTable {
|
|
20
|
-
/**
|
|
21
|
-
* Table Factory helper
|
|
22
|
-
* @param {Object} options
|
|
23
|
-
* @param {string} [options.title] - optional title center above the table
|
|
24
|
-
* @param {string[]} options.heading - table column names
|
|
25
|
-
* @param {number[]} [options.leftAlignedCols=[]] - indexes of columns that should be left aligned
|
|
26
|
-
* Pass the columns that are non numeric here - the rest will be aligned to the right
|
|
27
|
-
* @param {Array} [options.rows] The table can be initialized with row. Rows can also be added by `addRow`
|
|
28
|
-
* @returns {MDTable}
|
|
29
|
-
*/
|
|
30
|
-
function factory({ title, heading, leftAlignedCols, rows }: {
|
|
31
|
-
title?: string | undefined;
|
|
32
|
-
heading: string[];
|
|
33
|
-
leftAlignedCols?: number[] | undefined;
|
|
34
|
-
rows?: any[] | undefined;
|
|
35
|
-
}): MDTable;
|
|
36
|
-
}
|
package/dist/MDTable.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
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 ascii_table_1 = __importDefault(require("ascii-table"));
|
|
7
|
-
class MDTable extends ascii_table_1.default {
|
|
8
|
-
/**
|
|
9
|
-
* Create a CSV string from the table data
|
|
10
|
-
* @returns {string}
|
|
11
|
-
*/
|
|
12
|
-
toCSV() {
|
|
13
|
-
return [this.getTitle(), this.getHeading(), ...this.getRows()].join('\n');
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Create a JSON string from the table data
|
|
17
|
-
* @returns {string}
|
|
18
|
-
*/
|
|
19
|
-
toJSON() {
|
|
20
|
-
return JSON.stringify(super.toJSON());
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Create a MD string from the table data
|
|
24
|
-
* @returns {string}
|
|
25
|
-
*/
|
|
26
|
-
toString() {
|
|
27
|
-
// Ignore modifying the first |---| for titled tables
|
|
28
|
-
let idx = this.getTitle() ? -2 : -1;
|
|
29
|
-
const ascii = super.toString().replace(/-\|/g, () => {
|
|
30
|
-
/* we replace "----|" with "---:|" to align the data to the right in MD */
|
|
31
|
-
idx++;
|
|
32
|
-
if (idx < 0 || this.leftAlignedCols.includes(idx)) {
|
|
33
|
-
return '-|';
|
|
34
|
-
}
|
|
35
|
-
return ':|';
|
|
36
|
-
});
|
|
37
|
-
// strip the top and the bottom row (----) to make an MD table
|
|
38
|
-
const md = ascii.split('\n').slice(1, -1).join('\n');
|
|
39
|
-
return md;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Table Factory helper
|
|
44
|
-
* @param {Object} options
|
|
45
|
-
* @param {string} [options.title] - optional title center above the table
|
|
46
|
-
* @param {string[]} options.heading - table column names
|
|
47
|
-
* @param {number[]} [options.leftAlignedCols=[]] - indexes of columns that should be left aligned
|
|
48
|
-
* Pass the columns that are non numeric here - the rest will be aligned to the right
|
|
49
|
-
* @param {Array} [options.rows] The table can be initialized with row. Rows can also be added by `addRow`
|
|
50
|
-
* @returns {MDTable}
|
|
51
|
-
*/
|
|
52
|
-
MDTable.factory = ({ title, heading, leftAlignedCols = [], rows = [] }) => {
|
|
53
|
-
const table = new MDTable({ title, heading, rows });
|
|
54
|
-
table.leftAlignedCols = leftAlignedCols;
|
|
55
|
-
/* By default we want everything aligned to the right as most values are numbers
|
|
56
|
-
* we just override the columns that are not right aligned */
|
|
57
|
-
heading.forEach((name, idx) => table.setAlign(idx, ascii_table_1.default.RIGHT));
|
|
58
|
-
leftAlignedCols.forEach((idx) => table.setAlign(idx, ascii_table_1.default.LEFT));
|
|
59
|
-
return table;
|
|
60
|
-
};
|
|
61
|
-
exports.default = MDTable;
|