Fixes type for serialize option

This commit is contained in:
Louis DeScioli 2022-03-08 17:00:35 -05:00
parent fe6419412b
commit 5aab34e503
3 changed files with 53 additions and 17 deletions

View File

@ -29,7 +29,8 @@
"prepublish": "pnpm run type-check && pnpm run lint" "prepublish": "pnpm run type-check && pnpm run lint"
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.17.9" "@babel/runtime": "^7.17.9",
"immutable": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.17.10", "@babel/cli": "^7.17.10",

View File

@ -1,3 +1,4 @@
import Immutable from 'immutable';
import { Action, ActionCreator, compose, StoreEnhancer } from 'redux'; import { Action, ActionCreator, compose, StoreEnhancer } from 'redux';
export interface EnhancerOptions { export interface EnhancerOptions {
@ -24,6 +25,14 @@ export interface EnhancerOptions {
* @default 50 * @default 50
*/ */
maxAge?: number; maxAge?: number;
/**
* 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
* were to pass an object and specify `options` as a boolean. Giving an object allows fine-grained customization using the `replacer` and `reviver`
* functions.
*/
serialize?:
| boolean
| {
/** /**
* - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode). * - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode).
* - `false` - will handle also circular references. * - `false` - will handle also circular references.
@ -33,18 +42,42 @@ export interface EnhancerOptions {
* For `function` key you can also specify a custom function which handles serialization. * For `function` key you can also specify a custom function which handles serialization.
* See [`jsan`](https://github.com/kolodny/jsan) for more details. * See [`jsan`](https://github.com/kolodny/jsan) for more details.
*/ */
serialize?: options?:
| undefined
| boolean | boolean
| { | {
date?: boolean; date?: true;
regex?: boolean; regex?: true;
undefined?: boolean; undefined?: true;
error?: boolean; error?: true;
symbol?: boolean; symbol?: true;
map?: boolean; map?: true;
set?: boolean; set?: true;
// eslint-disable-next-line @typescript-eslint/ban-types function?: true | ((fn: (...args: any[]) => any) => string);
function?: boolean | Function; };
/**
* [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.
* In addition, you can specify a data type by adding a [`__serializedType__`](https://github.com/zalmoxisus/remotedev-serialize/blob/master/helpers/index.js#L4)
* key. So you can deserialize it back while importing or persisting data.
* 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):
*/
replacer?: (key: string, value: unknown) => any;
/**
* [JSON `reviver` function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter)
* used for parsing the imported actions and states. See [`remotedev-serialize`](https://github.com/zalmoxisus/remotedev-serialize/blob/master/immutable/serialize.js#L8-L41)
* as an example on how to serialize special data types and get them back.
*/
reviver?: (key: string, value: unknown) => any;
/**
* Automatically serialize/deserialize immutablejs via [remotedev-serialize](https://github.com/zalmoxisus/remotedev-serialize).
* Just pass the Immutable library. It will support all ImmutableJS structures. You can even export them into a file and get them back.
* The only exception is `Record` class, for which you should pass this in addition the references to your classes in `refs`.
*/
immutable?: typeof Immutable;
/**
* ImmutableJS `Record` classes used to make possible restore its instances back when importing, persisting...
*/
refs?: Immutable.Record.Factory<any>[];
}; };
/** /**
* function which takes `action` object and id number as arguments, and should return `action` object back. * function which takes `action` object and id number as arguments, and should return `action` object back.

View File

@ -1157,11 +1157,13 @@ importers:
'@typescript-eslint/parser': ^5.22.0 '@typescript-eslint/parser': ^5.22.0
eslint: ^8.15.0 eslint: ^8.15.0
eslint-config-prettier: ^8.5.0 eslint-config-prettier: ^8.5.0
immutable: ^4.0.0
redux: ^4.2.0 redux: ^4.2.0
rimraf: ^3.0.2 rimraf: ^3.0.2
typescript: ~4.6.4 typescript: ~4.6.4
dependencies: dependencies:
'@babel/runtime': 7.17.9 '@babel/runtime': 7.17.9
immutable: 4.0.0
devDependencies: devDependencies:
'@babel/cli': 7.17.10_@babel+core@7.17.10 '@babel/cli': 7.17.10_@babel+core@7.17.10
'@babel/core': 7.17.10 '@babel/core': 7.17.10