Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move makeUniqueId from QueryManager.ts into @apollo/client/utilities.
- Loading branch information
Showing
4 changed files
with
12 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const prefixCounts = new Map<string, number>(); | ||
|
||
// These IDs won't be globally unique, but they will be unique within this | ||
// process, thanks to the counter, and unguessable thanks to the random suffix. | ||
export function makeUniqueId(prefix: string) { | ||
const count = prefixCounts.get(prefix) || 1; | ||
prefixCounts.set(prefix, count + 1); | ||
return `${prefix}:${count}:${Math.random().toString(36).slice(2)}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters