Skip to content

Commit 448607a

Browse files
authored
Merge pull request #2596 from reduxjs/feature/export-more-ts-types
2 parents 88692ae + ddef7c4 commit 448607a

File tree

3 files changed

+55
-21
lines changed

3 files changed

+55
-21
lines changed

packages/toolkit/src/configureStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
CombinedState,
1212
} from 'redux'
1313
import { createStore, compose, applyMiddleware, combineReducers } from 'redux'
14-
import type { EnhancerOptions as DevToolsOptions } from './devtoolsExtension'
14+
import type { DevToolsEnhancerOptions as DevToolsOptions } from './devtoolsExtension'
1515
import { composeWithDevTools } from './devtoolsExtension'
1616

1717
import isPlainObject from './isPlainObject'
@@ -52,7 +52,7 @@ export interface ConfigureStoreOptions<
5252
/**
5353
* An array of Redux middleware to install. If not supplied, defaults to
5454
* the set of middleware returned by `getDefaultMiddleware()`.
55-
*
55+
*
5656
* @example `middleware: (gDM) => gDM().concat(logger, apiMiddleware, yourCustomMiddleware)`
5757
* @see https://redux-toolkit.js.org/api/getDefaultMiddleware#intended-usage
5858
*/

packages/toolkit/src/devtoolsExtension.ts

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { compose } from 'redux'
44
/**
55
* @public
66
*/
7-
export interface EnhancerOptions {
7+
export interface DevToolsEnhancerOptions {
88
/**
99
* the instance name to be showed on the monitor page. Default value is `document.title`.
1010
* If not specified and there's no document title, it will consist of `tabId` and `instanceId`.
@@ -29,26 +29,58 @@ export interface EnhancerOptions {
2929
*/
3030
maxAge?: number
3131
/**
32-
* - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode).
33-
* - `false` - will handle also circular references.
34-
* - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions.
35-
* - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys.
36-
* For each of them you can indicate if to include (by setting as `true`).
37-
* For `function` key you can also specify a custom function which handles serialization.
38-
* See [`jsan`](https://github.com/kolodny/jsan) for more details.
32+
* 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
33+
* were to pass an object and specify `options` as a boolean. Giving an object allows fine-grained customization using the `replacer` and `reviver`
34+
* functions.
3935
*/
4036
serialize?:
4137
| boolean
4238
| {
43-
date?: boolean
44-
regex?: boolean
45-
undefined?: boolean
46-
error?: boolean
47-
symbol?: boolean
48-
map?: boolean
49-
set?: boolean
50-
// eslint-disable-next-line @typescript-eslint/ban-types
51-
function?: boolean | Function
39+
/**
40+
* - `undefined` - will use regular `JSON.stringify` to send data (it's the fast mode).
41+
* - `false` - will handle also circular references.
42+
* - `true` - will handle also date, regex, undefined, error objects, symbols, maps, sets and functions.
43+
* - object, which contains `date`, `regex`, `undefined`, `error`, `symbol`, `map`, `set` and `function` keys.
44+
* For each of them you can indicate if to include (by setting as `true`).
45+
* For `function` key you can also specify a custom function which handles serialization.
46+
* See [`jsan`](https://github.com/kolodny/jsan) for more details.
47+
*/
48+
options?:
49+
| undefined
50+
| boolean
51+
| {
52+
date?: true
53+
regex?: true
54+
undefined?: true
55+
error?: true
56+
symbol?: true
57+
map?: true
58+
set?: true
59+
function?: true | ((fn: (...args: any[]) => any) => string)
60+
}
61+
/**
62+
* [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.
63+
* In addition, you can specify a data type by adding a [`__serializedType__`](https://github.com/zalmoxisus/remotedev-serialize/blob/master/helpers/index.js#L4)
64+
* key. So you can deserialize it back while importing or persisting data.
65+
* 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):
66+
*/
67+
replacer?: (key: string, value: unknown) => any
68+
/**
69+
* [JSON `reviver` function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter)
70+
* used for parsing the imported actions and states. See [`remotedev-serialize`](https://github.com/zalmoxisus/remotedev-serialize/blob/master/immutable/serialize.js#L8-L41)
71+
* as an example on how to serialize special data types and get them back.
72+
*/
73+
reviver?: (key: string, value: unknown) => any
74+
/**
75+
* Automatically serialize/deserialize immutablejs via [remotedev-serialize](https://github.com/zalmoxisus/remotedev-serialize).
76+
* Just pass the Immutable library. It will support all ImmutableJS structures. You can even export them into a file and get them back.
77+
* The only exception is `Record` class, for which you should pass this in addition the references to your classes in `refs`.
78+
*/
79+
immutable?: any
80+
/**
81+
* ImmutableJS `Record` classes used to make possible restore its instances back when importing, persisting...
82+
*/
83+
refs?: any
5284
}
5385
/**
5486
* function which takes `action` object and id number as arguments, and should return `action` object back.
@@ -187,7 +219,7 @@ export interface EnhancerOptions {
187219
type Compose = typeof compose
188220

189221
interface ComposeWithDevTools {
190-
(options: EnhancerOptions): Compose
222+
(options: DevToolsEnhancerOptions): Compose
191223
<StoreExt>(...funcs: StoreEnhancer<StoreExt>[]): StoreEnhancer<StoreExt>
192224
}
193225

@@ -208,7 +240,7 @@ export const composeWithDevTools: ComposeWithDevTools =
208240
* @public
209241
*/
210242
export const devToolsEnhancer: {
211-
(options: EnhancerOptions): StoreEnhancer<any>
243+
(options: DevToolsEnhancerOptions): StoreEnhancer<any>
212244
} =
213245
typeof window !== 'undefined' && (window as any).__REDUX_DEVTOOLS_EXTENSION__
214246
? (window as any).__REDUX_DEVTOOLS_EXTENSION__

packages/toolkit/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type {
3434
ConfigureStoreOptions,
3535
EnhancedStore,
3636
} from './configureStore'
37+
export type { DevToolsEnhancerOptions } from './devtoolsExtension'
3738
export {
3839
// js
3940
createAction,
@@ -174,6 +175,7 @@ export type {
174175
TaskResolved,
175176
TaskResult,
176177
} from './listenerMiddleware/index'
178+
export type { AnyListenerPredicate } from './listenerMiddleware/types'
177179

178180
export {
179181
createListenerMiddleware,

0 commit comments

Comments
 (0)