preparing to fold .render(..) and .map(..) together (they are too similar)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-03-20 19:13:38 +03:00
parent e414ad3eb3
commit 7422b7f0d3

View File

@ -1127,6 +1127,8 @@ var BaseBrowserPrototype = {
// generate paths: // generate paths:
// .map(func, path, options) // .map(func, path, options)
// //
// XXX this essentially repeats what .render(..) does but in a more
// complex way -- can we reuse one or the other and simplify things???
// XXX make item access by index lazy... // XXX make item access by index lazy...
// - index nested stuff and lengths... (.sublist_length) // - index nested stuff and lengths... (.sublist_length)
// - stop when target reached... (control callback???) // - stop when target reached... (control callback???)
@ -1158,6 +1160,7 @@ var BaseBrowserPrototype = {
func.call(that, elem, path.concat(elem.id), that) func.call(that, elem, path.concat(elem.id), that)
: elem] } : elem] }
var _render
return this.items return this.items
// check if we need to go from the end... // check if we need to go from the end...
// NOTE: we need to reverse two things: // NOTE: we need to reverse two things:
@ -1167,7 +1170,7 @@ var BaseBrowserPrototype = {
return reverse ? return reverse ?
this.slice().reverse() this.slice().reverse()
: this }) : this })
.map(function(elem){ .map(_render = function(elem){
return ( return (
// item not iterable -- skip... // item not iterable -- skip...
(!iterateNonIterable && elem.noniterable) ? (!iterateNonIterable && elem.noniterable) ?
@ -1198,11 +1201,15 @@ var BaseBrowserPrototype = {
doElem(elem) doElem(elem)
.concat((!iterateCollapsed && elem.collapsed) ? .concat((!iterateCollapsed && elem.collapsed) ?
[] []
/*/ XXX need to path.concat(..) in the context for this...
: elem.sublist.map(_render)).flat()
/*/
: (func ? : (func ?
elem.sublist elem.sublist
.map(function(e){ .map(function(e){
return func.call(that, e, path.concat(elem.id, e.id), that) }) return func.call(that, e, path.concat(elem.id, e.id), that) })
: elem.sublist.slice())) : elem.sublist.slice()))
//*/
// handle reverse... // handle reverse...
// XXX if we support nested browsers in lists // XXX if we support nested browsers in lists
// this will mess things up... // this will mess things up...