Skip to content

Instantly share code, notes, and snippets.

@andrejewski
Created December 29, 2017 05:39
Show Gist options
  • Select an option

  • Save andrejewski/66cf01b640f177697a4a7a92d0196305 to your computer and use it in GitHub Desktop.

Select an option

Save andrejewski/66cf01b640f177697a4a7a92d0196305 to your computer and use it in GitHub Desktop.
Raj ported to Clojure/Script
(defn program [{:keys [init, update, done, view]}]
(let [state (atom nil)
running (atom true)
change (fn [dispatch [newState effect]]
(do
(if effect
(effect dispatch))
(reset! state newState)
(view @state dispatch)))
dispatch (fn dispatch [message]
(if @running
(change dispatch (update message @state))))]
(do
(change dispatch init)
(fn []
(do
(reset! running false)
(done @state))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment