File tree Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Expand file tree Collapse file tree 1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -10,11 +10,28 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
10
10
*/
11
11
let idCounter = 0 ;
12
12
13
+ const PREFIXES = { } ;
14
+
13
15
// SHIM Lodash because it caches in node_modules and generates id's that are always incrementing
14
16
import _ from 'lodash' ;
15
17
16
- function uniqueId ( prefix ) {
17
- var id = ++ idCounter ;
18
- return prefix ? prefix + id : id ;
19
- }
18
+ const newCounter = prefix =>
19
+ PREFIXES [ prefix ] = 0 ;
20
+
21
+ const incCounter = prefix =>
22
+ PREFIXES [ prefix ] = PREFIXES [ prefix ] + 1 ;
23
+
24
+ const initCounterForPrefix = prefix =>
25
+ PREFIXES [ prefix ] != null
26
+ ? PREFIXES [ prefix ]
27
+ : newCounter ( prefix ) ;
28
+
29
+ const addToPrefix = prefix => {
30
+ initCounterForPrefix ( prefix ) ;
31
+ return prefix + incCounter ( prefix ) ;
32
+ } ;
33
+
34
+ const uniqueId = prefix =>
35
+ prefix ? addToPrefix ( prefix ) : idCounter ++ ;
36
+
20
37
_ . uniqueId = uniqueId ;
You can’t perform that action at this time.
0 commit comments