Skip to content

Instantly share code, notes, and snippets.

@y2k
Created November 26, 2021 13:53
Show Gist options
  • Save y2k/c965c185527f7c501fc670b24a4cdb9f to your computer and use it in GitHub Desktop.
Save y2k/c965c185527f7c501fc670b24a4cdb9f to your computer and use it in GitHub Desktop.
Events driven arch
(ns domain)
(listen-event
:item-created
(fn [e]
{:fetch {:url "https://backend.com/save"
:body {:text (:text e)}}}))
(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