From 7f24cab7ddb7715ffa4fe16ab8d7b5aa2ec8356e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=AE=D1=80=D0=B0=20=D0=9F=D0=B0=D0=BD=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=BD?= Date: Tue, 13 Feb 2018 18:39:08 +0100 Subject: [PATCH] add uniq Map for generated ID (#3644) --- uniqueId.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/uniqueId.js b/uniqueId.js index 16909062d..c8072dbc0 100644 --- a/uniqueId.js +++ b/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}` }