updated generic-walk + .walk2(..) now fully works...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-05-04 15:46:04 +03:00
parent dffd66a8ae
commit 6e05be9fee
3 changed files with 119 additions and 78 deletions

View File

@ -779,20 +779,45 @@ var BaseBrowserPrototype = {
},
//
// .walk2()
// -> list
//
// .walk2(func[, options])
// .walk2(func, recursion[, options])
// .walk2(func, recursion, walkable[, options])
// -> list
//
//
// func(node, index, path, next(..), stop(..), children)
// -> list
//
// next(children)
// -> list
//
// stop(result)
//
//
// recursion(func(..), stop(..), index, path, children, options)
// -> list
//
//
// walkable(node)
// -> bool
//
//
// 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...
// XXX this uses a slightly different signature to func(..) that .walk(..) does...
// XXX can this be simpler???
walk2: function(func, recursion, walkable, options){
var that = this
// parse args...
var args = [...arguments]
func = args[0] instanceof Function ?
func = (args[0] instanceof Function
|| args[0] == null) ?
args.shift()
: undefined
var recursion = (args[0] instanceof Function
@ -806,17 +831,18 @@ var BaseBrowserPrototype = {
: null
options = args.shift() || {}
// threaded args...
// recursion-threaded args...
var i = args.shift() || 0
var path = args.shift() || []
var stopParent = args.shift() || null
// options specifics...
options = !options.root ?
Object.assign({},
this.options,
this.options || {},
options,
// set call context...
{root: this})
{ root: this })
: options
var iterateNonIterable = options.iterateAll || options.iterateNonIterable
var iterateCollapsed = options.iterateAll || options.iterateCollapsed
@ -855,11 +881,12 @@ var BaseBrowserPrototype = {
return (list === false ?
[]
: list instanceof Array ?
// NOTE: this gets the path and i from context...
next('do', state, ...(reverse ? list.slice().reverse() : list))
// user-defined recursion...
: recursion instanceof Function ?
recursion.call(that, func, i, p, list, options)
: list[recursion || 'walk2'](func, recursion, walkable, options, i, p))
recursion.call(that, func, stop, i, p, list, options)
: list.walk2(func, recursion, walkable, options, i, p, stop))
.run(function(){
// normalize...
nested = this instanceof Array ?
@ -896,12 +923,14 @@ var BaseBrowserPrototype = {
&& doNested()
// element...
state.splice(state.length, 0,
...[func.call(that,
...[ func ?
(func.call(that,
...(inline ? [null, i] : [node, i++]),
p,
doNested,
stop,
children) || []])
children) || [])
: [node] ])
// normal order -> do children...
children
&& (doNested(),
@ -911,8 +940,14 @@ var BaseBrowserPrototype = {
return state
},
// normalize the root result...
function(state){
return options.root === that ?
function(state, mode){
// if we stopped, thread the stop up...
mode == 'stopped'
&& stopParent instanceof Function
&& stopParent(state)
// normalize the result...
return (options.root === that
&& state instanceof Array) ?
state.flat()
: state },
[],

View File

@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"@types/node": {
"version": "10.12.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.18.tgz",
"integrity": "sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ=="
"version": "10.14.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.14.6.tgz",
"integrity": "sha512-Fvm24+u85lGmV4hT5G++aht2C5I4Z4dYlWZIh62FAfFO/TfzXtPpoLI6I7AuBWkIFqZCnhFOoTT7RjjaIL5Fjg=="
},
"ajv": {
"version": "6.6.1",
@ -147,11 +147,6 @@
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"builtin-modules": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
"integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8="
},
"camelcase": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-2.1.1.tgz",
@ -227,9 +222,9 @@
}
},
"commander": {
"version": "2.19.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz",
"integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg=="
"version": "2.20.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz",
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ=="
},
"concat-map": {
"version": "0.0.1",
@ -285,11 +280,11 @@
}
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"requires": {
"ms": "2.0.0"
"ms": "^2.1.1"
}
},
"decamelize": {
@ -335,9 +330,9 @@
}
},
"electron": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/electron/-/electron-4.0.1.tgz",
"integrity": "sha512-kBWDLn1Vq8Tm6+/HpQc8gkjX7wJyQI8v/lf2kAirfi0Q4cXh6vBjozFvV1U/9gGCbyKnIDM+m8/wpyJIjg4w7g==",
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-4.2.0.tgz",
"integrity": "sha512-bn41xAekJ8h4QfMwmlsL3Qx1xUloTwVHBEKRg8hGDhecfdPgDdps60gfoZOhdL88avimahrP01Bd7Aijsyywdg==",
"requires": {
"@types/node": "^10.12.18",
"electron-download": "^4.1.0",
@ -451,6 +446,11 @@
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},
@ -1071,9 +1071,9 @@
}
},
"generic-walk": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/generic-walk/-/generic-walk-1.3.1.tgz",
"integrity": "sha512-SWKd/3pnz4214suNn0+0hsfJmHkEoXXnU+oX2XtdmcCqOc8IzkioOry54cbp2Mvydvk0/3ebA2i0mqF5X7o/Ag=="
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/generic-walk/-/generic-walk-1.4.0.tgz",
"integrity": "sha512-xeU2id9PsCDO2Q+96sAQ0BItpTa5or2xFtQTTKVTqxJ/rpo4DGLAk/uNwZQJMUd5B48lccDqqGNh1ndbctF03g=="
},
"get-stdin": {
"version": "4.0.1",
@ -1222,14 +1222,6 @@
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz",
"integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ=="
},
"is-builtin-module": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz",
"integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=",
"requires": {
"builtin-modules": "^1.0.0"
}
},
"is-finite": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz",
@ -1351,13 +1343,6 @@
"pify": "^2.0.0",
"pinkie-promise": "^2.0.0",
"strip-bom": "^2.0.0"
},
"dependencies": {
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
}
}
},
"loose-envify": {
@ -1477,14 +1462,14 @@
}
},
"moment": {
"version": "2.23.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.23.0.tgz",
"integrity": "sha512-3IE39bHVqFbWWaPOMHZF98Q9c3LDKGTmypMiTM2QygGXXElkFWIH7GxfmlwmY2vwa+wmNsoYZmG2iusf1ZjJoA=="
"version": "2.24.0",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
},
"nan": {
"version": "2.13.2",
@ -1519,12 +1504,12 @@
"integrity": "sha1-lKKxYzxPExdVMAfYlm/Q6EG2pMI="
},
"normalize-package-data": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz",
"integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==",
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz",
"integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==",
"requires": {
"hosted-git-info": "^2.1.4",
"is-builtin-module": "^1.0.0",
"resolve": "^1.10.0",
"semver": "2 || 3 || 4 || 5",
"validate-npm-package-license": "^3.0.1"
}
@ -1561,6 +1546,11 @@
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},
@ -1620,6 +1610,11 @@
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"path-parse": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw=="
},
"path-type": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz",
@ -1628,13 +1623,6 @@
"graceful-fs": "^4.1.2",
"pify": "^2.0.0",
"pinkie-promise": "^2.0.0"
},
"dependencies": {
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
}
}
},
"pend": {
@ -1658,6 +1646,11 @@
"webworkify": "^1.3.0"
}
},
"pify": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw="
},
"pinkie": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz",
@ -1920,6 +1913,14 @@
"resolved": "https://registry.npmjs.org/requirejs-plugins/-/requirejs-plugins-1.0.2.tgz",
"integrity": "sha1-aTtVidl/hZhGL8cYJjUyYqr9qDY="
},
"resolve": {
"version": "1.10.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.1.tgz",
"integrity": "sha512-KuIe4mf++td/eFb6wkaPbMDnP6kObCaEtIDuHOUED6MNUo4K670KZUHuuvYPZDxNF0WVLw49n06M2m2dXphEzA==",
"requires": {
"path-parse": "^1.0.6"
}
},
"safe-buffer": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
@ -2036,9 +2037,9 @@
}
},
"spdx-license-ids": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.3.tgz",
"integrity": "sha512-uBIcIl3Ih6Phe3XHK1NqboJLdGfwr1UN3k6wSD1dZpmPsIkb8AGNbZYJ1fOBk834+Gxy8rpfDxrS6XLEMZMY2g=="
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.4.tgz",
"integrity": "sha512-7j8LYJLeY/Yb6ACbQ7F76qy5jHkp0U6jgBfJsk97bwWlVUnUWsAgpyaCvo17h0/RQGnQ036tVDomiwoI4pDkQA=="
},
"speedometer": {
"version": "0.1.4",
@ -2123,6 +2124,11 @@
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},

View File

@ -20,18 +20,18 @@
"dependencies": {
"app-module-path": "^1.0.6",
"async-json": "0.0.2",
"commander": "^2.19.0",
"electron": "^4.0.1",
"commander": "^2.20.0",
"electron": "^4.2.0",
"exiftool": "^0.0.3",
"fs-extra": "^7.0.1",
"fs-walk": "^0.0.1",
"generic-walk": "^1.3.1",
"generic-walk": "^1.4.0",
"glob": "^7.1.3",
"guarantee-events": "^1.0.0",
"ig-actions": "^3.22.2",
"ig-features": "^3.3.4",
"ig-object": "^1.2.0",
"moment": "^2.23.0",
"moment": "^2.24.0",
"openseadragon": "^2.4.0",
"requirejs": "^2.3.6",
"requirejs-plugins": "^1.0.2",