mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 23:37:49 +00:00
add uniq Map for generated ID (#3644)
This commit is contained in:
committed by
John-David Dalton
parent
54f05aa5cb
commit
7f24cab7dd
14
uniqueId.js
14
uniqueId.js
@@ -1,5 +1,5 @@
|
||||
/** Used to generate unique IDs. */
|
||||
let idCounter = 0
|
||||
let idCounter = {}
|
||||
|
||||
/**
|
||||
* Generates a unique ID. If `prefix` is given, the ID is appended to it.
|
||||
@@ -17,8 +17,16 @@ let idCounter = 0
|
||||
* uniqueId()
|
||||
* // => '105'
|
||||
*/
|
||||
function uniqueId(prefix='') {
|
||||
const id = ++idCounter
|
||||
function uniqueId(prefix='$lodash$') {
|
||||
if(!idCounter[prefix]){
|
||||
idCounter[prefix] = 0
|
||||
}
|
||||
|
||||
const id =++idCounter[prefix]
|
||||
if(prefix === '$lodash$') {
|
||||
return `${id}`
|
||||
}
|
||||
|
||||
return `${prefix + id}`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user