Skip to content

Commit

Permalink
Renamed "safeSerialize" to "serializeToString" and added inline comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Dec 18, 2019
1 parent 7589f9e commit 80931fb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/react-devtools-shared/src/backend/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function cleanForBridge(
}

export function copyToClipboard(value: any): void {
const safeToCopy = safeSerialize(value);
const safeToCopy = serializeToString(value);
copy(safeToCopy === undefined ? 'undefined' : safeToCopy);
}

Expand All @@ -59,8 +59,9 @@ export function copyWithSet(
return updated;
}

export function safeSerialize(data: any): string {
export function serializeToString(data: any): string {
const cache = new Set();
// Use a custom replacer function to protect against circular references.
return JSON.stringify(data, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (cache.has(value)) {
Expand Down

0 comments on commit 80931fb

Please sign in to comment.