-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.cljs
22 lines (20 loc) · 843 Bytes
/
core.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(ns elm-cljs.core
(:require-macros [cljs.core.async.macros :refer [go-loop]])
(:require [cljs.core.async :refer [>! <!]]
[elm-cljs.channels :refer [messages effects]]
[elm-cljs.render :refer [render]]))
(defn- print-update [action old-model new-model effect]
(js/console.groupCollapsed action)
(js/console.info old-model)
(js/console.info new-model)
(js/console.info effect)
(js/console.groupEnd))
(defn main [initial-model view update root]
(render (view initial-model) root)
(go-loop [model initial-model]
(let [message (<! messages)
[updated-model effect] (update model message)]
(print-update message model updated-model effect)
(when (not= model updated-model) (render (view updated-model) root))
(when effect (>! effects effect))
(recur updated-model))))