Remove deprecated serialization parameters (#942)

This commit is contained in:
Nathan Bierema 2021-11-05 14:54:22 -04:00 committed by GitHub
parent a3d70a7e04
commit 39be59eebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 6 additions and 114 deletions

View File

@ -1,4 +1,3 @@
import mapValues from 'lodash/mapValues';
import jsan from 'jsan'; import jsan from 'jsan';
import seralizeImmutable from '@redux-devtools/serialize/lib/immutable/serialize'; import seralizeImmutable from '@redux-devtools/serialize/lib/immutable/serialize';
import { import {
@ -9,13 +8,6 @@ import Immutable from 'immutable';
import { LiftedState } from '@redux-devtools/instrument'; import { LiftedState } from '@redux-devtools/instrument';
import { Action } from 'redux'; import { Action } from 'redux';
function deprecate(param: string) {
// eslint-disable-next-line no-console
console.warn(
`\`${param}\` parameter for Redux DevTools Extension is deprecated. Use \`serialize\` parameter instead: https://github.com/zalmoxisus/redux-devtools-extension/releases/tag/v2.12.1`
);
}
interface SerializeWithRequiredImmutable extends SerializeWithImmutable { interface SerializeWithRequiredImmutable extends SerializeWithImmutable {
readonly immutable: typeof Immutable; readonly immutable: typeof Immutable;
} }
@ -43,7 +35,7 @@ interface ParsedSerializedLiftedState {
export default function importState<S, A extends Action<unknown>>( export default function importState<S, A extends Action<unknown>>(
state: string | undefined, state: string | undefined,
{ deserializeState, deserializeAction, serialize }: Config { serialize }: Config
) { ) {
if (!state) return undefined; if (!state) return undefined;
let parse = jsan.parse; let parse = jsan.parse;
@ -82,35 +74,6 @@ export default function importState<S, A extends Action<unknown>>(
unknown unknown
>) >)
: parsedSerializedLiftedState; : parsedSerializedLiftedState;
if (deserializeState) {
deprecate('deserializeState');
if (typeof nextLiftedState.computedStates !== 'undefined') {
nextLiftedState.computedStates = nextLiftedState.computedStates.map(
(computedState) => ({
...computedState,
state: deserializeState(computedState.state),
})
);
}
if (typeof nextLiftedState.committedState !== 'undefined') {
nextLiftedState.committedState = deserializeState(
nextLiftedState.committedState
);
}
if (typeof preloadedState !== 'undefined') {
preloadedState = deserializeState(preloadedState);
}
}
if (deserializeAction) {
deprecate('deserializeAction');
nextLiftedState.actionsById = mapValues(
nextLiftedState.actionsById,
(liftedAction) => ({
...liftedAction,
action: deserializeAction(liftedAction.action),
})
);
}
return { nextLiftedState, preloadedState }; return { nextLiftedState, preloadedState };
} }

View File

@ -76,10 +76,7 @@ export interface Serialize {
readonly options?: Options | boolean; readonly options?: Options | boolean;
} }
export function getSerializeParameter( export function getSerializeParameter(config: Config) {
config: Config,
param?: 'serializeState' | 'serializeAction'
) {
const serialize = config.serialize; const serialize = config.serialize;
if (serialize) { if (serialize) {
if (serialize === true) return { options: true }; if (serialize === true) return { options: true };
@ -109,16 +106,7 @@ export function getSerializeParameter(
}; };
} }
const value = config[param!]; return undefined;
if (typeof value === 'undefined') return undefined;
// eslint-disable-next-line no-console
console.warn(
`\`${param}\` parameter for Redux DevTools Extension is deprecated. Use \`serialize\` parameter instead: https://github.com/zalmoxisus/redux-devtools-extension/releases/tag/v2.12.1`
);
if (typeof value === 'boolean') return { options: value };
if (typeof value === 'function') return { replacer: value };
return value;
} }
interface InitInstancePageScriptToContentScriptMessage { interface InitInstancePageScriptToContentScriptMessage {

View File

@ -37,10 +37,6 @@ export default function configureStore<
shouldStartLocked: config.shouldStartLocked, shouldStartLocked: config.shouldStartLocked,
pauseActionType: config.pauseActionType || '@@PAUSED', pauseActionType: config.pauseActionType || '@@PAUSED',
}), }),
persistState( persistState(getUrlParam('debug_session'))
getUrlParam('debug_session'),
config.deserializeState,
config.deserializeAction
)
)(next); )(next);
} }

View File

