Hacker News new | ask | show | jobs
by fabiospampinato 1748 days ago
I maintain an alternative to jQuery called Cash [0], this looks cool! If you are interested in joining forces OP it'd be cool to have this capability in Cash itself. IMO that'd be the best of both world because this feature is cool and useful, and Cash's methods are most probably closer to jQuery's, better tested and there are more of them available (76 vs 44).

For example, your `on` method [1]:

- Doesn't support event delegation.

- Doesn't support event namespaces.

- Doesn't support receiving an argument mapping events to callbacks like jQuery also can.

- It seems to have subtle bugs, like the way the events string is split makes so that double consecutive spaces in it (which can happen as a result of a typo) will result in listening to the empty string event. Basically: 'foo bar'.split ( ' ' ) => ['foo', '', 'bar'] (there are two spaces between foo and bar).

The `on` method we are using in Cash [2] is a lot more convoluted than that. On one hand it requires more bytes, but on the other the chances of it behaving exactly like jQuery's are much higher. In fact we can also run jQuery's test suite with Cash to spot issues.

Feel free to ping me if you are interested in joining forces.

[0]: https://github.com/fabiospampinato/cash

[1]: https://github.com/sachinchoolur/replace-jquery#on

[2]: https://github.com/fabiospampinato/cash/blob/master/src/even...

3 comments

Sure, Cash is super cool. I wrote this library for my personal use. As I was repeating the same work on multiple projects. While removing jQuery dependency, the hardest part was finding the jQuery methods in the existing project and writing the alternative vanilla js methods without making much changes in the codebase. Yes, I agree with you the events part needs to be improved and well documented. (It actually supports namespacing.) I fixed most of the things in https://github.com/sachinchoolur/tiny-events.js and need to make the changes here as well.

My intention was not to build another JavaScript utility library. I just wanted to make my JavaScript libraries jQuery independent.

"I made a tool to remove a library"

"Would you like to integrate that tool into my library?"

Kinda accurate, but as soon as you realize that "tool" is basically another name for "library" it makes sense. Like OP replaced code with code at the end of the day, who cares if you call it "library" or "tool" or something else.
Seems pretty cool. The only Cash design decision I’m doubting is $().append not accepting plain text. I get the reason why, but the alternative is ugly. Maybe add an appendText method, or a utility $.textNode?

I’m kind of assuming the underlying philosophy of the project is to make DOM manipulation as easy as in jQuery but smaller by removing seldom needed safeguards and relying on modern browser selectors. I’m okay with the additional footguns but think it should still preserve easy, concise syntax.

That's kind of a mistake of the library IMO, but changing that requires pushing a major release and I'm not sure if it's worth asking everybody to update their code to align that with jQuery at this point.