fixed main functionality of .get(..), still needs work...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-03-15 14:26:53 +03:00
parent d731b03514
commit 292ba4bf2e

View File

@ -742,37 +742,41 @@ var BaseBrowserPrototype = {
// index... // index...
if(typeof(key) == typeof(123)){ if(typeof(key) == typeof(123)){
var items = this.items var items = this.items
// XXX make this an index... // XXX cache this (prop?)...
var sublists = this.sublists() var sublists = this.sublists()
.map(function(e, i){ .map(function(e, i){
return [e, i] }) return [e, i] })
.compact() .compact()
var i = 0 var i = 0
var v = 0 var nested = 0
var offset = 0 var offset = 0
// XXX BUG: getting last element returns undefined...
// to reproduce:
// dialog_1.get(22) // -> undefined, should return the last element...
do { do {
var x = key - offset + nested
// direct match... // direct match...
// XXX this is messed up on the second+ iteration... if(sublists.length == 0 || x < sublists[0][1]){
if(sublists.length == 0 || key - offset - i < sublists[0][1]){ return items[x]
return items[key - offset]
} }
// query the sublist... // query the sublist...
var [sublist, i] = sublists.shift() var [sublist, i] = sublists.shift()
nested += 1
// inlined... // inlined...
if(sublist.value instanceof Browser){ if(sublist.value instanceof Browser){
var res = sublist.value.get(key - i, true) var res = sublist.value.get(x - i, true)
// nested... // nested...
} else { } else {
var res = key - offset == 1 ? var res = x - i == 0 ?
sublist sublist
: sublist.sublist instanceof Browser ? : sublist.sublist instanceof Browser ?
sublist.sublist.get(key - i - offset, true) sublist.sublist.get(x - i - 1, true)
: sublist.sublist[key - i - offset] : sublist.sublist[x - i - 1]
// account for the header... // account for the header...
offset += 1 offset += 1
} }
@ -783,8 +787,7 @@ var BaseBrowserPrototype = {
offset += (sublist.sublist || sublist.value).length offset += (sublist.sublist || sublist.value).length
// XXX this is wrong... } while(x >= items.length)
} while(true)
return undefined return undefined