Created
December 29, 2017 05:39
-
-
Save andrejewski/66cf01b640f177697a4a7a92d0196305 to your computer and use it in GitHub Desktop.
Raj ported to Clojure/Script
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
| (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