tweaking id management...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-02-28 20:30:41 +03:00
parent fa4c7737f9
commit 1064cb79b3

View File

@ -395,15 +395,21 @@ var BaseBrowserPrototype = {
&& Date.now()) && Date.now())
|| JSON.stringify(value) || JSON.stringify(value)
// handle duplicate ids -> err if found...
if(opts.id && opts.id in new_index){
throw new Error(`make(..): duplicate id "${key}": `
+`can't create multiple items with the same key.`) }
// handle duplicate keys...
var k = key var k = key
while(k in new_index){ while(k in new_index){
// no duplicate keys... // duplicate keys disabled...
if(options.noDuplicateValues){ if(options.noDuplicateValues){
throw new Error(`make(..): duplicate key "${key}": ` throw new Error(`make(..): duplicate key "${key}": `
+`can't create multiple items with the same key.`) } +`can't create multiple items with the same key.`) }
// create a new key... // create a new key...
k = k +' '+ Date.now() k = key +' '+ Date.now()
} }
key = opts.id = k key = opts.id = k