Skip to content

Commit

Permalink
perf(math): enhance getClientId
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Feb 6, 2023
1 parent f60f585 commit af42959
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions core/math/src/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,13 @@ export const hex = (bytes: Uint8Array): string => {
return str;
};

let clientId = globalThis.localStorage?.getItem('client-id');
export const getClientId = (): string => {
let uuid = localStorage.getItem('client-id');
if (uuid == null) {
uuid = random.uuid;
localStorage.setItem('client-id', uuid);
if (clientId != null) {
return clientId;
}
return uuid;
// else
clientId = random.uuid;
localStorage.setItem('client-id', clientId);
return clientId;
};

0 comments on commit af42959

Please sign in to comment.