@ -95,14 +95,6 @@ export interface ConfigWithExpandedMaxAge {
readonly actionsDenylist?: string | readonly string[]; readonly actionsDenylist?: string | readonly string[];
readonly actionsAllowlist?: string | readonly string[]; readonly actionsAllowlist?: string | readonly string[];
serialize?: boolean | SerializeWithImmutable; serialize?: boolean | SerializeWithImmutable;
readonly serializeState?:
| boolean
| ((key: string, value: unknown) => unknown)
| Serialize;
readonly serializeAction?:
| boolean
| ((key: string, value: unknown) => unknown)
| Serialize;
readonly statesFilter?: <S>(state: S, index?: number) => S; readonly statesFilter?: <S>(state: S, index?: number) => S;
readonly actionsFilter?: <A extends Action<unknown>>( readonly actionsFilter?: <A extends Action<unknown>>(
action: A, action: A,
@ -134,8 +126,6 @@ export interface ConfigWithExpandedMaxAge {
readonly shouldRecordChanges?: boolean; readonly shouldRecordChanges?: boolean;
readonly shouldStartLocked?: boolean; readonly shouldStartLocked?: boolean;
readonly pauseActionType?: unknown; readonly pauseActionType?: unknown;
readonly deserializeState?: <S>(state: S) => S;
readonly deserializeAction?: <A extends Action<unknown>>(action: A) => A;
name?: string; name?: string;
readonly autoPause?: boolean; readonly autoPause?: boolean;
readonly features?: Features; readonly features?: Features;
@ -210,8 +200,8 @@ function __REDUX_DEVTOOLS_EXTENSION__<S, A extends Action<unknown>>(
let sendingActionId = 1; let sendingActionId = 1;
const instanceId = generateId(config.instanceId); const instanceId = generateId(config.instanceId);
const localFilter = getLocalFilter(config); const localFilter = getLocalFilter(config);
const serializeState = getSerializeParameter(config, 'serializeState'); const serializeState = getSerializeParameter(config);
const serializeAction = getSerializeParameter(config, 'serializeAction'); const serializeAction = getSerializeParameter(config);
let { let {
statesFilter, statesFilter,
actionsFilter, actionsFilter,

View File

@ -183,7 +183,6 @@ describe('Redux enhancer', () => {
window.__REDUX_DEVTOOLS_EXTENSION__({ window.__REDUX_DEVTOOLS_EXTENSION__({
actionsDenylist: ['SOME_ACTION'], actionsDenylist: ['SOME_ACTION'],
statesFilter: (state) => state, statesFilter: (state) => state,
serializeState: (key, value) => value,
}) })
); );
expect(typeof window.store).toBe('object'); expect(typeof window.store).toBe('object');

View File

@ -1,4 +1,3 @@
import mapValues from 'lodash/mapValues';
import jsan from 'jsan'; import jsan from 'jsan';
import { immutableSerialize } from '@redux-devtools/serialize'; import { immutableSerialize } from '@redux-devtools/serialize';
import { Action } from 'redux'; import { Action } from 'redux';
@ -11,23 +10,11 @@ interface State {
committedState?: unknown; committedState?: unknown;
} }
function deprecate(param: string) {
// eslint-disable-next-line no-console
console.warn(
`\`${param}\` parameter for Redux DevTools Extension is deprecated. Use \`serialize\` parameter instead:` +
' https://github.com/zalmoxisus/redux-devtools-extension/releases/tag/v2.12.1'
);
}
export default function importState( export default function importState(
state: string, state: string,
{ {
deserializeState,
deserializeAction,
serialize, serialize,
}: { }: {
deserializeState?: (state: string) => unknown;
deserializeAction?: (action: string) => Action<unknown>;
serialize?: { serialize?: {
immutable?: typeof Immutable; immutable?: typeof Immutable;
refs?: (new (data: any) => unknown)[] | null; refs?: (new (data: any) => unknown)[] | null;
@ -83,37 +70,6 @@ export default function importState(
).payload ).payload
) as State; ) as State;
} }
if (deserializeState) {
deprecate('deserializeState');
if (typeof nextLiftedState.computedStates !== 'undefined') {
nextLiftedState.computedStates = nextLiftedState.computedStates.map(
(computedState) => ({
...computedState,
state: deserializeState(computedState.state as string),
})
);
}
if (typeof nextLiftedState.committedState !== 'undefined') {
nextLiftedState.committedState = deserializeState(
nextLiftedState.committedState as string
);
}
if (typeof preloadedState !== 'undefined') {
preloadedState = deserializeState(
preloadedState as unknown as string
) as State;
}
}
if (deserializeAction) {
deprecate('deserializeAction');
nextLiftedState.actionsById = mapValues(
nextLiftedState.actionsById,
(liftedAction) => ({
...liftedAction,
action: deserializeAction(liftedAction.action as unknown as string),
})
);
}
return { nextLiftedState, preloadedState }; return { nextLiftedState, preloadedState };
} }