TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Faster, Better DOM manipulation with Dommy and ClojureScript

162 pointsby zackzackzackabout 12 years ago

10 comments

jlongsterabout 12 years ago
ClojureScript is so different from JavaScript that it makes sense write a more native DOM library for it. As someone with a lisp background, it's very cool to see a high-profile company like Prismatic using it.<p>However, macros for javascript are being worked on. sweet.js is coming along <i>really</i> well, and just needs to continue ironing out bugs and maturing. <a href="http://sweetjs.org/" rel="nofollow">http://sweetjs.org/</a> I believe that it could have a profound effect on JavaScript, such as parsing selector string at expand time.
评论 #5627984 未加载
k3nabout 12 years ago
Interesting, but I'm not sure how appropriate it is to be comparing it to jQuery in such a head-to-head fashion such as by saying "15x slower", etc. Does Dommy offer the same features (including the browser support) that jQuery does? If not, then you're just comparing apples to oranges, and it doesn't sound like it does (or even plans to) on account that it sounds like there are design decisions that separate the two with regards to the published API ("Inspired by jQuery, but adapted to be functional in order to better fit with ClojureScript core").<p>Also, wouldn't it be more accurate for the selector testing to actually test against Sizzle[1]?<p>Other features aren't even present in jQuery, such as templating, and so I'm not sure why you'd even compare that. Yes people can and do use templates with jQuery, but that's an implementation detail and is not a concern of the library itself; jQuery does not coerce or force you to use a slow templating system, and most any good templating system will also have a compilation step that is run at build-time. So yeah, you can take some ugly userland jQuery example code and make specific code that is faster..<p>1. <a href="https://github.com/jquery/sizzle" rel="nofollow">https://github.com/jquery/sizzle</a>
评论 #5628822 未加载
olenhadabout 12 years ago
This is super impressive. I'm going to use this for my frontend work now. On a side note, what's the idiomatic structure, or "design pattern" for cljs front end code? I would assume something based on MVC, with models comprising of atoms with watches, Views consisting of hiccup templates and controllers gluing dom events to models and views. Am I close?
评论 #5628396 未加载
评论 #5628245 未加载
评论 #5628228 未加载
d0mabout 12 years ago
&#62;&#62; Again the time saving comes from macros moving the work of parsing the template data structures from runtime to compile-time and directly generating efficient JavaScript.<p>If it ends being javascript string in the ends, how is it 7x faster (or whatever number)? I mean, sure the compiler could optimize a part of my code, but other javascript compiler could do it to.. right?<p>Although I find the Clojure example very sexy, I don't like how the examples tries to compare to contrived Javascript. I.e. I've been coding javascript for a couple years and I've never used jQuery "sort/filter/slice". But more importantly, it uses pre-defined function in Dommy but not in javascript. For instance:<p><pre><code> (-&#62;&#62; (sel [:ul.my-list :li]) (sort-by #(-&#62; % (sel :input.last-name) .-value)) </code></pre> This uses sort-by where there's:<p><pre><code> function(a, b) { return ( $(a).find('input.last-name').val() .localeCompare( $(b).find('input.last-name').val() ) ); </code></pre> in Javascript.. Obviously, I can say:<p><pre><code> $('ul.my-list li').sortBy(function(x) { return x.attr('last-name'); } </code></pre> My point isn't that much that jQuery is longer/shorter, but mostly that if two examples in two different languages are to be compared, it makes sense to use the same function.. where in this case sort-by is a high-level sort.<p>&#62;&#62; One is the loneliest number<p>It's not just "1" or "more than one", it's also zero. Iterating on a list makes it such that you can freely think in a high-level way about the operation and not about the exceptional cases. I.e. $('.blabla').hide(); It Just Works.<p>&#62;&#62; (mapv #(add-class! % :first-ten-adults)))<p>Yes, of course you can use map.. but using $('..').addClass('first-ten-adults') makes it so much easier to deal with, instead of knowing what works on one object, what works on multiple objects, what will throw an error if there's nothing, etc.<p>Meh.<p>I think Dommy is a great library but the author didn't do a great job at explaining why it rocks. I guess attacking a very popular language with its most popular library doesn't help :p
评论 #5628888 未加载
st3redstripeabout 12 years ago
Whilst I'm sure this is clever - I guess I'll never understand the obsession with micro DOM optimisations. When, ever, are we severely held back by the 'speed' of our selectors? It just doesn't happen!
评论 #5628074 未加载
评论 #5628210 未加载
ariaabout 12 years ago
Author here. Happy to answer any questions/concerns.
评论 #5627949 未加载
评论 #5628028 未加载
评论 #5627881 未加载
评论 #5628460 未加载
评论 #5629113 未加载
codewrightabout 12 years ago
Carthago delenda est: when are you re-releasing the software you yanked from your Github?
评论 #5630650 未加载
j_m_babout 12 years ago
All this talk of jQuery and no mention of domina (<a href="https://github.com/levand/domina" rel="nofollow">https://github.com/levand/domina</a>) the native clojurescript dom manipulation library? I've since abandoned css and jquery selectors in favor of using domina.xpath.<p>I also want to mention webfui (<a href="https://github.com/drcode/webfui" rel="nofollow">https://github.com/drcode/webfui</a>). It is authored by Conrad Barski, who also wrote Land of Lisp. He gave a nice talk about it at the Chicago Clojure meetup group a few months back. He is a fellow hacker news user so I figured he deserved a shout out.
dmixabout 12 years ago
I'd love to use Clojure and clojurescript to replace js/ruby. It's a shame I never come across consulting gigs that use it. Or know any local clojure devs, so I'm still wary of using it on my own projects.<p>So it continues to only be the ideal choice for pet projects.
iamleppertabout 12 years ago
It would be more interesting if someone wrote something like this for standard jQuery-compatible syntax. jQuery code in, compiled selectors out. And it's just standard javascript, so no learning curve to learn or anything.
评论 #5644673 未加载