-
Notifications
You must be signed in to change notification settings - Fork 0
It's Just HTML and CSS
mxWebis just thinly wrapped HTML/CSS.
mxWeb syntax parallels HTML syntax.
- HTML tags such as
DIVandSPANare mxWeb functionsdivandspan; -
mxWebtag function signatures mirror HTML tag syntax:- HTML: <tag attributes*> content* </tag>
- mxWeb: (tag [{HTML-attributes*} [{custom-attributes*}]] content*)
If you do not like mentally parsing Bauckus-Naur, the square brackets above translate to all these being legal:
(span "Hi, Mom!")(span {:style "color:red"} "Hi, Mom!")(span {} {:birthday "March 4, 1953"} "Hi, Mom!")- ...but not
(span {} {:style "color:red"} "Hi, Mom!")because mxWeb will not pass thecoloralong to the DOM; - ...and not
(span {:birthday "March 4, 1953"} "Hi, Mom!")because mxWeb will not know how to tell the DOM about Mom's birthday.
To complete this mission, you need to add one button to the "It's Just HTML" mission panel, with an onclick handler which will be provided.
The source code for this mission panel is here.
Our new code goes where we see the comment, "Your code here."
You will see a lot of extra code just to show off a bit, including snazzy reactive code, none of which will make a lot of sense yet. Please ignore, or explore for ideas.
Hint: In HTML, we would write the pseudo-code:
<button onclick=its-just-html-click-handler>
Accomplish Mission
</button>
Another hint: A "hello, world" exercise might be to add a simpler bit of mxWeb DOM. Find "Your button code here" in the source and add:
(span "Hi, Mom")
A second warm-up exercise:
(span {:style "color:red;font-size:2em"
:onclick (fn [e] (prn "onclick sees:" e))} "Hi, Mom!")
So now just translate the HTML in the first hint, emulating the warm-up exercises, and you will accomplish your first mission!
- The mxWeb programmer does not need to think about so-called "view functions", or dividing their view hierarchies up into reasonable sized chunks; mxWeb manages each DOM element separately. Even where we see a
(div ...)with many children, behind the scenes mxWeb maintains each DOM node separately, so a change, say, to thedisabledattribute of a child element in a large tree never requires any more code than directly altering that attribute of that DOM element. - Put differently, mxWeb does not involve VDOM. Instead, we instantiate long-lived proxy CLJS objects that stay around to manage their DOM counterparts. These proxy objects leverage the reactive power of Matrix to build efficient, dynamic web pages.
Help learning mxWeb is available on the #matrix channel of Clojurians Slack.
Issues with this trainer can be reported on its GitHub repo.