feat: 🎸 Update how we store tokens in indexed-db (#2223)
Added logic to make the list tokens stored in indexed DB more granular. I get a hash of the query parameters that will get sent to the controller and use that as the id for the token. This also means extra logic for when a token is invalid as we will need to delete all tokens of the same resource type.
This commit is contained in:
1 parent
6c59baa413
commit
5d32d987bc
13 files changed
+121
-33
No files matched your search
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Takes an object and gets the JSON stringified version of it to be converted
|
||||
* to a hash code. Taken from https://stackoverflow.com/a/8076436
|
||||
* @param obj
|
||||
*/
|
||||
export const hashCode = (obj) => {
|
||||
if (!obj) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Use a replacer function to sort the keys of the object so we get the same hashcode
|
||||
// regardless of the order of the keys.
|
||||
const jsonString = JSON.stringify(obj, Object.keys(obj).sort());
|
||||
|
||||
let hash = 0;
|
||||
for (let i = 0; i < jsonString.length; i++) {
|
||||
let code = jsonString.charCodeAt(i);
|
||||
hash = (hash << 5) - hash + code;
|
||||
hash = hash & hash; // Convert to 32bit integer
|
||||
}
|
||||
|
||||
// Make sure the hash is positive since we're using it as an ID
|
||||
return Math.abs(hash);
|
||||
};
|
||||
Reference in new issue
Block a user