-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(community-pagination): adding unique keys to pagination
- Loading branch information
1 parent
1982942
commit 6eb2a96
Showing
5 changed files
with
50 additions
and
51 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
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,26 @@ | ||
import stringHash from 'string-hash' | ||
|
||
const JSONSafeStringify = input => { | ||
let cache = [] | ||
const result = JSON.stringify(input, (key, value) => { | ||
if (typeof value !== 'object' || value === null) { | ||
return value | ||
} | ||
if (cache.includes(value)) { | ||
// Circular reference found, discard key | ||
return undefined | ||
} | ||
// Store value in our collection | ||
cache.push(value) | ||
return value | ||
}) | ||
cache = null // Enable garbage collection | ||
return result | ||
} | ||
|
||
const hash = obj => { | ||
if (!obj) return 0 | ||
return typeof obj !== 'string' ? stringHash(JSONSafeStringify(obj)) : stringHash(obj) | ||
} | ||
|
||
export default hash |