Skip to content

Commit 3aa2c18

Browse files
dannyBieszewa666
authored andcommitted
feat(DevTools): options to configure the Redux DevTools communication
allows to pass connect options to initiate customised communication with the Redux DevTools fixes issue #51
1 parent 40827a0 commit 3aa2c18

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

doc/article/en-US/aurelia-store-plugin.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,37 @@ If you've ever worked with Redux then you know for sure about the [Redux Devtool
16701670

16711671
There are tons of [great articles](https://codeburst.io/redux-devtools-for-dummies-74566c597d7) to get you started. Head over to [DevTools browser extension page](https://github.com/zalmoxisus/redux-devtools-extension) for instructions on how to install the extension, start your Aurelia Store plugin project and see how it works.
16721672

1673+
## Defining custom devToolsOptions
1674+
1675+
if you use the Redux DevTools extension you can pass options to Aurelia-Store to setup the extension with your [preferred configuration](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md).
1676+
We can set the serialize property to an [object or boolean](https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md#serialize).
1677+
1678+
In the following example, we set serialize to false. This way our state will not get serialized when sending it to the extension.
1679+
1680+
<code-listing heading="Initializing the DevTools extension with custom options">
1681+
<source-code lang="TypeScript">
1682+
1683+
// main.ts
1684+
1685+
...
1686+
aurelia.use.plugin("aurelia-store", { initialState, {
1687+
devToolsOptions: {
1688+
serialize: false
1689+
},
1690+
}});
1691+
</source-code>
1692+
<source-code lang="JavaScript">
1693+
1694+
// main.js
1695+
1696+
...
1697+
aurelia.use.plugin("aurelia-store", { initialState, {
1698+
devToolsOptions: {
1699+
serialize: false
1700+
},
1701+
}});
1702+
</source-code>
1703+
</code-listing>
16731704

16741705
## Defining custom LogLevels
16751706

src/store.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,26 @@ export enum PerformanceMeasurement {
1818
All = "all"
1919
}
2020

21+
export interface DevToolsOptions {
22+
serialize?: boolean | {
23+
date?: boolean;
24+
regex?: boolean;
25+
undefined?: boolean;
26+
error?: boolean;
27+
symbol?: boolean;
28+
map?: boolean;
29+
set?: boolean;
30+
function?: boolean | Function;
31+
};
32+
}
33+
2134
export interface StoreOptions {
2235
history: Partial<HistoryOptions>;
2336
logDispatchedActions?: boolean;
2437
measurePerformance?: PerformanceMeasurement;
2538
propagateError?: boolean;
2639
logDefinitions?: LogDefinitions;
40+
devToolsOptions?: DevToolsOptions;
2741
}
2842

2943
interface DispatchQueueItem<T> {
@@ -258,7 +272,7 @@ export class Store<T> {
258272
if (PLATFORM.global.devToolsExtension) {
259273
this.logger[getLogType(this.options, "devToolsStatus", LogLevel.debug)]("DevTools are available");
260274
this.devToolsAvailable = true;
261-
this.devTools = PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect();
275+
this.devTools = PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__.connect(this.options.devToolsOptions);
262276
this.devTools.init(this.initialState);
263277

264278
this.devTools.subscribe((message: any) => {

test/unit/redux-devtools.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { DevToolsOptions } from "./../../src/store";
12
import { skip, delay } from "rxjs/operators";
23

34
import {
@@ -11,12 +12,14 @@ class DevToolsMock {
1112
public subscriptions = [];
1213
public init = jest.fn();
1314
public subscribe = jest.fn().mockImplementation((cb: (message: any) => void) => this.subscriptions.push(cb));
15+
16+
constructor(public devToolsOptions: DevToolsOptions) {}
1417
}
1518

1619
function createDevToolsMock() {
1720
PAL.PLATFORM.global.devToolsExtension = {};
1821
PAL.PLATFORM.global.__REDUX_DEVTOOLS_EXTENSION__ = {
19-
connect: () => new DevToolsMock()
22+
connect: (devToolsOptions?: DevToolsOptions) => new DevToolsMock(devToolsOptions)
2023
}
2124
}
2225

@@ -43,6 +46,13 @@ describe("redux devtools", () => {
4346
expect((store as any).devTools.init).toHaveBeenCalled();
4447
});
4548

49+
it("should use DevToolsOptions if available", () => {
50+
createDevToolsMock();
51+
const store = new Store<testState>({ foo: "bar " }, { devToolsOptions: { serialize: false } });
52+
53+
expect((store as any).devTools.devToolsOptions).toBeDefined();
54+
});
55+
4656
it("should receive time-travel notification from devtools", () => {
4757
createDevToolsMock();
4858

0 commit comments

Comments
 (0)