|
| 1 | +import Immutable from 'immutable'; |
1 | 2 | import { Action, ActionCreator, compose, StoreEnhancer } from 'redux'; |
2 | 3 |
|
3 | 4 | export interface EnhancerOptions { |
@@ -25,26 +26,58 @@ export interface EnhancerOptions { |
25 | 26 | */ |
26 | 27 | maxAge?: number; |
27 | 28 | /** |
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. |
35 | 32 | */ |
36 | 33 | serialize?: |
37 | 34 | | boolean |
38 | 35 | | { |
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>[]; |
48 | 81 | }; |
49 | 82 | /** |
50 | 83 | * function which takes `action` object and id number as arguments, and should return `action` object back. |
|
0 commit comments