Created
November 26, 2021 13:53
-
-
Save y2k/c965c185527f7c501fc670b24a4cdb9f to your computer and use it in GitHub Desktop.
Events driven arch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns domain) | |
(listen-event | |
:item-created | |
(fn [e] | |
{:fetch {:url "https://backend.com/save" | |
:body {:text (:text e)}}})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns view) | |
(defn view [model] | |
[:div | |
[:input {:on-changed (dispatch ::text-changed)}] | |
[:button | |
{:style {:enabled (not-empty? (:text model))} | |
:on-clicked (dispatch ::add-clicked)} | |
"add"] | |
(into | |
[:div] | |
(map (fn [x] [:span (str x)]) (:model items)))]) | |
(listen-event | |
::add-clicked | |
(fn [e db] | |
{:db (update-in [:items] (fn [items] (conj items (:text db)))) | |
:domain/item-created (:text db)})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment