DEV Community

Discussion on: Design pattern: JS Functional Chains

Collapse
 
ironsavior profile image
Erik Elmore

Chain style APIs are a crime against humanity. Get out now and save yourself. This other guy said it better than I can: medium.com/making-internets/why-us...

Collapse
 
nokomoko profile image
nsmokon

but the reason it's not good for lodash is because the chain style API doesn't work well as a means of composing functions

Even though I agree that using functional piping is better than method chaining, can't you just literally add a new method to the API object in this example? Besides the main complain in that medium post seems to be about being unable to do tree shaking with this pattern.

Collapse
 
patrixr profile image
Patrick R

Most of his arguments are against the lodash chain specifically, not the pattern itself.

I don't think he even believes chain style APIs are evil.

I'm not using lodash at all here. It's about the potential vanilla implementation of such pattern.

Which in itself has both good use cases and poor ones. Far from a crime :)

Collapse
 
ironsavior profile image
Erik Elmore

There is a broader wisdom to take from the post I referenced. The lesson is that method chaining as API comes at a cost in terms of design simplicity and consistency. This specific case is explained in terms of lodash chaining, but the reason it's not good for lodash is because the chain style API doesn't work well as a means of composing functions--which is fundamentally what your post is about.

Thread Thread
 
patrixr profile image
Patrick R • Edited

Not denying there are caveats to the pattern. The implementation is still interesting in my eyes.
I appreciate your second comment for the constructive details. My concern is more with click-baity titles :)