renamed .iter(..) to .map(..)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-03-12 23:03:53 +03:00
parent db4758bddc
commit 9de887fd9b
2 changed files with 29 additions and 12 deletions

View File

@ -455,12 +455,23 @@ nw-run: dev
##------------------------------------------------------------- deb --- ##----------------------------------------------- Windows installer ---
# XXX # XXX
##----------------------------------------------------- Deb package ---
# XXX
##----------------------------------------------------- CLI package ---
# XXX
#********************************************************************** #**********************************************************************
### Dependency checking... ### Dependency checking...

View File

@ -734,7 +734,7 @@ var BaseBrowserPrototype = {
if(typeof(key) == typeof(123)){ if(typeof(key) == typeof(123)){
// XXX this needs to return as soon as we find an item and // XXX this needs to return as soon as we find an item and
// not construct the whole list... // not construct the whole list...
return this.iter()[key] return this.map()[key]
// key... // key...
// XXX account for paths... // XXX account for paths...
@ -764,10 +764,12 @@ var BaseBrowserPrototype = {
}, },
// Extended map...
// //
// .iter([options]) // Generic map...
// .iter(func[, options]) // .map([options])
// .iter(func, path[, options]) // .map(func[, options])
// .map(func, path[, options])
// -> items // -> items
// //
// options format: // options format:
@ -789,11 +791,16 @@ var BaseBrowserPrototype = {
// - collapsed sub-items (item.collapsed is true) // - collapsed sub-items (item.collapsed is true)
// //
// //
// This extends the Array .map(..) by adding:
// - ability to run without arguments
// - support for options
//
//
// 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???)
// XXX rename this to .items... (???) // XXX rename this to .items(..), or is this a .map(..) (???)
iter: function(func, path, options){ map: function(func, path, options){
var that = this var that = this
// parse args... // parse args...
@ -814,7 +821,7 @@ var BaseBrowserPrototype = {
var doElem = function(elem){ var doElem = function(elem){
return [func ? return [func ?
func.call(that, elem, path.concat(elem.id)) func.call(that, elem, path.concat(elem.id), that)
: elem] } : elem] }
return this.items return this.items
@ -825,7 +832,7 @@ var BaseBrowserPrototype = {
[] []
// value is Browser (inline) -- list browser items... // value is Browser (inline) -- list browser items...
: elem.value instanceof Browser ? : elem.value instanceof Browser ?
elem.value.iter(func, elem.value.map(func,
options.inlinedPaths ? options.inlinedPaths ?
path.concat(elem.id) path.concat(elem.id)
: path.slice(), : path.slice(),
@ -836,7 +843,7 @@ var BaseBrowserPrototype = {
doElem(elem) doElem(elem)
.concat((!iterateCollapsed && elem.collapsed) ? .concat((!iterateCollapsed && elem.collapsed) ?
[] []
: elem.sublist.iter(func, path.concat(elem.id), options)) : elem.sublist.map(func, path.concat(elem.id), options))
// .sublist is Array (nested) -- list header then array content... // .sublist is Array (nested) -- list header then array content...
: (!skipNested : (!skipNested
&& elem.sublist instanceof Array) ? && elem.sublist instanceof Array) ?
@ -846,7 +853,7 @@ var BaseBrowserPrototype = {
: (func ? : (func ?
elem.sublist elem.sublist
.map(function(e){ .map(function(e){
return func.call(that, e, path.concat(elem.id, e.id)) }) return func.call(that, e, path.concat(elem.id, e.id), that) })
: elem.sublist.slice())) : elem.sublist.slice()))
// normal item -- list... // normal item -- list...
: doElem(elem) ) }) : doElem(elem) ) })
@ -867,7 +874,6 @@ var BaseBrowserPrototype = {
// XXX should there return an array or a .constructor(..) instance?? // XXX should there return an array or a .constructor(..) instance??
forEach: function(){}, forEach: function(){},
map: function(){},
filter: function(){}, filter: function(){},
reduce: function(){}, reduce: function(){},