mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-07-16 03:02:40 +03:00
* Use rollup for d3tooltip * Use rollup for map2tree * Set moduleResolution * Use rollup for d3-state-visualizer * Use rollup for react-base16-styling * Use rollup for react-dock * Use rollup for react-json-tree * Use rollup for redux-devtools * Use rollup for redux-devtools-intrument * Use rollup for redux-devtools-chart-monitor * Update export * Use rollup for redux-devtools-dock-monitor * Use rollup for redux-devtools-inspector-monitor * Fix inspector demo * Fix invalid eslint config * Use rollup for inspector-monitor-test-tab * Use rollup for inspector-monitor-trace-tab * Use rollup for redux-devtools-log-monitor * Use rollup for redux-devtools-remote * Use rollup in redux-devtools-rtk-query-monitor * Use rollup for redux-devtools-serialize * Fix redux-devtools examples * Use rollup for redux-devtools-slider-monitor * Fix slider examples * Use rollup for redux-devtools-ui * Use rollup for redux-devtools-utils * Use rollup for redux-devtools-extension * Use rollup for redux-devtools-app * Fix Webpack app build * Fix extension build * Turn on minimization * Update CLI
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
import jsan from 'jsan';
|
|
import { immutableSerialize } from '@redux-devtools/serialize';
|
|
import {
|
|
Config,
|
|
SerializeWithImmutable,
|
|
} from '../../browser/extension/inject/pageScript';
|
|
import Immutable from 'immutable';
|
|
import { LiftedState } from '@redux-devtools/instrument';
|
|
import { Action } from 'redux';
|
|
|
|
interface SerializeWithRequiredImmutable extends SerializeWithImmutable {
|
|
readonly immutable: typeof Immutable;
|
|
}
|
|
|
|
function isSerializeWithImmutable(
|
|
serialize: boolean | SerializeWithImmutable
|
|
): serialize is SerializeWithRequiredImmutable {
|
|
return !!(serialize as SerializeWithImmutable).immutable;
|
|
}
|
|
|
|
interface SerializeWithRequiredReviver extends SerializeWithImmutable {
|
|
readonly reviver: (key: string, value: unknown) => unknown;
|
|
}
|
|
|
|
function isSerializeWithReviver(
|
|
serialize: boolean | SerializeWithImmutable
|
|
): serialize is SerializeWithRequiredReviver {
|
|
return !!(serialize as SerializeWithImmutable).immutable;
|
|
}
|
|
|
|
interface ParsedSerializedLiftedState {
|
|
readonly payload: string;
|
|
readonly preloadedState?: string;
|
|
}
|
|
|
|
export default function importState<S, A extends Action<unknown>>(
|
|
state: string | undefined,
|
|
{ serialize }: Config
|
|
) {
|
|
if (!state) return undefined;
|
|
let parse = jsan.parse;
|
|
if (serialize) {
|
|
if (isSerializeWithImmutable(serialize)) {
|
|
parse = (v) =>
|
|
jsan.parse(
|
|
v,
|
|
immutableSerialize(
|
|
serialize.immutable,
|
|
serialize.refs,
|
|
serialize.replacer,
|
|
serialize.reviver
|
|
).reviver
|
|
);
|
|
} else if (isSerializeWithReviver(serialize)) {
|
|
parse = (v) => jsan.parse(v, serialize.reviver);
|
|
}
|
|
}
|
|
|
|
const parsedSerializedLiftedState:
|
|
| ParsedSerializedLiftedState
|
|
| LiftedState<S, A, unknown> = parse(state) as
|
|
| ParsedSerializedLiftedState
|
|
| LiftedState<S, A, unknown>;
|
|
let preloadedState =
|
|
'payload' in parsedSerializedLiftedState &&
|
|
parsedSerializedLiftedState.preloadedState
|
|
? (parse(parsedSerializedLiftedState.preloadedState) as S)
|
|
: undefined;
|
|
const nextLiftedState =
|
|
'payload' in parsedSerializedLiftedState
|
|
? (parse(parsedSerializedLiftedState.payload) as LiftedState<
|
|
S,
|
|
A,
|
|
unknown
|
|
>)
|
|
: parsedSerializedLiftedState;
|
|
|
|
return { nextLiftedState, preloadedState };
|
|
}
|