Consider combining arrayToString and combineTerms transforms

Description

The two custom transforms "sjrk.storyTelling.transforms.arrayToString" and "sjrk.storyTelling.transforms.combineTerms" are very similar in function and purpose. Consider a way to combine them to make code DRYer.

Activity

Show:

Gregor Moss June 12, 2018 at 7:58 PM

The arrayToString transform function now has the body of the former combineTerms function, and the latter has been removed. All references to combineTerms have been updated to call arrayToString transform instead, and tests were updated. This is actually quite an improvement and test coverage automagically increased!

Gregor Moss June 12, 2018 at 7:09 PM
Edited

These two transform functions do very similar but distinct tasks.

arrayToString simply calls array.join() (docs here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)

which will first attempt to convert the object to a string value, and then concats it to the end of the resulting string. This includes falsy values like "", and false.

combineTerms, on the other hand, takes into account a couple of extra parameters. a "path" can be specified so that inner elements of the top-level array items can be accessed and combined. Perhaps that's something more appropriately done by the map function... Anyway, it also checks each value before adding it and will only add it if it's truthy.

If we want to combine these two funcitons, then we need to add an extra parameter for specifying whether to omit values based on their truthiness.

Done

Details

Assignee

Reporter

Components

Priority

Created May 31, 2018 at 10:29 PM
Updated June 12, 2018 at 7:58 PM
Resolved June 12, 2018 at 7:58 PM