mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
cleaning up make(..) api...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
07d6e8dba9
commit
0e569b6261
@ -299,18 +299,35 @@ var BaseBrowserPrototype = {
|
|||||||
//
|
//
|
||||||
// make(value)
|
// make(value)
|
||||||
// make(value, options)
|
// make(value, options)
|
||||||
|
// make(value, func[, options])
|
||||||
// -> make
|
// -> make
|
||||||
//
|
//
|
||||||
var make_called = false
|
var make_called = false
|
||||||
var make = function(value, opts){
|
var make = function(value, opts){
|
||||||
make_called = true
|
make_called = true
|
||||||
|
var args = [...arguments]
|
||||||
|
|
||||||
opts = opts || {}
|
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 revise id generation...
|
||||||
// XXX check if id already exists and complain if it
|
// XXX these should include the path...
|
||||||
// does -- only for options.id???
|
|
||||||
var key = opts.id || JSON.stringify(value)
|
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...
|
// build the item...
|
||||||
var item = Object.assign({},
|
var item = Object.assign({},
|
||||||
// get the old item values...
|
// get the old item values...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user