mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 02:40:08 +00:00
minor refactoring and cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
51369ab05a
commit
dcfd4d33c5
@ -498,12 +498,15 @@ var BaseBrowserPrototype = {
|
|||||||
// -> list
|
// -> list
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
// Item handler...
|
||||||
// func(node, index, path, next(..), stop(..), children)
|
// func(node, index, path, next(..), stop(..), children)
|
||||||
// -> list
|
// -> list
|
||||||
//
|
//
|
||||||
|
// Trigger next/nested item handling...
|
||||||
// next(children)
|
// next(children)
|
||||||
// -> list
|
// -> list
|
||||||
//
|
//
|
||||||
|
// Stop handling...
|
||||||
// stop(result)
|
// stop(result)
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -578,7 +581,7 @@ var BaseBrowserPrototype = {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// NOTE: if recursion(..) is not given then .walk(..) is used to
|
// NOTE: if recursion(..) is not given then .walk(..) is used to
|
||||||
// handle nested children...
|
// handle all the nested elements (children)...
|
||||||
// NOTE: if walkable(..) is not given then we check for .walk(..)
|
// NOTE: if walkable(..) is not given then we check for .walk(..)
|
||||||
// availability...
|
// availability...
|
||||||
// NOTE: children arrays are handled internally...
|
// NOTE: children arrays are handled internally...
|
||||||
@ -672,7 +675,7 @@ var BaseBrowserPrototype = {
|
|||||||
// this can be called only once -> return cached results...
|
// this can be called only once -> return cached results...
|
||||||
if(nested !== false){
|
if(nested !== false){
|
||||||
return nested }
|
return nested }
|
||||||
|
// calling this on a node without .children is a no-op...
|
||||||
if(children == null){
|
if(children == null){
|
||||||
return [] }
|
return [] }
|
||||||
|
|
||||||
@ -745,43 +748,36 @@ var BaseBrowserPrototype = {
|
|||||||
: [false, path.concat([id]), undefined]
|
: [false, path.concat([id]), undefined]
|
||||||
|
|
||||||
if(inline && skipInlined){
|
if(inline && skipInlined){
|
||||||
return state
|
return state }
|
||||||
}
|
|
||||||
|
|
||||||
// reverse -> do children...
|
// go through the elements...
|
||||||
reverse == 'flat'
|
|
||||||
&& children
|
|
||||||
&& state.splice(state.length, 0, ...doNested())
|
|
||||||
// do element...
|
|
||||||
state.splice(state.length, 0,
|
state.splice(state.length, 0,
|
||||||
// NOTE: here we use:
|
...[
|
||||||
// [ func(..) ].flat()
|
// reverse -> do children...
|
||||||
// to normalize the return value of func to an array
|
reverse == 'flat'
|
||||||
// but this is not equivalent to:
|
&& children
|
||||||
// x instanceof Array ? x : [x]
|
&& doNested()
|
||||||
// as it creates a new array instance in all cases
|
|| [],
|
||||||
// and this is less efficient, though in most cases
|
// do element...
|
||||||
// negligibly so...
|
func ?
|
||||||
...[ func ?
|
(func.call(that,
|
||||||
(func.call(that,
|
...(inline ?
|
||||||
...(inline ?
|
[null, context.index]
|
||||||
[null, context.index]
|
: [node, context.index++]),
|
||||||
: [node, context.index++]),
|
p,
|
||||||
p,
|
// NOTE: when calling this it is the
|
||||||
// NOTE: when calling this it is the
|
// responsibility of the caller to return
|
||||||
// responsibility of the caller to return
|
// the result to be added to state...
|
||||||
// the result to be added to state...
|
doNested,
|
||||||
doNested,
|
stop,
|
||||||
stop,
|
children) || [])
|
||||||
children) || [])
|
: [node],
|
||||||
: [node] ].flat())
|
// normal order -> do children...
|
||||||
// normal order -> do children...
|
children
|
||||||
// NOTE: doNested(..) is executed only once so in reverse
|
&& nested === false
|
||||||
// the call will have no effect, but we need to
|
&& doNested()
|
||||||
// update the context...
|
|| [],
|
||||||
children
|
].flat())
|
||||||
&& nested === false
|
|
||||||
&& state.splice(state.length, 0, ...doNested())
|
|
||||||
|
|
||||||
// restore path context...
|
// restore path context...
|
||||||
children
|
children
|
||||||
@ -817,21 +813,6 @@ var BaseBrowserPrototype = {
|
|||||||
return [options, context] },
|
return [options, context] },
|
||||||
options, context)
|
options, context)
|
||||||
.join('\n') },
|
.join('\n') },
|
||||||
paths: function(options, context){
|
|
||||||
return this.walk(
|
|
||||||
function(n, i, p){
|
|
||||||
return n
|
|
||||||
&& [(options || {}).joinPaths !== false ?
|
|
||||||
p.join('/')
|
|
||||||
: p] },
|
|
||||||
'paths',
|
|
||||||
function(_, i, path, options, context){
|
|
||||||
// NOTE: for paths and indexes to be consistent between
|
|
||||||
// levels we need to thread the context on, here and
|
|
||||||
// into the base .walk(..) call below...
|
|
||||||
return [options, context] },
|
|
||||||
options, context) },
|
|
||||||
|
|
||||||
// XXX test manual recursion...
|
// XXX test manual recursion...
|
||||||
text2: function(options, context){
|
text2: function(options, context){
|
||||||
return this
|
return this
|
||||||
@ -850,6 +831,20 @@ var BaseBrowserPrototype = {
|
|||||||
return [options, context] },
|
return [options, context] },
|
||||||
options, context)
|
options, context)
|
||||||
.join('\n') },
|
.join('\n') },
|
||||||
|
paths: function(options, context){
|
||||||
|
return this.walk(
|
||||||
|
function(n, i, p){
|
||||||
|
return n
|
||||||
|
&& [(options || {}).joinPaths !== false ?
|
||||||
|
p.join('/')
|
||||||
|
: p] },
|
||||||
|
'paths',
|
||||||
|
function(_, i, path, options, context){
|
||||||
|
// NOTE: for paths and indexes to be consistent between
|
||||||
|
// levels we need to thread the context on, here and
|
||||||
|
// into the base .walk(..) call below...
|
||||||
|
return [options, context] },
|
||||||
|
options, context) },
|
||||||
|
|
||||||
// Extended map...
|
// Extended map...
|
||||||
//
|
//
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user