Settings

Theme

Cloact: Minimalistic React for ClojureScript

holmsand.github.io

118 points by danh 12 years ago · 44 comments

Reader

lftl 12 years ago

While I haven't had any time to play with ClojureScript, Om, React, etc. I've been keeping a pretty watchful eye, because the stack looks very appealing.

One bit that doesn't look appealing to me in Om, or Cloact is the tree-building. Is there anything in ClojureScript and React right now that will let me build templates in HTML and attach functionality via attributes Angular-style?

  • swannodette 12 years ago

    As I suggest below I don't see why you could not compile to Om or Cloact from HTML for a friendlier presentation for designers. Still I don't think Cloact nor Om DOM syntax is particularly unapproachable for designers - I think we need some good documentation and some compelling, friendly walk-through demos (Light Table anyone? :)

    • airlocksoftware 12 years ago

      Please yes (on the Light Table demo). I know my way around ClojureScript, and I cannot get the Om TODOMVC demo to run in Light Table. If I get it figured out, I guess I'll be the one writing the tutorial, but so far no dice.

    • craigching 12 years ago

      > Still I don't think Cloact nor Om DOM syntax is particularly unapproachable for designers

      It's not just designers who appreciate using declarative markup over programmatic syntax! Of all the people who might understand this, I'd have thought you would be the first in line (as a fan of your work on core.logic and inspiring me to learn prolog)!

      • swannodette 12 years ago

        I find the React approach very declarative. Certainly competitive with most of the templating systems I've used, few of which I can speak very highly of :)

        • craigching 12 years ago

          I've used both dojo dijit and angularjs templates. I admit, I haven't done more than read your blog on Om, but I very much prefer the html declarative templates of both dojo and angularjs ... show me how Om/React beats direct html templates, I'm not seeing it.

          I'm not trying to be too non-constructive critical here, I fully admit I haven't tried Om/React, just looked at your blog post about it. So what am I missing?

          • jacobolus 12 years ago

            Using clojure data syntax instead of SGML-like syntax doesn’t make the language any more or less “declarative”. Assuming you use the same features in your templates, the clojure version is precisely as declarative as whatever other template language.

            However, if you use the clojurescript version [or in standard React, the javascript- or coffeescript-looking version], then you suddenly have a bunch of potential extra features which in some cases are invaluable. (Or you can deliberately ignore those if you prefer.)

            When you say “declarative” I think you might really just mean “familiar for html experts”. But most html expert should be able to learn the new syntax quite easily, since the relevant parts are less verbose than html, quite regular and straightforward, and semantically equivalent.

            If you feel like putting your templates in separate files from your logic, or writing them using an SGML-like syntax, that’s pretty trivial to do in any of these environments.

  • brandonbloom 12 years ago

    Hopefully not!

    Why don't you give React a whirl and try not to force Angular thinking on to the React model. Shouldn't take more than an hour or two of investment to make a small toy app to experiment with.

fourply 12 years ago

I can't see that word without thinking of Cloaca. Cloaca. If you don't know what it is, you should. Cloaca.

  • Zancarius 12 years ago

    Same here. Perhaps it's my exceptionally wry (and inappropriate sense of humor), but I rather wish it were cloaca. Just imagine the logo opportunities!

    A startled pigeon, looking over its wing, tail up in the air, clearly exposing its backside...

    ...this is why I'd never get hired as a marketer or designer, never mind the fact I'm no artist.

  • smrtinsert 12 years ago

    I never thought that I would need this at Hacker News. A nsfw warning would suffice.

    • downer86 12 years ago

      Ha ha! Oh wow! I just ran a google image search to see what you were talking about...

      Knowing what a cloaca is beforehand, and then searching for it anyway on Google produces some truly curious results. I was trying to mentally prepare myself for what I may be about to see, because I couldn't imagine what might be on the other side, that would prompt your reaction. The only thing I could think of was some bizarre new form of bestiality that lurks in the shadows of taboo obscurity.

      It turns out that most of the images are of obvious medical or scientific origin. I don't even know why pictures of humans show up in the search. I saw lots of pictures of various reptile junk which was totally expected, and none of it was being unceremoniously violated by unscrupulous human beings, so thank god for that!

      Apparently there's a medical condition, "Persistent Cloaca Perineum", which is frequently misdiagnosed as "Imperforate Anus with Rectovaginal Fistula." The pictures that depict the condition are mostly de-identified newborn infants, and they originate from edu domains, but in a google search without proper context, they're kind of unexpected. I guess you learn something new every day...

  • jbeja 12 years ago

    My mother language is Spanish, and to be honest the first time i read the name i was thinking the word "cloth" or "coat" instead "cloaca".

