Skip to content

Instantly share code, notes, and snippets.

@swannodette
Forked from haywoood/wont_work.cljs
Last active January 2, 2016 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save swannodette/8324933 to your computer and use it in GitHub Desktop.
Save swannodette/8324933 to your computer and use it in GitHub Desktop.
(ns test.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs.core.async :refer [<! chan put!]]
[om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
(enable-console-print!)
(def aidc (chan))
(defn handle-x [e p chan]
(put! chan (:id p)))
(defn project-view [the-project owner opts]
(om/component
(dom/li
#js {:onClick (om/bind handle-x the-project (:chan opts))}
(str (:title the-project) " selected: " (:selected the-project)))))
(defn update-aid [owner aidx]
(om/set-state! owner :aid aidx))
(defn project-list [projects owner opts]
(reify
om/IWillMount
(will-mount [_]
(go (while true
(let [aidx (<! aidc)]
(update-aid owner aidx)))))
om/IRender
(render [_]
(dom/ul nil
(let [state (om/get-state owner)]
(om/build-all project-view
projects
{:key :id
:opts opts
:fn (fn [proj]
(cond-> (assoc proj :selected false)
(= (:id proj) (:aid state)) (assoc :selected true)))}))))))
(om/root app-state
(fn [{:keys [projects] :as app} owner]
(reify
om/IRender
(render [_]
(dom/div nil
(om/build project-list (:projects app) {:opts {:aid (:aid app) :chan aidc}})))))
(.getElementById js/document "app"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment