by moritzwarhier · 1w ago · 0 comments
And obviously, this is a design pattern that fits when a suitable supertype exists or xan be easily defined.
Thus, void methods are already fit for pretty much the same interface, and everything with a return value that shouldn't be of the type of that specific god-interface, doesn't fit well into a fluent interface, e.g. count().
You can be insistent on the pattern and make count() return `this` instead of a number, but that's where the pattern becomes blurry.
When I started web dev, fluent interfaces were everywhere, and the motivations, thinking about it, seem to converge about another, different thing: lazy evaluation.
This is what jQuery has in common with ORMs, I'd guess.
The development experience isn't even the most important thing, it's providing an abstraction between executing a query (hence jQuery) and chaining selectors.
Natrowing down snapshots is completely different from chaining selectors, and this is the common aspect between an ORM and a library working on the DOM.
Where it starts to feel icky, in both cases, is, when mutations are involved.
Then you have potential for confusion around when these mutations are commited.
In other words, since jQuery collections are, well not "live", like getElementsByTagName, also not snapshots, like querySelectorAll is (snapshot regarding the reference, not what it points at, of course).
jQuery combined the best of both worlds for many everyday applications.
But mentally working through an applications with complex mutations only was fun if your colleagues were disciplined.
jQuery "soup" when using many mutations, leveraging the DOM as a snychronized shared state, and mixing in some confusing closures anf loops, was also real.
I admire jQuery, but also don't miss debugging half-working giant files. Not a library issue, you can have similar issues with any library when working on dynamic frontend state.
Circling back to the point: I'm not sure whether a fluent interface is ideal for DOM manipulation.
But in any case, jQuery was used way beyond "DOM library". It was almost synonymous with "JavaScript" at some point, and putting huge blocks of imperative domain logic nested 5 closures deep into some event callback was an issue with jQuery just as it is an issue with React right now.
Same story, different day.
No comments yet.