add uniq Map for generated ID (#3644)

This commit is contained in:
Юра Панарин
2018-02-13 18:39:08 +01:00
committed by John-David Dalton
parent 54f05aa5cb
commit 7f24cab7dd

View File

@@ -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}`
}