mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
bare .walk2(..) working...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d47af07fd9
commit
ac89db2c83
@ -1346,6 +1346,8 @@ var BaseBrowserPrototype = {
|
|||||||
// {
|
// {
|
||||||
// value: ...,
|
// value: ...,
|
||||||
//
|
//
|
||||||
|
// children: ...,
|
||||||
|
//
|
||||||
// ...
|
// ...
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
@ -1917,15 +1919,62 @@ var BaseBrowserPrototype = {
|
|||||||
|
|
||||||
|
|
||||||
// XXX EXPERIMENTAL -- an attempt to simplify walking...
|
// XXX EXPERIMENTAL -- an attempt to simplify walking...
|
||||||
|
//
|
||||||
|
// .walk(func, options)
|
||||||
|
// -> res???
|
||||||
|
//
|
||||||
|
// func(elem, i, path, next(..), stop())
|
||||||
|
// -> res???
|
||||||
|
//
|
||||||
walk2: function(func, options){
|
walk2: function(func, options){
|
||||||
return this.items
|
var that = this
|
||||||
.map(function(elem){
|
|
||||||
return elem instanceof BaseBrowser ?
|
var res
|
||||||
: elem instanceof BaseItem ?
|
var Stop = new Error('walk2(..): Stop walk.')
|
||||||
: elem.children ?
|
var stop = function(res){ throw stop }
|
||||||
: elem
|
|
||||||
})
|
try {
|
||||||
.flat() },
|
var map
|
||||||
|
return this.items
|
||||||
|
.map(map = function(elem){
|
||||||
|
// XXX
|
||||||
|
var i = 0
|
||||||
|
var path = []
|
||||||
|
|
||||||
|
var children = (elem instanceof BaseBrowser
|
||||||
|
|| elem instanceof Array) ?
|
||||||
|
elem
|
||||||
|
: (elem.children || [])
|
||||||
|
|
||||||
|
var next = function(elems){
|
||||||
|
children = elems == null ?
|
||||||
|
[]
|
||||||
|
: elems }
|
||||||
|
return [
|
||||||
|
// item...
|
||||||
|
// XXX should we call func(..) on inlined sections???
|
||||||
|
// i.e. when elem instanceof Array || elem instanceof BaseBrowser ???
|
||||||
|
// ...should this be an option???
|
||||||
|
...[(elem instanceof Array || elem instanceof BaseBrowser) ?
|
||||||
|
[]
|
||||||
|
// XXX should that be root call context or the local call context???
|
||||||
|
: func.call(that, elem, i, path, next, stop) || []].flat(),
|
||||||
|
// children...
|
||||||
|
...children instanceof Array ?
|
||||||
|
children
|
||||||
|
.map(map)
|
||||||
|
.flat()
|
||||||
|
: children instanceof BaseBrowser ?
|
||||||
|
children
|
||||||
|
.walk2(func, options)
|
||||||
|
: [] ] })
|
||||||
|
.flat()
|
||||||
|
|
||||||
|
// handle Stop and errors...
|
||||||
|
} catch(e){
|
||||||
|
if(e === Stop){
|
||||||
|
return res }
|
||||||
|
throw e } },
|
||||||
|
|
||||||
|
|
||||||
// Data access and iteration...
|
// Data access and iteration...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user