Skip to content

Commit

Permalink
added external serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
salvoravida committed Sep 1, 2022
1 parent c24aa4d commit 884692d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/recoil-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recoil-toolkit",
"version": "0.2.9",
"version": "0.2.10",
"description": "recoil-toolkit",
"main": "./build/es5/index.js",
"module": "./build/es6/index.js",
Expand Down
17 changes: 10 additions & 7 deletions packages/recoil-toolkit/src/devtools/RecoilDevTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRecoilSnapshot } from 'recoil';
import { RecoilToolkitDevTools } from './consts';
import { getSnapshotState } from './getSnapshotState';

const stringifyCircularJSON = obj => {
/*const stringifyCircularJSON = obj => {
const seen = new WeakSet();
return JSON.stringify(obj, (k, v) => {
if (v !== null && typeof v === 'object') {
Expand All @@ -12,12 +12,13 @@ const stringifyCircularJSON = obj => {
}
return v;
});
};
};*/

export const RecoilDevTools: React.FC<{ enableConsole?: boolean; forceSerialize?: boolean }> = ({
enableConsole,
forceSerialize,
}) => {
export const RecoilDevTools: React.FC<{
enableConsole?: boolean;
forceSerialize?: boolean;
serializer?: (obj: any) => string;
}> = ({ enableConsole, forceSerialize, serializer }) => {
const snapshot = useRecoilSnapshot();

useEffect(() => {
Expand All @@ -33,7 +34,9 @@ export const RecoilDevTools: React.FC<{ enableConsole?: boolean; forceSerialize?
window.postMessage(
{
type: RecoilToolkitDevTools.eventMessageFromPage,
data: forceSerialize ? JSON.parse(stringifyCircularJSON(snapState)) : snapState,
data: forceSerialize
? JSON.parse(serializer ? serializer(snapState) : JSON.stringify(snapState))
: snapState,
},
'*',
);
Expand Down

0 comments on commit 884692d

Please sign in to comment.