cleaning up make(..) api...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-02-20 16:56:36 +03:00
parent 07d6e8dba9
commit 0e569b6261

View File

@ -299,18 +299,35 @@ var BaseBrowserPrototype = {
//
// make(value)
// make(value, options)
// make(value, func[, options])
// -> make
//
var make_called = false
var make = function(value, opts){
make_called = true
var args = [...arguments]
opts = opts || {}
// handle: make(.., func, ..)
opts = opts instanceof Function ?
{open: opts}
: opts
// handle trailing options...
opts = args.length > 2 ?
Object.assign({},
args.pop(),
opts)
: opts
// XXX revise id generation...
// XXX check if id already exists and complain if it
// does -- only for options.id???
// XXX these should include the path...
var key = opts.id || JSON.stringify(value)
// no duplicate keys...
if(key in new_index){
throw new Error(`make(..): duplicate key "${key}": `
+`can't create multiple items with the same key.`) }
// build the item...
var item = Object.assign({},
// get the old item values...