Skip to content

Instantly share code, notes, and snippets.

@mynomoto
Created October 31, 2015 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mynomoto/c128da6dcaacd76d9796 to your computer and use it in GitHub Desktop.
Save mynomoto/c128da6dcaacd76d9796 to your computer and use it in GitHub Desktop.
Update state
(page "index.html"
(:require
[estimate-work.elements :as e]
[estimate-work.elements.nav :as nav]
[estimate-work.elements.estimate :as estimate]))
(defc state
[{:data "foo"}
{:data "bingz"}
{:data ""}
{:data "bar"}
{:data ""}])
(defn prepare-values
"Filter empty values, then add one empty on the end."
[values]
(conj (filterv #(seq (:data (last %))) (map-indexed (fn [idx v] [idx v]) values)) [(count values) {:data ""}]))
; (swap! state prepare-values)
(defc= prepared-values
(prepare-values state))
(cell= (prn :state state))
(cell= (prn :preparede-values prepared-values))
(e/outer-dom
(loop-tpl :bindings [[idx {data :data}] prepared-values]
[(input
:value data
:change #(swap! state assoc-in [@idx :data] @%)
:type "text") (br)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment