Hello, Owen.
Right now I'm working on the abstract UI reconciliation library:
https://github.com/jetbrains/noria-clj
This is created to address the issue between UI and functional programming 
languages. Basically it is very similar to React, except:
1) The communication between host platform (DOM, Cocoa, javax.swing, Win32 
etc.) and your UI logic is done with data, not bindings.

reconcile is a pure function:
(reconcile [old-ui element]) => [new-ui updates]

where updates is a vector of commands to be performed by the host patform 
and could be put on the wire. There actually a very simple set of 5 kinds 
of commands:
- make-node ;; which creates a node on host with given ID
- set-attr ;; sets some attribute of node with given ID to be a specific 
value
- add ;; adds value to a collection of values stored as attribute of some 
node (say dom/children attr or NSView/subviews)
- remove ;; symmetrical to add
- destroy ;; destroy this node, I don't need it

2) The implementer of this commands runs on a host runtime with some 
traditional UI toolkit. The logic of the UI itself is written in clojure 
and works with plain immutable data structures and pure functions.

3) Noria differs from React in a way we treat a state of the components:
the component itself is a transducer: 
(def my-stateful-component [r-f]
  (fn ([] (r-f))
       ([state input] 
           (r-f updated-state <result of your render>))
       ([state] <your finalization, component will be destroyed> (r-f 
state)))
4) Noria allows you to create a graph of objects rather than a tree:

(def constraint
  (render
   (fn [text1 text2]
     ['apply
      (fn [view1 view2]
        ['do
          {:noria/type :fake/constraint
           :constraint/view1 view1
           :constraint/view2 view2}
          {:noria/type :Container
           :fake/children [view1 view2]}])
      {:noria/type :fake/label
       :label/text text1}
      {:noria/type :fake/label2
       :label2/text text2}])))

Here we have two special 'elements'. 
One is 'apply which gives you a reference to existing component so you 
could use it in different contexts.
Another is 'do which behaves much like clojure's do: all components inside 
of it will be created, but the last one will be returned to the caller.

Host side is to be open-sourced soon. DOM/js and Cocoa/objc hosts are in 
progress at the moment. One could implement something else.


On Saturday, December 2, 2017 at 3:53:10 PM UTC+3, Owen wrote:
>
> Hey all. I'm looking for hints on how to put GUIs together in Clojure. Any 
> thoughts appreciated.
>
> The two themes that stick out for me in Clojure are considered attention 
> to the default data structures and the radical approach to minimising 
> state. But it seems to me that GUIs are inherently stateful and I don't 
> have a huge amount of faith that issues around data structures have been 
> completely thought through. It particularly sticks out to me that Clojure 
> itself hasn't taken a position on the subject and that the 'official' 
> Clojure GUI language might actually be Swing or JavaFX. This would be in 
> spite of the fact that those two both bring extremely stateful objects into 
> the Clojure world that just don't sit very neatly with the apparent vision 
> of the language.
>
> So with this as my starting point; I don't think there is an official, 
> idiomatic way to create a GUI. Can anyone point me in the direction of any 
> authoritative recommendations (particularly academic literature) on how to 
> balance GUI state and functional programming? I can tell if I have a GUI or 
> not, but I'm looking for yardsticks to assess:
> 1) Is my toolkit introducing unnecessary state?
> 2) Am I introducing unnecessary state?
> 3) Are my models of inter-widget communication appropriate?
>
> I know that MVC/MVMC/MVA/etc exist, but I don't know how to assess their 
> merits against how Clojure wants me to work.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to