Skip to content

Commit 6cf1865

Browse files
lourdMethuselah96
andauthored
Fixes type for serialize option (#1112)
* Fixes type for serialize option * Create gold-chairs-rescue.md * Update gold-chairs-rescue.md Co-authored-by: Nathan Bierema <[email protected]>
1 parent db1fcd1 commit 6cf1865

File tree

4 files changed

+97
-18
lines changed

4 files changed

+97
-18
lines changed

.changeset/gold-chairs-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@redux-devtools/extension': patch
3+
---
4+
5+
Fix type for serialize option

packages/redux-devtools-extension/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"prepublish": "pnpm run type-check && pnpm run lint"
3030
},
3131
"dependencies": {
32-
"@babel/runtime": "^7.18.3"
32+
"@babel/runtime": "^7.18.3",
33+
"immutable": "^4.0.0"
3334
},
3435
"devDependencies": {
3536
"@babel/cli": "^7.17.10",

packages/redux-devtools-extension/src/index.ts

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Immutable from 'immutable';
12
import { Action, ActionCreator, compose, StoreEnhancer } from 'redux';
23

34
export interface EnhancerOptions {
@@ -25,26 +26,58 @@ export interface EnhancerOptions {
2526
*/
2627
maxAge?: number;
2728
/**
28-
* - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode).
29-
* - `false` - will handle also circular references.
30-
* - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions.
31-
* - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys.
32-
* For each of them you can indicate if to include (by setting as `true`).
33-
* For `function` key you can also specify a custom function which handles serialization.
34-
* See [`jsan`](https://github.com/kolodny/jsan) for more details.
29+
* Customizes how actions and state are serialized and deserialized. Can be a boolean or object. If given a boolean, the behavior is the same as if you
30+
* were to pass an object and specify `options` as a boolean. Giving an object allows fine-grained customization using the `replacer` and `reviver`
31+
* functions.
3532
*/
3633
serialize?:
3734
| boolean
3835
| {
39-
date?: boolean;
40-
regex?: boolean;
41-
undefined?: boolean;
42-
error?: boolean;
43-
symbol?: boolean;
44-
map?: boolean;
45-
set?: boolean;
46-
// eslint-disable-next-line @typescript-eslint/ban-types
47-
function?: boolean | Function;
36+
/**
37+
* - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode).
38+
* - `false` - will handle also circular references.
39+
* - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions.
40+
* - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys.
41+
* For each of them you can indicate if to include (by setting as `true`).
42+
* For `function` key you can also specify a custom function which handles serialization.
43+
* See [`jsan`](https://github.com/kolodny/jsan) for more details.
44+
*/
45+
options?:
46+
| undefined
47+
| boolean
48+
| {
49+
date?: true;
50+
regex?: true;
51+
undefined?: true;
52+
error?: true;
53+
symbol?: true;
54+
map?: true;
55+
set?: true;
56+
function?: true | ((fn: (...args: any[]) => any) => string);
57+
};
58+
/**
59+
* [JSON replacer function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) used for both actions and states stringify.
60+
* In addition, you can specify a data type by adding a [`__serializedType__`](https://github.com/zalmoxisus/remotedev-serialize/blob/master/helpers/index.js#L4)
61+
* key. So you can deserialize it back while importing or persisting data.
62+
* Moreover, it will also [show a nice preview showing the provided custom type](https://cloud.githubusercontent.com/assets/7957859/21814330/a17d556a-d761-11e6-85ef-159dd12f36c5.png):
63+
*/
64+
replacer?: (key: string, value: unknown) => any;
65+
/**
66+
* [JSON `reviver` function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter)
67+
* used for parsing the imported actions and states. See [`remotedev-serialize`](https://github.com/zalmoxisus/remotedev-serialize/blob/master/immutable/serialize.js#L8-L41)
68+
* as an example on how to serialize special data types and get them back.
69+
*/
70+
reviver?: (key: string, value: unknown) => any;
71+
/**
72+
* Automatically serialize/deserialize immutablejs via [remotedev-serialize](https://github.com/zalmoxisus/remotedev-serialize).
73+
* Just pass the Immutable library. It will support all ImmutableJS structures. You can even export them into a file and get them back.
74+
* The only exception is `Record` class, for which you should pass this in addition the references to your classes in `refs`.
75+
*/
76+
immutable?: typeof Immutable;
77+
/**
78+
* ImmutableJS `Record` classes used to make possible restore its instances back when importing, persisting...
79+
*/
80+
refs?: Immutable.Record.Factory<any>[];
4881
};
4982
/**
5083
* function which takes `action` object and id number as arguments, and should return `action` object back.

pnpm-lock.yaml

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)