gcao 12 years ago

React is nice. I've created a simple library that shares same core concept - map DOM to Javascript objects. The difference is my lib uses Javascript standard data type, array, to represent tag, and hash(or object) to represent attributes, and strings for text contents. With a few tricks, I got a very powerful library - http://github.com/gcao/T.js. You can see an example written in CoffeeScript here

https://gist.github.com/gcao/8363743

elwell 12 years ago

I wish github had better syntax highlighting for Clojure. Different colors for matching parentheses.

jbeja 12 years ago

IMHO, This look more easy to read than OM

  • smrtinsert 12 years ago

    Agreed. I'm so much more into the hiccup style tree building. This looks like something I can get into tonight. David is great but he prefers his code a little mysterious.

    • swannodette 12 years ago

      You can use Hiccup style with Om via sablono if you like via http://github.com/r0man/sablono. Om will never dictate nor provide an alternate syntax layer as everyone will want something different. I personally don't care for Hiccup.

      More importantly, Cloact is much closer to the React model while Om diverges quite a bit because we're interested in enabling patterns that are more difficult otherwise, trivial complete UI state rewind on exceptions/errors, trivial undo, and more powerful operations on the applicate state history oriented at interactive debugging and development.

      Of course these values might not interest you and you just want a simple direct mapping onto React. Then Cloact looks awesome! :)

      • danhOP 12 years ago

        Thanks, again :)

        Yes, exactly, Cloact tries to stay really close to plain React. But since it allows you to separate data from rendering, undo should be quite trivial to implement (if you keep all your application data in a single cloact/atom)...

        • swannodette 12 years ago

          Yep sounds right to me. The other reason I did Om the way I did was to keep the door open for more React optimizations that Om can drive which are more work if you remain close to the React model - particularly only reconciling the specific children that changed in a list instead of iterating over them like React does.

        • Touche 12 years ago

          One thing I can't figure out is why they need to be cloact/atoms and not just regular atoms. Is it because cloact/atoms are observable?

          • danhOP 12 years ago

            In a way. Using regular atoms you can only get a callback when they are modified, but not when they are deref'ed.

            You could still use regular atoms, though, with some extend-type magic. But then you risk messing with non-Cloact code in horrible ways...

      • smrtinsert 12 years ago

        Undo is like half of what I want out of a reactive cljs lib! You sly devil you, I guess I'll keep watching both projects.

    • adambard 12 years ago

      I think the hiccup style is a bit dangerous myself. It's great for a one-man show, or a situation where everyone who would ever have to touch the HTML is a developer, but personally I find it's a pain in my ass when it's my problem when someone else wants to insert an element into the DOM.

werdnapk 12 years ago

How does this all work with non-inlined event handlers? I see a lot of on-click, on-change going on in these examples.

elwell 12 years ago

Sorry for the noob question, but: does this take the place of Hiccup? Or, would one use both at the same time?

  • danhOP 12 years ago

    Firstly, Hiccup is Clojure (so basically server only). Cloact is ClojureScript, that compiles to javascript (so browser, node.js, etc).

    Secondly, Hiccup produces strings. Cloact typically creates DOM elements, through React, that change every time a component rendered. But it can also produce an HTML string using the same data, to pre-render a page on the server using node.js.

  • drcode 12 years ago

    Hiccup is for going html->string

    This library goes from html->React data structure

    The React.js system then is responsible for pushing it into the DOM, which it can often do in a way that's more performant than using a string intermediary (by computing deltas)

    That's the short of it- The other part is that React is mainly a client-side technology whereas Hiccup is mainly used on the server (though these lines are blurry)

  • lgas 12 years ago

    As danh and drcode said, Hiccup is basically edn->text and server side only but there are a number of implementations of the same concept in ClojureScript:

    https://github.com/teropa/hiccups - Basically a straight port of hiccup to ClojureScript.

    https://github.com/ibdknox/crate - Returns dom nodes instead of strings.

    https://github.com/lynaghk/singult - Works in Clojure or ClojureScript and offers live merging of nodes into the dom.

    https://github.com/Prismatic/dommy - Dommy is more than just templating but offers a hiccup style templating language too.

    And I'm sure there are others.

smrtinsert 12 years ago

Wow this looks like an awesome little lib. I love stuff like this.

andyl 12 years ago

Cloact: unfortunate name.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection