-
-
Save swannodette/8324933 to your computer and use it in GitHub Desktop.
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
(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