minor refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-03-01 00:40:16 +03:00
parent 1064cb79b3
commit 3523b8b61e

View File

@ -385,21 +385,28 @@ var BaseBrowserPrototype = {
opts) opts)
: opts : opts
// item id...
// XXX do a better id... // XXX do a better id...
var makeID = function(id){
// id prefix...
return (id || '')
// separator...
+ (id && ' ')
// date...
+ Date.now() }
// item id...
// XXX should these include the path??? // XXX should these include the path???
var key = opts.id var key = opts.id
// value is a browser -> generate an unique id... // value is a browser -> generate an unique id...
// XXX identify via structure... // XXX identify via structure...
|| (value instanceof Browser || (value instanceof Browser
&& Date.now()) && makeID())
|| JSON.stringify(value) || JSON.stringify(value)
// handle duplicate ids -> err if found... // handle duplicate ids -> err if found...
if(opts.id && opts.id in new_index){ if(opts.id && opts.id in new_index){
throw new Error(`make(..): duplicate id "${key}": ` throw new Error(`make(..): duplicate id "${key}": `
+`can't create multiple items with the same key.`) } +`can't create multiple items with the same key.`) }
// handle duplicate keys... // handle duplicate keys...
var k = key var k = key
while(k in new_index){ while(k in new_index){
@ -407,9 +414,8 @@ var BaseBrowserPrototype = {
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 = key +' '+ Date.now() k = makeID(key)
} }
key = opts.id = k key = opts.id = k