An app with The elm architecture demonstration made with ClojureDart on Flutter
clojure_dart_tea_example
ClojureDart Flutter project with demonstration of:
- Graphql usage;
- managing business logic and state with TEA*-like MVU architecture.
- widget and nest macro from ClojureDart/alpha.
* The Elm architecture
Warnings!
This approach is not ready for production, just the idea demo.
MVU TEA-like architecture
I will provide my vision to the TEA.
There are 4 parts:
- Model – application state.
- Effects – side effect functions.
- Message – events that happens, like user click or effect result
- Update – function that takes old model and message, and return new model with list of effects.
To allow all this to work we have a dispatch
function, that takes messages from all the source.
So in this app this components are:
- Model. State of the flutter/widget.
- Effects. Functions with the signature like
(defn some-effect [dispatch-fn] ...)
- Messages. Keywords.
- Update. Function with the signature like
(defn update [state message-key data])
. Data is a part of the message abstraction.
For all this to work you don’t need a framework, just 1 dispatch function:
(defn- ^:async dispatch! [tea-update state-atom message data]
(let [[new-state effects] (tea-update @state-atom message data)
dispatch-for-effet-fn (partial dispatch! state-atom)]
(reset! state-atom new-state) ;; state modification
(doseq [e effects] (await (e dispatch-for-effet-fn)))))
Resources
- ClojureDart
- ClojureDart differences from clojure.
- The dart project that I used as a base for graphql and ui at the begining.