mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
added sync children processing to .walk2(..), only .search(..) seems to be left...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
20e6aed9c2
commit
fb35be5404
@ -724,6 +724,8 @@ var BrowserViewMixin = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// XXX if this is the common case shouldn't we set the args as defaults
|
||||||
|
// to .View(..) ???
|
||||||
var viewWrap =
|
var viewWrap =
|
||||||
function(context, lst, options){
|
function(context, lst, options){
|
||||||
return context.view(
|
return context.view(
|
||||||
@ -735,6 +737,16 @@ function(context, lst, options){
|
|||||||
options.skipNested
|
options.skipNested
|
||||||
: true,
|
: true,
|
||||||
}) }
|
}) }
|
||||||
|
|
||||||
|
// Make a View wrapper function for use in .run(..)...
|
||||||
|
//
|
||||||
|
var makeFlatRunViewWrapper =
|
||||||
|
function(context, options){
|
||||||
|
return function(){
|
||||||
|
return (options || {}).rawResults === true ?
|
||||||
|
this
|
||||||
|
: viewWrap(context, this, options) } }
|
||||||
|
|
||||||
//
|
//
|
||||||
// options format:
|
// options format:
|
||||||
// {
|
// {
|
||||||
@ -759,15 +771,6 @@ function(options){
|
|||||||
return viewWrap(this, res, options) }) }
|
return viewWrap(this, res, options) }) }
|
||||||
|
|
||||||
|
|
||||||
var makeFlatRunViewWrapper =
|
|
||||||
function(context, options){
|
|
||||||
return function(){
|
|
||||||
return (options || {}).rawResults === true ?
|
|
||||||
this
|
|
||||||
: viewWrap(context, this, options) } }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// Event system parts and helpers...
|
// Event system parts and helpers...
|
||||||
@ -1930,7 +1933,8 @@ var BaseBrowserPrototype = {
|
|||||||
return false },
|
return false },
|
||||||
|
|
||||||
|
|
||||||
// XXX EXPERIMENTAL -- an attempt to simplify walking...
|
// XXX EXPERIMENTAL -- simplifying walking...
|
||||||
|
|
||||||
// Walk the browser...
|
// Walk the browser...
|
||||||
//
|
//
|
||||||
// Get list of nodes...
|
// Get list of nodes...
|
||||||
@ -1952,10 +1956,16 @@ var BaseBrowserPrototype = {
|
|||||||
//
|
//
|
||||||
// Ignore current .children...
|
// Ignore current .children...
|
||||||
// next()
|
// next()
|
||||||
|
// -> children
|
||||||
|
//
|
||||||
|
// Force children processing synchronously...
|
||||||
|
// next(true)
|
||||||
|
// -> res
|
||||||
//
|
//
|
||||||
// Explicitly pass children to be handled...
|
// Explicitly pass children to be handled...
|
||||||
// next(browser)
|
// next(browser)
|
||||||
// next([elem, ...])
|
// next([elem, ...])
|
||||||
|
// -> input
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Stop walking (return undefined)...
|
// Stop walking (return undefined)...
|
||||||
@ -2033,8 +2043,6 @@ var BaseBrowserPrototype = {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// XXX should we implement next(true) to synchronously process the
|
|
||||||
// children and return the result to the caller???
|
|
||||||
walk2: function(func, options){
|
walk2: function(func, options){
|
||||||
var that = this
|
var that = this
|
||||||
var [func=null, options={}, path=[], context={}] = [...arguments]
|
var [func=null, options={}, path=[], context={}] = [...arguments]
|
||||||
@ -2042,6 +2050,15 @@ var BaseBrowserPrototype = {
|
|||||||
// context...
|
// context...
|
||||||
context.root = context.root || this
|
context.root = context.root || this
|
||||||
context.index = context.index || 0
|
context.index = context.index || 0
|
||||||
|
// stop...
|
||||||
|
var res, StopException
|
||||||
|
var stop = context.stop =
|
||||||
|
context.stop
|
||||||
|
|| function(r){
|
||||||
|
res = r
|
||||||
|
throw StopException }
|
||||||
|
.run(function(){
|
||||||
|
StopException = new Error('walk2(..): StopException.') })
|
||||||
|
|
||||||
// options...
|
// options...
|
||||||
options = Object.assign(
|
options = Object.assign(
|
||||||
@ -2073,16 +2090,6 @@ var BaseBrowserPrototype = {
|
|||||||
options.skipDisabledMode || 'node'
|
options.skipDisabledMode || 'node'
|
||||||
: options.skipDisabled
|
: options.skipDisabled
|
||||||
|
|
||||||
// stopping mechanics...
|
|
||||||
var res, StopException
|
|
||||||
var stop = context.stop =
|
|
||||||
context.stop
|
|
||||||
|| function(r){
|
|
||||||
res = r
|
|
||||||
throw StopException }
|
|
||||||
.run(function(){
|
|
||||||
StopException = new Error('walk2(..): StopException.') })
|
|
||||||
|
|
||||||
// item handler generator...
|
// item handler generator...
|
||||||
var makeMap = function(path){
|
var makeMap = function(path){
|
||||||
return function(elem){
|
return function(elem){
|
||||||
@ -2098,17 +2105,14 @@ var BaseBrowserPrototype = {
|
|||||||
path.concat(elem.id)
|
path.concat(elem.id)
|
||||||
: p
|
: p
|
||||||
var item
|
var item
|
||||||
// NOTE: this will handle the item once and then re-return its value...
|
// NOTE: this will process the value once then return the cached value...
|
||||||
var getItem = function(){
|
var processItem = function(){
|
||||||
return (item =
|
return (item =
|
||||||
item !== undefined ?
|
item !== undefined ?
|
||||||
item
|
item
|
||||||
: !skipItem && func ?
|
: !skipItem && func ?
|
||||||
[ func.call(that, elem, context.index++, p, next, stop) ].flat()
|
[ func.call(that, elem, context.index++, p, next, stop) ].flat()
|
||||||
: []) }
|
: []) }
|
||||||
// pre-call the item if reverse is not 'full'...
|
|
||||||
reverse == 'full'
|
|
||||||
|| getItem()
|
|
||||||
|
|
||||||
// children...
|
// children...
|
||||||
var children = (
|
var children = (
|
||||||
@ -2124,28 +2128,49 @@ var BaseBrowserPrototype = {
|
|||||||
: (!options.skipNested && elem.children) )
|
: (!options.skipNested && elem.children) )
|
||||||
|| []
|
|| []
|
||||||
var next = function(elems){
|
var next = function(elems){
|
||||||
children = elems == null ?
|
return (children =
|
||||||
|
// skip...
|
||||||
|
elems == null ?
|
||||||
[]
|
[]
|
||||||
: elems }
|
// force processing now...
|
||||||
|
: elems === true ?
|
||||||
|
processChildren()
|
||||||
|
// set elems as children...
|
||||||
|
: elems) }
|
||||||
|
var processed
|
||||||
|
// NOTE: this will process the value once then return the cached value...
|
||||||
|
var processChildren = function(){
|
||||||
|
return (processed =
|
||||||
|
processed !== undefined ?
|
||||||
|
processed
|
||||||
|
: children instanceof Array ?
|
||||||
|
handleReverse(children)
|
||||||
|
.map(makeMap(p))
|
||||||
|
.flat()
|
||||||
|
: children instanceof BaseBrowser ?
|
||||||
|
// NOTE: this will never return non-array as
|
||||||
|
// when stop(..) is called it will break
|
||||||
|
// execution and get handled in the catch
|
||||||
|
// clause below...
|
||||||
|
children
|
||||||
|
.walk2(func, options, p, context)
|
||||||
|
: []) }
|
||||||
|
|
||||||
|
// pre-call the item if reverse is not 'full'...
|
||||||
|
reverse == 'full'
|
||||||
|
|| processItem()
|
||||||
|
|
||||||
// build the result...
|
// build the result...
|
||||||
return [
|
return [
|
||||||
// item (normal order)...
|
// item (normal order)...
|
||||||
...!(reverse && reverse != 'tree') ?
|
...!(reverse && reverse != 'tree') ?
|
||||||
getItem()
|
processItem()
|
||||||
: [],
|
: [],
|
||||||
// children...
|
// children...
|
||||||
...children instanceof Array ?
|
...processChildren(),
|
||||||
handleReverse(children)
|
|
||||||
.map(makeMap(p))
|
|
||||||
.flat()
|
|
||||||
: children instanceof BaseBrowser ?
|
|
||||||
children
|
|
||||||
.walk2(func, options, p, context)
|
|
||||||
: [],
|
|
||||||
// item (in reverse)...
|
// item (in reverse)...
|
||||||
...(reverse && reverse != 'tree') ?
|
...(reverse && reverse != 'tree') ?
|
||||||
getItem()
|
processItem()
|
||||||
: [], ] } }
|
: [], ] } }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -2164,6 +2189,8 @@ var BaseBrowserPrototype = {
|
|||||||
throw e } },
|
throw e } },
|
||||||
|
|
||||||
// basic iteration...
|
// basic iteration...
|
||||||
|
// NOTE: we do not inherit options from this.options here as it
|
||||||
|
// will be done in .walk(..)
|
||||||
map2: function(func, options){
|
map2: function(func, options){
|
||||||
var that = this
|
var that = this
|
||||||
var args = [...arguments]
|
var args = [...arguments]
|
||||||
@ -2171,8 +2198,6 @@ var BaseBrowserPrototype = {
|
|||||||
|| args[0] == null) ?
|
|| args[0] == null) ?
|
||||||
args.shift()
|
args.shift()
|
||||||
: undefined
|
: undefined
|
||||||
// NOTE: we do not inherit options from this.options here is it
|
|
||||||
// will be done in .walk(..)
|
|
||||||
options = args.shift() || {}
|
options = args.shift() || {}
|
||||||
options = !options.defaultReverse ?
|
options = !options.defaultReverse ?
|
||||||
Object.assign({},
|
Object.assign({},
|
||||||
@ -2220,9 +2245,10 @@ var BaseBrowserPrototype = {
|
|||||||
options || {},
|
options || {},
|
||||||
{rawResults: true})) },
|
{rawResults: true})) },
|
||||||
|
|
||||||
// XXX
|
// XXX the rest of the 2'nd and 3'rd gen data access API should fall
|
||||||
|
// inline as soon as this is done...
|
||||||
|
// XXX reuse __search_test_generators__...
|
||||||
search2: function(){},
|
search2: function(){},
|
||||||
get2: function(){},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -3233,11 +3259,6 @@ var BaseBrowserPrototype = {
|
|||||||
stop([func(elem, i, path)]) },
|
stop([func(elem, i, path)]) },
|
||||||
options) ].flat()[0] },
|
options) ].flat()[0] },
|
||||||
|
|
||||||
// Sublist map functions...
|
|
||||||
// XXX this does not include inlined sections, should it???
|
|
||||||
sublists: function(func, options){
|
|
||||||
return this.search({children: true}, func, options) },
|
|
||||||
|
|
||||||
// XXX should these return an array or a .constructor(..) instance??
|
// XXX should these return an array or a .constructor(..) instance??
|
||||||
// XXX should this call .forEach(..) on nested stuff or just fall
|
// XXX should this call .forEach(..) on nested stuff or just fall
|
||||||
// back to .map(..)???
|
// back to .map(..)???
|
||||||
@ -3274,6 +3295,11 @@ var BaseBrowserPrototype = {
|
|||||||
return context.result
|
return context.result
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Sublist map functions...
|
||||||
|
// XXX this does not include inlined sections, should it???
|
||||||
|
sublists: function(func, options){
|
||||||
|
return this.search({children: true}, func, options) },
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get parent of .focused
|
// Get parent of .focused
|
||||||
// .parentOf()
|
// .parentOf()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user