Message from JavaScript discussions
February 2018
— Ahh
I can re-use how filter
reconstructs objects to parse paths into search indexes, something like this
const paths = d.paths({hello: ["friend", "grandma"]});
// parse paths into search index
const search = {};
paths.forEach(function (path, acc) {
var loc = search;
path.forEach(function (prop, acc) {
if (!prop in loc) loc[prop] = acc < path.length ? {} : null;
loc = loc[prop];
});
});
— const paths = paths(...)
? :^)
— Returns an array of arrays of paths
— Oh whoops
— Check out done
module of the strategy https://github.com/Floofies/Differentia.js/blob/master/src/strategies.js#L548
— filter
creates paths on the fly while traversing, then afterwards it parses those paths to recreate an object, very similarly to creating a search index
— Which means if I did code that, filter
would then include it as a dependency
— Since strategies often call each other so they are reusable
— Hey, wanna see how this data structure looks like?
— Sure
— Https://rawgit.com/determin1st/w3ui-demo/accordion/index.html