News for hackers. Stuff that matters.
Re:Things every React.js beginner should know by aikah on Monday January 25, 2016 @11:21AM (#10968003)
> ... that then expand to be turing-complete and basically offer everything their primary language offered in the beginning.

then they wrote template languages on top of the template language to separate layout and logic again ( PHP vs Twig/Smarty )

so maybe we need to step back a little and figure out how to write a language that wouldn't need a different syntax for logic and layout. This family of languages exists already, but since current developers grew up with C like languages, it is not that popular.

IMHO the best compromise is direct support for XML syntax inside languages (which Javascript had at some point with E4X) because I don't think anyone will be able to make developers use LISP like languages on a wide scale. JSX, with some modifications and standardisation could also be a solution.

Re:Things every React.js beginner should know by escherize on Monday January 25, 2016 @11:40AM (#10968138)
I'm a huge fan of Clojure's Hiccup library. It allows the user to make html like the following.

Here's a function that always returns true - but it could do any kind of data access. It is just plain Clojure.

    (defn selected? [] true)
Here is a datastructure that represents html:

    [:h2 {:class (when (selected?) "selected")} "Hello"]
Calling the function hiccup.core/html on that datastructure yeilds an html string like this:

    "<h2 class='selected'>Hello</h2>"
So that's great for _strings_ right? But there is an awesome library for ClojureScript called Reagent. And it uses those simple datastructures to generate react components!! I put some more examples at: http://hiccup.space
Re:Things every React.js beginner should know by munro on Monday January 25, 2016 @02:57PM (#10969512)
I love Clojure, but I'm tired of embedded DSLs, they're a dime a dozen. You can argue the benefits of Hiccup's syntax & s-expr all day, but it's still a different, and unpopular syntax for describing HTML.

The ability to copy snippets of HTML from web, or old code when refactoring, or from Clojure/Hiccup to another language & framework, or changes from developer tool, or familiarity for new engineers, or not having to care about what flavor of HTML is hip today is a huge productivity boost for me.

I would love to see push for template strings [1] in Clojure, it should be trivial with macros. It would only take some time for IDEs to catch up. They're good. So good they've even influenced Python 3 to add them.

    (defui my-component [x]
      "<h2 class=(when (selected? x) ["selected"])>Hello</h2>")
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Re:Things every React.js beginner should know by escherize on Monday January 25, 2016 @06:46PM (#10970917)
So you _actually_ use function names as strings? That seems like a problem, and that it would need its own special editor tooling. Yikes.
Re:Things every React.js beginner should know by munro on Monday January 25, 2016 @09:20PM (#10971487)

    (defui my-component [x]
      <h2 class=(when (selected? x) ["selected"])>Hello</h2>)
It's possible to macro the above to the code below, without any language extensions. IntelliJ has powerful nested DSL introspection, it would be neat if Cursive allowed to hook into this through defui's metadata for highlighting. I was a hater of JSX until I used it. Now I hate eDSLs. :D

    (defn my-component [x]
      [:h2 {:class (when (selected? x) ["selected"])} "Hello"])
Re:Things every React.js beginner should know by chimeracoder on Monday January 25, 2016 @12:30PM (#10968505)
> I'm a huge fan of Clojure's Hiccup library. It allows the user to make html like the following.

It helps that Clojure's syntax is based on s-expressions, and s-expressions are already isomorphic to HTML/XML.

So in a way, you're still mixing your templates and your code, but you happen to be using the same syntax for both. Which is arguably an improvement.

Re:Things every React.js beginner should know by teej on Monday January 25, 2016 @11:58AM (#10968280)
I don't know man. Every time I've worked with that style of approaching the problem, it feels like I'm just writing HTML with different syntax.
Re:Things every React.js beginner should know by mst on Monday January 25, 2016 @01:02PM (#10968710)
If (if) you already like lisp, it more feels like writing HTML with cleaner, more composable syntax. Were I working on an all-lisp team, I'd be totally happy to use it. Since I'm generally not, JSX function components seem to be the next best (or at least next-least-worst) thing.
Re:Things every React.js beginner should know by rakoo on Wednesday January 27, 2016 @04:00AM (#10979025)
I have discovered this little gem, allowing you to do the same in pure Javascript: https://github.com/leeoniya/domvm

The equivalent would be something like

  function() selected { return true }
  ["h2", {class: function() {if (selected()) {return "selected"}}}, "Hello"]
Not as clean, but still usable IMO
Re:Things every React.js beginner should know by pekk on Monday January 25, 2016 @12:05PM (#10968321)
If you are trying to make a language that doesn't need a different syntax for logic and layout, do you not end up with a templating language similar to PHP? Is this the right goal?
Re:Things every React.js beginner should know by matt4077 on Monday January 25, 2016 @10:52PM (#10971732)
Yes – look for example at the .erb templates that rails uses. It's still possible to do evil stuff in those, but I actually haven't seen it in practice. The whole framework is organized in such a way that people get where their logic belongs.

The worst I've seen is a bit of confusion between models and controllers. But views are usually as clean as the Gods of MVC commanded.

Re:Things every React.js beginner should know by paulddraper on Monday January 25, 2016 @08:58PM (#10971422)
Scala has inline XML support.

Not a good thing, IMO, since it makes the syntax way more complicated, but there you have it.