mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-03-10 13:55:47 +03:00
This change splits out the main logic from the Redux Devtools App into a new core package but keeps the socket connection management in @redux-devtools/app. The aim is to allow for easier reuse of the rest of the app in other envioronments with their own transport methods, such as React Native or Electron.
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import jsan from 'jsan';
|
|
import { DATA_TYPE_KEY, DATA_REF_KEY } from '../constants/dataTypes';
|
|
|
|
export function reviver(key: string, value: unknown) {
|
|
if (
|
|
typeof value === 'object' &&
|
|
value !== null &&
|
|
'__serializedType__' in value &&
|
|
typeof (value as any).data === 'object'
|
|
) {
|
|
const data = (value as any).data;
|
|
data[DATA_TYPE_KEY] = (value as any).__serializedType__;
|
|
if ('__serializedRef__' in value)
|
|
data[DATA_REF_KEY] = (value as any).__serializedRef__;
|
|
/*
|
|
if (Array.isArray(data)) {
|
|
data.__serializedType__ = value.__serializedType__;
|
|
} else {
|
|
Object.defineProperty(data, '__serializedType__', {
|
|
value: value.__serializedType__
|
|
});
|
|
}
|
|
*/
|
|
return data;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
export default function parseJSON(
|
|
data: string | undefined,
|
|
serialize?: boolean,
|
|
) {
|
|
if (typeof data !== 'string') return data;
|
|
try {
|
|
return serialize ? jsan.parse(data, reviver) : jsan.parse(data);
|
|
} catch (e) {
|
|
if (process.env.NODE_ENV !== 'production')
|
|
/* eslint-disable-next-line no-console */
|
|
console.error(data + 'is not a valid JSON', e);
|
|
return undefined;
|
|
}
|
|
}
|