Lurker News

Comments (156) 28 threads

Show all comments

Showing thread 12 of 28

k__1 reply#
Nice experiment.

I've also "re-created React" multiple times before it was actually created.
Diffing somehow always ended up being thr most natural way tondo things in the end.
My selling point in the end were the components

leontrolski1 reply#
My feeling is that if html and js had syntactically shared data structures at their conception, we wouldn't have quite so much frontend mess as we do now and declarative UI would have been the norm for a while. Having said that, I'm not sure how much precedent this has in UI frameworks outside of the web.
k__3 replies#
You think so?

What would be different if

    Document.createElement('a')
Would look like

    
?

The rest would still be imperative code.

capableweb#
The first one is imperative and locks the implementation to use the Document object and the createElement function.

The second one is declarative and leaves it up to the receiver to handle however they seem fit.
I'm not arguing one is better or worse, or that we would be better off if we we're using the JSX way with native support in the browsers, just explaining how I see the differences between the two.

colejohnson66#
It’s been a bit since I’ve used JS (so I may have the latter syntax wrong), but I’d prefer the JSX style of

    var elem = Test;
over

    var elem = document.createElement("a");
    elem.href = "#test";
    elem.innerText = "Test";
jQuery allows one to do something similar to JSX (which is nice):

    var elem = $("Test");
ken#
I don't interpret "html and js had syntactically shared data structures" to mean what you wrote, unless you also replace all other JS data structures (arrays and dicts and ...) with <> syntax. You've made it more concise but it's still distinct.

For an example of a system where the programming language and document generator share data structures, look at Hiccup (and Reagent). One of their very first examples is putting a loop inside a list. There's no special API for the attributes -- it's just an ordinary map. There's no special API for the children -- it's just an ordinary vector.