testing generic-walk...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-05-03 19:43:22 +03:00
parent a200c41684
commit bed990372b
3 changed files with 54 additions and 2 deletions

View File

@ -3,7 +3,6 @@
* *
* *
**********************************************************************/ **********************************************************************/
var requirejs_cfg = { var requirejs_cfg = {
// XXX this does not work on direct filesystem access... // XXX this does not work on direct filesystem access...
//urlArgs: 'bust='+Date.now(), //urlArgs: 'bust='+Date.now(),
@ -20,6 +19,8 @@ var requirejs_cfg = {
'lib/actions': 'node_modules/ig-actions/actions', 'lib/actions': 'node_modules/ig-actions/actions',
'lib/features': 'node_modules/ig-features/features', 'lib/features': 'node_modules/ig-features/features',
//'lib/keyboard': './node_modules/ig-keyboard/keyboard', //'lib/keyboard': './node_modules/ig-keyboard/keyboard',
'lib/walk': 'node_modules/generic-walk/walk',
}, },
map: { map: {
'*': { '*': {
@ -31,6 +32,8 @@ var requirejs_cfg = {
'ig-features': 'lib/features', 'ig-features': 'lib/features',
//'ig-keyboard': 'lib/keyboard', //'ig-keyboard': 'lib/keyboard',
'generic-walk': 'lib/walk',
}, },
}, },
} }

View File

@ -21,6 +21,7 @@ body {
<script src="../jli.js"></script> <script src="../jli.js"></script>
<script src="../../ext-lib/require.js"></script> <script src="../../ext-lib/require.js"></script>
<script src="../../cfg/requirejs.js"></script>
<!--script src="browse-dialog.js"></script--> <!--script src="browse-dialog.js"></script-->

View File

@ -12,6 +12,10 @@ var keyboard = require('../keyboard')
var object = require('../object') var object = require('../object')
var widget = require('./widget') var widget = require('./widget')
// XXX
//var walk = require('lib/walk')
var walk = require('../../node_modules/generic-walk/walk').walk
/*********************************************************************/ /*********************************************************************/
@ -592,6 +596,7 @@ var BaseBrowserPrototype = {
// ...or abort walk and return result on user request... // ...or abort walk and return result on user request...
// XXX can this support breadth first walking??? // XXX can this support breadth first walking???
// XXX revise protocol... // XXX revise protocol...
// XXX use generic-walk.... (???)
walk: function(func, options){ walk: function(func, options){
var that = this var that = this
@ -720,7 +725,7 @@ var BaseBrowserPrototype = {
}) })
} }
// setup some context... // setup iteration context...
var inline = false var inline = false
// inline browser or array... // inline browser or array...
if(isWalkable(elem)){ if(isWalkable(elem)){
@ -775,6 +780,49 @@ var BaseBrowserPrototype = {
}, },
// XXX need to make this the same as .walk(..) from the user's
// perspective with one addition, expose the root stop(..)
// function to func...
// next steps:
// - get a feeling of this running
// - see if we need to change the API
// - either embed into .walk(..) or reimplement...
walk2: function(func, i, path, options){
i = i || 0
path = path || []
return walk(
function(state, node, next, stop){
node.value
&& console.log('---', i++, path, node.value)
return (
// inline...
node instanceof Array ?
next('do', state, ...node)
: node.walk2 instanceof Function ?
// XXX pass stop(..) to this...
state.concat(node.walk2(func, i, path, options))
// nested...
// XXX add node to state...
: node.sublist instanceof Array ?
// XXX need to update path...
next('do', state, ...node.sublist)
: node.sublist && node.sublist.walk2 instanceof Function ?
// XXX pass stop(..) to this...
state.concat(node.sublist.walk2(func, i, path.concat([node.value]), options))
: state)
},
// XXX done(..)
//function(state){ console.log('done:', state) },
[],
...this.items)
},
// Text render... // Text render...
// //
// This is mainly here for doc/debug purposes... // This is mainly here for doc/debug purposes...