Have you ever needed to prune an order line? Y'know, prune them. This is an entirely common operation you do on orders all the time, and requires absolutely no context or explanation. There's absolutely no chance that you might need to wonder, exactly what is being pruned.
Bartholomew A. was a little bit confused by the prune
method in the codebase. Fortunately, reading through the code makes everything clear:
// Prune
// @param d - Expects 'd' to be OrderDetails Line Item Row
prune = (function prune(d, re) {
var z = [],
y = [],
out = [],
sub = {};
if (Object.prototype.toString.call(re) != "[Object String]") {
re = "SubLines";
match = { 'SubLines': [] };
} else {
match[re] = [];
}
// Get the SubLines
out = _.filter(d, _.matches(match, false));
_.each(out, function (i) {
var x;
x = _.pick(i, [re]);
[].push.apply(y, x.SubLines);
});
// trim it down to just Tracking
_.each(y, function (value, key) {
if (!_.has(value, 'Tracking')) {
return false;
}
z = [].concat.apply(z, value.Tracking);
});
// return some data
return z;
});
There, that clears everything up. Now you know what pruning is, and I hope you can explain it to me, because I'm pretty confused. If the input parameter d
is actually just a "Line Item Row" why are we filter
ing it? Is this using the "lodash" library, and if so, have they hacked the matches
method, because according to the docs, it doesn't take a boolean parameter. Maybe it did in an old version?
I think that by the end of this, it will return an array of all of the tracking information for every sub-line on this order-line, which I have to admit, I've worked on a lot of order management systems, and we never broke line items up into sub-lines, because the whole point of a line item was that it was the atom of your order, but sure, whatever.
Bartholomew provides more context:
I saved this from a few years ago at a company where I used to work. It sits in a 3,000 line AngularJS file at no particular level of abstraction. It involves order lines and sublines, which indicates that it relates to the business entities displayed on the screen, and then it "prunes" them. I have no idea what that means, but if this doesn't get executed something doesn't work.
This file just grew larger and larger. There were no unit tests. Something was always broken and the answer was always adding more and more code…