vrac

Template-based web library [WIP] - https://github.com/green-coder/vrac Zulip archive: https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/vrac Clojureverse archive: https://clojurians-log.clojureverse.org/vrac
yogthos 2020-09-01T00:06:50.387200Z

ah makes sense

yogthos 2020-09-01T00:07:17.387800Z

a bit of syntax sugar helps

2020-09-01T00:09:10.389300Z

Inside the template’s grammar, there are 2 distinct modes: In the html mode: 1. a literal vector is interpreted as the inclusion of a html node or a vrac component, 2. a if is interpreted as a html-if if its then and or else parameters are html nodes, In the value mode: 1. a literal vector is interpreted as a value 2. a if is interpreted as a value-if .

2020-09-01T00:12:01.390500Z

The html-if in going to be treated specially during the rendering process. With the html-for node, it will be updated with a higher priority compared to any other nodes.

2020-09-01T00:14:31.391700Z

Thinking of which, the value-if will have to be treated in a special way as well, as it won’t need both the data from its then and the else parameters.

2020-09-01T00:18:35.393800Z

The (val ...) block is for explicitly stating that its content is to be understood in the value mode.

2020-09-01T00:21:31.395800Z

Maybe I should also keep html/if and value/if as reserved symbols for the users who don’t want to think about the modes, to make it simple. Or maybe they won’t care about the difference between the 2 ifs.

2020-09-01T00:38:09.401600Z

Oh .. my mistake, it should count as the html-if if any of the “then” or “else” is a html node.

;; then param is a value
;; else param is a html node
[:div (if foobar "then" [:div "else"])]
nil counts at both a value and an html node. I am thinking that components should be allowed to return nil, as well as (for ...) blocks.

2020-09-01T00:41:51.403700Z

— End of today’s brainstorming. Feedback is welcome, as always. My next step will be to aggregate all the things I wrote into an organized documentation file.

2020-09-01T19:46:00.404700Z

I am writing the documentation, and I realized that there is an important detail that I forgot to mention about data loading.

2020-09-01T19:46:39.405400Z

The templates let the system know what data is required for a full display of the template.

2020-09-01T19:47:00.405900Z

But what to do when the data is not loaded yet?

2020-09-01T19:47:27.406600Z

David Nolen suggested in one of his talks about OM Next that the component should not be displayed.

2020-09-01T19:47:39.406900Z

I have another solution more flexible:

2020-09-01T19:56:12.407200Z

;; Let's reuse the syntax from Clojure ! :-)
(let [cake (:cake global {:loaded? false
                          :name "The cake is a lie!"})]
  [:div
   {:class (if (:loaded? cake) :loaded :lie)}
   (:name cake)])

2020-09-01T20:02:59.407300Z

2020-09-01T20:04:57.409400Z

Here is what I typed so far. The next section will be a description of the template’s grammar, mostly copy/paste from what I’ve written so far. As usual, feedback is super-mega-really welcome. Do not hesitate to ask questions, it helps me to find places where the documentation is lacking.

2020-09-01T20:06:20.409600Z

cc @yogthos

yogthos 2020-09-01T20:09:33.410300Z

so you're thinking of adding an ability to provide the default state while component loads?

2020-09-01T20:10:14.411Z

yes, knowing that the if in the template will provide enough flexibility for the user to take advantage of it.

2020-09-01T20:11:27.411600Z

The default value will be used when the data is just not available, it does not necessary mean that it is loading.

2020-09-01T20:17:42.412100Z

Good night~

yogthos 2020-09-01T20:19:46.412500Z

I like that, a very clean way to get the default behavior

yogthos 2020-09-01T20:20:07.412800Z

oh and might be an idea to do a version of this with Vrac https://github.com/ClojureTO/JS-Workshop

👍 1
yogthos 2020-09-01T20:20:32.413500Z

a kind of a step by step introducing different features from something really basic

yogthos 2020-09-01T20:20:37.413700Z

and g'night 🙂