The app with The elm architecture demonstration made with ClojureDart on Flutter

Overview

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

You may read about TEA approaches in other libraries (dart, kotlin).

Here I will provide my vision to the TEA.

There are 4 components:

  1. Model - application state.
  2. Effects - side effect functions.
  3. Message - events that happens, like user click or effect result
  4. 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 sources.

MVU Components example:

  1. Model - atom with map:
{:selected-country-code nil
 :country nil 
 :continent nil 
 :expanded nil}
  1. Effects - functions with the signature like (defn some-effect [dispatch-fn] ...):
(defn- effect-load-countries [dispatch!]
  (dispatch! :loaded-countries (await (api/get-countries))))

;; effect with additional arg (code)
(defn- effect-load-continent [dispatch! code]
  (dispatch! :loaded-continent (await (api/get-continent code))))

;; effect as a lambda that ignores args 
#(log "country selected")
  1. Messages - Keywords:
:user-openes-app
:loaded-continent
:loaded-countries 
...
  1. Update - function that takes state-map, message and message-data and returns vector with new state and effects:
(defn- tea-update [state message data]
  (case message
    :user-openes-app [state [effect-load-countries effect-select-default-country]]

    ;; changing state and passing two lambda-effects
    :user-choose-country [(assoc state :selected-country-code data :continent nil :expanded nil) 
                          [#(effect-load-country % data)
                           #(log "country selected")]]

    ;; effects may vary based on condifions
    :user-click-expand-continent [(assoc state :expanded (not (:expanded state)))
                                  (if (:continent state) [] [#(effect-load-continent % data)])]

    ;; effects could be omited
    :loaded-countries [(assoc state :countries data)]

    ;; default state
    [state [#(log "don't know how to process the message")]]))

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

You might also like...

Made with Clean architecture + TDD + GraphQL + flutter_bloc + CodeCov + GitHooks + GitHub Actions (CI/CD) and finally with πŸ’™

Made with Clean architecture + TDD + GraphQL + flutter_bloc + CodeCov + GitHooks + GitHub Actions (CI/CD) and finally with πŸ’™

Rick and Morty Info A simple app to demonstrate Clean Architecture with GraphQL and flutter_bloc Motivation In Martin Fowler's words, β€œAny fool can wr

Dec 25, 2022

This is the UI of Furniture App made using Flutter SDK. The original design was made by someone else in dribble and I tried to create the screens of that UI using Flutter

This is the UI of Furniture App made using Flutter SDK. The original design was made by someone else in dribble and I tried to create the screens of that UI using Flutter

Furniture App - Responsive Flutter UI Watch it on YouTube Responsive UI Fetch Data From API Custom Loading Indicator Packages we are using: flutter_sv

Dec 3, 2022

Flutter App Templete is a project that introduces an approach to architecture and project structure for developing Flutter apps.

Flutter App Template "Flutter App Template" is a project that introduces an approach to architecture and project structure for developing Flutter apps

Jan 5, 2023

πŸš€ Sample Flutter Clean Architecture on Rorty App focused on the scalability, testability and maintainability written in Dart, following best practices using Flutter.

πŸš€ Sample Flutter Clean Architecture on Rorty App focused on the scalability, testability and maintainability written in Dart, following best practices using Flutter.

Rorty Flutter Rorty πŸ“Ί (work-in-progress for V2 πŸ‘· πŸ”§οΈ πŸ‘·β€β™€οΈ ⛏ ) Getting Started Flutter Clean Architecture in Rorty is a sample project that presents

Jan 1, 2023

This project follows the Reso Coder course for flutter test-driven-development with clean architecture and BloC state management for a random trivia simple app.

This project follows the Reso Coder course for flutter test-driven-development with clean architecture and BloC state management for a random trivia simple app.

Jan 5, 2022

Flutter app using MVVM architecture pattern , dio , provider , intl packages.

Flutter app using MVVM architecture pattern , dio , provider , intl packages.

News App Simple news application using free news API for fetching realtime data from the internet. Features -Used MVVM architecture pattern. Packages

Mar 25, 2022

FlutterQRcode - Flutter QR Code Scanner app for a specific type of QR using GetX State Management Architecture

FlutterQRcode - Flutter QR Code Scanner app for a specific type of QR using GetX State Management Architecture

qrcode A new Flutter QR Scanner Project for Data Entry using GetX state manageme

Dec 11, 2022

A Flutter Enterprise Software Development Architecture. Start to develop your bigger app easily.

A Flutter Enterprise Software Development Architecture. Start to develop your bigger app easily.

Jan 7, 2023

Build flutter posts app using Robert Martin (Uncle Bob) clean architecture.

Flutter clean architecture - Posts app Ψ¨Ψ§Ω„ΨΉΨ±Ψ¨ΩŠ #1 Intro Video Link #2 Explain clean architecture Video Link #3 Initial project , Add and explain requi

Dec 23, 2022
Owner
Artur Dumchev
Clojure enthusiast, android dev in the past.
Artur Dumchev
A demonstration of using Riverpod for dynamic locale switching in-app, with persistence.

Riverpod Localization A demonstration of using Riverpod for dynamic locale switching in-app, with persistence. How It Works Fallback Locale: Declared

Dominique Rwema Bagirishya 30 Oct 6, 2022
A basic demonstration for creating a Jardinains (Fancy Pong-Like) Game in Flutter

Jardinains Flutter! ?? Play Here - Web https://flutter-jardinains.web.app/#/ Demo Note: For optimal performance run the project in profile mode using

Paras Jain 60 Nov 12, 2022
Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to developing Flutter apps.

Flutter Architecture Blueprints Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to dev

Katsuyuki Mori 2 Apr 9, 2022
Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to developing Flutter apps.

Flutter Architecture Blueprints Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to dev

Daichi Furiya 1.5k Dec 31, 2022
Ouday 25 Dec 15, 2022
Flutter-clean-architecture - A simple flutter project developed with TDD and using Clean Architecture principles.

Clean Architecture This is a study project to practice TDD and a good approach of Clean Architecture for flutter projects. It is based on Reso Coder s

Luiz Paulo Franz 8 Jul 21, 2022
Flutter Architecture inspired by Domain Driven Design, Onion and Clean Architecture

Inspiring Domain Driven Design Flutter Architecture Please take a look at my slides to learn more Strategic Domain Driven Design For Improving Flutter

Majid Hajian 324 Dec 25, 2022
Proyect with Clean Architecture / Hexagonal Architecture - Patron BLoC - The MovieDB API

flutter_movies_db A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you starte

null 2 Sep 22, 2022
COVID-19 application made with Flutter, following Test Driven Development (TDD) and Clean Architecture along with Internationalization with JSON.

Covid App COVID-19 application made with Flutter, following Test Driven Development (TDD) and Clean Architecture along with Internationalization with

Sandip Pramanik 4 Aug 4, 2022
A Flutter boilerplate made by GeniusCrew BV and inspired to the Clean Architecture structure.

GeniusArchitecture This is a boilerplate project created in flutter using Provider, Firebase, Dio, and some fundamentals of Robert C Martin's Clean Ar

GeniusCrew 10 Dec 16, 2022