reworked id management...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-02-28 20:26:22 +03:00
parent 1edd5decc4
commit fa4c7737f9
2 changed files with 19 additions and 5 deletions

View File

@ -108,6 +108,8 @@ requirejs([
make.group( make.group(
make('a'), make('a'),
'b') 'b')
// XXX Q: should we show only one if multiple lines are in sequence???
make('---')
make('---') make('---')
// XXX not yet visible... // XXX not yet visible...
make('...') make('...')

View File

@ -223,7 +223,9 @@ var BaseBrowserClassPrototype = {
// XXX need a way to identify items... // XXX need a way to identify items...
var BaseBrowserPrototype = { var BaseBrowserPrototype = {
// XXX should we mix item/list options or separate them into sub-objects??? // XXX should we mix item/list options or separate them into sub-objects???
options: null, options: {
noDuplicateValues: false,
},
// //
// Format: // Format:
@ -353,6 +355,9 @@ var BaseBrowserPrototype = {
// //
// XXX revise options handling for .__list__(..) // XXX revise options handling for .__list__(..)
make: function(options){ make: function(options){
// XXX
options = options || this.options || {}
var items = this.items = [] var items = this.items = []
var old_index = this.item_index || {} var old_index = this.item_index || {}
var new_index = this.item_index = {} var new_index = this.item_index = {}
@ -390,10 +395,17 @@ var BaseBrowserPrototype = {
&& Date.now()) && Date.now())
|| JSON.stringify(value) || JSON.stringify(value)
// no duplicate keys... var k = key
if(key in new_index){ while(k in new_index){
throw new Error(`make(..): duplicate key "${key}": ` // no duplicate keys...
+`can't create multiple items with the same key.`) } if(options.noDuplicateValues){
throw new Error(`make(..): duplicate key "${key}": `
+`can't create multiple items with the same key.`) }
// create a new key...
k = k +' '+ Date.now()
}
key = opts.id = k
// build the item... // build the item...
var item = Object.assign({}, var item = Object.assign({},