react-native-onyx 3.0.7 → 3.0.9
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/README.md +18 -1
- package/dist/DevTools/NoOpDevTools.d.ts +11 -0
- package/dist/DevTools/NoOpDevTools.js +18 -0
- package/dist/DevTools/RealDevTools.d.ts +25 -0
- package/dist/DevTools/RealDevTools.js +72 -0
- package/dist/DevTools/types.d.ts +31 -0
- package/dist/DevTools/types.js +2 -0
- package/dist/DevTools.d.ts +19 -42
- package/dist/DevTools.js +35 -64
- package/dist/Onyx.d.ts +1 -1
- package/dist/Onyx.js +3 -2
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -441,7 +441,24 @@ To use the extension, simply install it from your favorite web browser store:
|
|
|
441
441
|
- [Microsoft Edge](https://microsoftedge.microsoft.com/addons/detail/redux-devtools/nnkgneoiohoecpdiaponcejilbhhikei)
|
|
442
442
|
- [Mozilla Firefox](https://addons.mozilla.org/en-US/firefox/addon/reduxdevtools/)
|
|
443
443
|
|
|
444
|
-
|
|
444
|
+
### Enabling or Disabling Redux DevTools
|
|
445
|
+
|
|
446
|
+
You can control whether the Redux DevTools integration is enabled by setting the `enableDevTools` option in the `Onyx.init()` configuration.
|
|
447
|
+
|
|
448
|
+
- To **enable** Redux DevTools and start logging updates to local storage, set `enableDevTools: true`.
|
|
449
|
+
- To **disable** Redux DevTools and prevent any logging to the extension, set `enableDevTools: false`.
|
|
450
|
+
|
|
451
|
+
This option defaults to `true` (enabled) on Web, so you only need to set it to `false` if you want to disable the integration.
|
|
452
|
+
|
|
453
|
+
```javascript
|
|
454
|
+
import Onyx from 'react-native-onyx';
|
|
455
|
+
import Config from './config';
|
|
456
|
+
|
|
457
|
+
Onyx.init({
|
|
458
|
+
keys: ONYXKEYS,
|
|
459
|
+
enableDevTools: Config.ENABLE_ONYX_DEVTOOLS,
|
|
460
|
+
});
|
|
461
|
+
```
|
|
445
462
|
|
|
446
463
|
### Usage
|
|
447
464
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IDevTools } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* No-op implementation of DevTools that does nothing
|
|
4
|
+
* Used when DevTools is disabled
|
|
5
|
+
*/
|
|
6
|
+
declare class NoOpDevTools implements IDevTools {
|
|
7
|
+
registerAction(): void;
|
|
8
|
+
initState(): void;
|
|
9
|
+
clearState(): void;
|
|
10
|
+
}
|
|
11
|
+
export default NoOpDevTools;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* No-op implementation of DevTools that does nothing
|
|
5
|
+
* Used when DevTools is disabled
|
|
6
|
+
*/
|
|
7
|
+
class NoOpDevTools {
|
|
8
|
+
registerAction() {
|
|
9
|
+
// do nothing
|
|
10
|
+
}
|
|
11
|
+
initState() {
|
|
12
|
+
// do nothing
|
|
13
|
+
}
|
|
14
|
+
clearState() {
|
|
15
|
+
// do nothing
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = NoOpDevTools;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IDevTools, DevtoolsOptions, DevtoolsConnection } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Real implementation of DevTools that connects to Redux DevTools Extension
|
|
4
|
+
*/
|
|
5
|
+
declare class RealDevTools implements IDevTools {
|
|
6
|
+
private remoteDev?;
|
|
7
|
+
private state;
|
|
8
|
+
private defaultState;
|
|
9
|
+
constructor();
|
|
10
|
+
connectViaExtension(options?: DevtoolsOptions): DevtoolsConnection | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Registers an action that updated the current state of the storage
|
|
13
|
+
*
|
|
14
|
+
* @param type - name of the action
|
|
15
|
+
* @param payload - data written to the storage
|
|
16
|
+
* @param stateChanges - partial state that got updated after the changes
|
|
17
|
+
*/
|
|
18
|
+
registerAction(type: string, payload: unknown, stateChanges?: Record<string, unknown> | null): void;
|
|
19
|
+
initState(initialState?: Record<string, unknown>): void;
|
|
20
|
+
/**
|
|
21
|
+
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
|
|
22
|
+
*/
|
|
23
|
+
clearState(keysToPreserve?: string[]): void;
|
|
24
|
+
}
|
|
25
|
+
export default RealDevTools;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ERROR_LABEL = 'Onyx DevTools - Error: ';
|
|
4
|
+
/**
|
|
5
|
+
* Real implementation of DevTools that connects to Redux DevTools Extension
|
|
6
|
+
*/
|
|
7
|
+
class RealDevTools {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.remoteDev = this.connectViaExtension();
|
|
10
|
+
this.state = {};
|
|
11
|
+
this.defaultState = {};
|
|
12
|
+
}
|
|
13
|
+
connectViaExtension(options) {
|
|
14
|
+
try {
|
|
15
|
+
// We don't want to augment the window type in a library code, so we use type assertion instead
|
|
16
|
+
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-explicit-any
|
|
17
|
+
const reduxDevtools = typeof window === 'undefined' ? undefined : window.__REDUX_DEVTOOLS_EXTENSION__;
|
|
18
|
+
if ((options === null || options === void 0 ? void 0 : options.remote) || !reduxDevtools) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
return reduxDevtools.connect(options);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(ERROR_LABEL, e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Registers an action that updated the current state of the storage
|
|
29
|
+
*
|
|
30
|
+
* @param type - name of the action
|
|
31
|
+
* @param payload - data written to the storage
|
|
32
|
+
* @param stateChanges - partial state that got updated after the changes
|
|
33
|
+
*/
|
|
34
|
+
registerAction(type, payload, stateChanges = {}) {
|
|
35
|
+
try {
|
|
36
|
+
if (!this.remoteDev) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const newState = Object.assign(Object.assign({}, this.state), stateChanges);
|
|
40
|
+
this.remoteDev.send({ type, payload }, newState);
|
|
41
|
+
this.state = newState;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.error(ERROR_LABEL, e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
initState(initialState = {}) {
|
|
48
|
+
try {
|
|
49
|
+
if (!this.remoteDev) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.remoteDev.init(initialState);
|
|
53
|
+
this.state = initialState;
|
|
54
|
+
this.defaultState = initialState;
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
console.error(ERROR_LABEL, e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
|
|
62
|
+
*/
|
|
63
|
+
clearState(keysToPreserve = []) {
|
|
64
|
+
const newState = Object.entries(this.state).reduce((obj, [key, value]) => {
|
|
65
|
+
// eslint-disable-next-line no-param-reassign
|
|
66
|
+
obj[key] = keysToPreserve.includes(key) ? value : this.defaultState[key];
|
|
67
|
+
return obj;
|
|
68
|
+
}, {});
|
|
69
|
+
this.registerAction('CLEAR', undefined, newState);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = RealDevTools;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
};
|
|
20
|
+
type ReduxDevtools = {
|
|
21
|
+
connect(options?: DevtoolsOptions): DevtoolsConnection;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Type definition for DevTools instance
|
|
25
|
+
*/
|
|
26
|
+
type IDevTools = {
|
|
27
|
+
registerAction(type: string, payload: unknown, stateChanges?: Record<string, unknown> | null): void;
|
|
28
|
+
initState(initialState?: Record<string, unknown>): void;
|
|
29
|
+
clearState(keysToPreserve?: string[]): void;
|
|
30
|
+
};
|
|
31
|
+
export type { DevtoolsOptions, DevtoolsSubscriber, DevtoolsConnection, ReduxDevtools, IDevTools };
|
package/dist/DevTools.d.ts
CHANGED
|
@@ -1,42 +1,19 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
declare class DevTools {
|
|
21
|
-
private remoteDev?;
|
|
22
|
-
private state;
|
|
23
|
-
private defaultState;
|
|
24
|
-
constructor();
|
|
25
|
-
connectViaExtension(options?: DevtoolsOptions): DevtoolsConnection | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* Registers an action that updated the current state of the storage
|
|
28
|
-
*
|
|
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
|
|
32
|
-
*/
|
|
33
|
-
registerAction(type: string, payload: unknown, stateChanges?: Record<string, unknown> | null): void;
|
|
34
|
-
initState(initialState?: Record<string, unknown>): void;
|
|
35
|
-
/**
|
|
36
|
-
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
|
|
37
|
-
*/
|
|
38
|
-
clearState(keysToPreserve?: string[]): void;
|
|
39
|
-
}
|
|
40
|
-
declare const _default: DevTools;
|
|
41
|
-
export default _default;
|
|
42
|
-
export type { DevtoolsConnection };
|
|
1
|
+
import type { IDevTools, DevtoolsConnection } from './DevTools/types';
|
|
2
|
+
/**
|
|
3
|
+
* Initializes DevTools with the given enabled flag
|
|
4
|
+
*/
|
|
5
|
+
declare function initDevTools(enabled: boolean): void;
|
|
6
|
+
/**
|
|
7
|
+
* Gets the current DevTools instance (for testing purposes only)
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
declare function getDevToolsInstance(): IDevTools;
|
|
11
|
+
/**
|
|
12
|
+
* Export a default object that delegates to the current devToolsInstance
|
|
13
|
+
* This allows the instance to be swapped out while keeping the same import signature
|
|
14
|
+
*/
|
|
15
|
+
declare const DevTools: IDevTools;
|
|
16
|
+
export default DevTools;
|
|
17
|
+
export { initDevTools, getDevToolsInstance };
|
|
18
|
+
export type { DevtoolsConnection, IDevTools };
|
|
19
|
+
export type { default as RealDevTools } from './DevTools/RealDevTools';
|
package/dist/DevTools.js
CHANGED
|
@@ -1,69 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* @param type - name of the action
|
|
28
|
-
* @param payload - data written to the storage
|
|
29
|
-
* @param stateChanges - partial state that got updated after the changes
|
|
30
|
-
*/
|
|
6
|
+
exports.initDevTools = initDevTools;
|
|
7
|
+
exports.getDevToolsInstance = getDevToolsInstance;
|
|
8
|
+
const RealDevTools_1 = __importDefault(require("./DevTools/RealDevTools"));
|
|
9
|
+
const NoOpDevTools_1 = __importDefault(require("./DevTools/NoOpDevTools"));
|
|
10
|
+
// Start with a no-op instance
|
|
11
|
+
let devToolsInstance = new NoOpDevTools_1.default();
|
|
12
|
+
/**
|
|
13
|
+
* Initializes DevTools with the given enabled flag
|
|
14
|
+
*/
|
|
15
|
+
function initDevTools(enabled) {
|
|
16
|
+
devToolsInstance = enabled ? new RealDevTools_1.default() : new NoOpDevTools_1.default();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Gets the current DevTools instance (for testing purposes only)
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
function getDevToolsInstance() {
|
|
23
|
+
return devToolsInstance;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Export a default object that delegates to the current devToolsInstance
|
|
27
|
+
* This allows the instance to be swapped out while keeping the same import signature
|
|
28
|
+
*/
|
|
29
|
+
const DevTools = {
|
|
31
30
|
registerAction(type, payload, stateChanges = {}) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const newState = Object.assign(Object.assign({}, this.state), stateChanges);
|
|
37
|
-
this.remoteDev.send({ type, payload }, newState);
|
|
38
|
-
this.state = newState;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
console.error(ERROR_LABEL, e);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
31
|
+
devToolsInstance.registerAction(type, payload, stateChanges);
|
|
32
|
+
},
|
|
44
33
|
initState(initialState = {}) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
this.remoteDev.init(initialState);
|
|
50
|
-
this.state = initialState;
|
|
51
|
-
this.defaultState = initialState;
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
console.error(ERROR_LABEL, e);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* This clears the internal state of the DevTools, preserving the keys included in `keysToPreserve`
|
|
59
|
-
*/
|
|
34
|
+
devToolsInstance.initState(initialState);
|
|
35
|
+
},
|
|
60
36
|
clearState(keysToPreserve = []) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}, {});
|
|
66
|
-
this.registerAction('CLEAR', undefined, newState);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.default = new DevTools();
|
|
37
|
+
devToolsInstance.clearState(keysToPreserve);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
exports.default = DevTools;
|
package/dist/Onyx.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as Logger from './Logger';
|
|
|
2
2
|
import type { CollectionKeyBase, ConnectOptions, InitOptions, OnyxKey, OnyxMergeCollectionInput, OnyxMergeInput, OnyxMultiSetInput, OnyxSetInput, OnyxUpdate, SetOptions } from './types';
|
|
3
3
|
import type { Connection } from './OnyxConnectionManager';
|
|
4
4
|
/** Initialize the store with actions and listening for storage events */
|
|
5
|
-
declare function init({ keys, initialKeyStates, evictableKeys, maxCachedKeysCount, shouldSyncMultipleInstances, enablePerformanceMetrics, skippableCollectionMemberIDs, }: InitOptions): void;
|
|
5
|
+
declare function init({ keys, initialKeyStates, evictableKeys, maxCachedKeysCount, shouldSyncMultipleInstances, enablePerformanceMetrics, enableDevTools, skippableCollectionMemberIDs, }: InitOptions): void;
|
|
6
6
|
/**
|
|
7
7
|
* Connects to an Onyx key given the options passed and listens to its changes.
|
|
8
8
|
* This method will be deprecated soon. Please use `Onyx.connectWithoutView()` instead.
|
package/dist/Onyx.js
CHANGED
|
@@ -40,7 +40,7 @@ const Logger = __importStar(require("./Logger"));
|
|
|
40
40
|
const OnyxCache_1 = __importStar(require("./OnyxCache"));
|
|
41
41
|
const storage_1 = __importDefault(require("./storage"));
|
|
42
42
|
const utils_1 = __importDefault(require("./utils"));
|
|
43
|
-
const DevTools_1 =
|
|
43
|
+
const DevTools_1 = __importStar(require("./DevTools"));
|
|
44
44
|
const OnyxUtils_1 = __importDefault(require("./OnyxUtils"));
|
|
45
45
|
const logMessages_1 = __importDefault(require("./logMessages"));
|
|
46
46
|
const OnyxConnectionManager_1 = __importDefault(require("./OnyxConnectionManager"));
|
|
@@ -48,12 +48,13 @@ const GlobalSettings = __importStar(require("./GlobalSettings"));
|
|
|
48
48
|
const metrics_1 = __importDefault(require("./metrics"));
|
|
49
49
|
const OnyxMerge_1 = __importDefault(require("./OnyxMerge"));
|
|
50
50
|
/** Initialize the store with actions and listening for storage events */
|
|
51
|
-
function init({ keys = {}, initialKeyStates = {}, evictableKeys = [], maxCachedKeysCount = 1000, shouldSyncMultipleInstances = !!global.localStorage, enablePerformanceMetrics = false, skippableCollectionMemberIDs = [], }) {
|
|
51
|
+
function init({ keys = {}, initialKeyStates = {}, evictableKeys = [], maxCachedKeysCount = 1000, shouldSyncMultipleInstances = !!global.localStorage, enablePerformanceMetrics = false, enableDevTools = true, skippableCollectionMemberIDs = [], }) {
|
|
52
52
|
var _a;
|
|
53
53
|
if (enablePerformanceMetrics) {
|
|
54
54
|
GlobalSettings.setPerformanceMetricsEnabled(true);
|
|
55
55
|
applyDecorators();
|
|
56
56
|
}
|
|
57
|
+
(0, DevTools_1.initDevTools)(enableDevTools);
|
|
57
58
|
storage_1.default.init();
|
|
58
59
|
OnyxUtils_1.default.setSkippableCollectionMemberIDs(new Set(skippableCollectionMemberIDs));
|
|
59
60
|
if (shouldSyncMultipleInstances) {
|
package/dist/types.d.ts
CHANGED
|
@@ -337,6 +337,12 @@ type InitOptions = {
|
|
|
337
337
|
* @default false
|
|
338
338
|
*/
|
|
339
339
|
enablePerformanceMetrics?: boolean;
|
|
340
|
+
/**
|
|
341
|
+
* If enabled, it will connect to Redux DevTools Extension for debugging.
|
|
342
|
+
* This allows you to see all Onyx state changes in the Redux DevTools.
|
|
343
|
+
* @default true
|
|
344
|
+
*/
|
|
345
|
+
enableDevTools?: boolean;
|
|
340
346
|
/**
|
|
341
347
|
* Array of collection member IDs which updates will be ignored when using Onyx methods.
|
|
342
348
|
* Additionally, any subscribers from these keys to won't receive any data from Onyx.
|