Last active
February 14, 2016 17:45
-
-
Save retro/e0813592749f693f3b2a to your computer and use it in GitHub Desktop.
This file contains 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
;; If it's for the user stored in the `:current-user` named slot | |
(def schema {:users {:id :id}}) | |
(def current-user-favorite-color [app-db] | |
(reaction | |
(let [db @app-db | |
current-user (edb/get-named-item schema app-db :users :current)] | |
(:favorite-color current-user)) | |
(defn favorite-color-renderer [ctx] | |
(fn [] | |
[:div (deref (ui/subscription ctx :current-user-favorite-color))])) | |
(def favorite-color-component | |
(ui/constructor {:renderer favorite-color-renderer | |
:subscription-deps [:current-user-favorite-color])) | |
;; If you have only the id | |
(defn favorite-color-for-user-id [app-db user-id] | |
(reaction | |
(let [db @app-db | |
user (edb/get-item-by-id schema app-db :users user-id] | |
(:favorite-color user)) | |
(defn favorite-color-by-user-id-renderer [ctx user-id] | |
(fn [] | |
(let [favorite-color (deref (ui/subscription ctx :favorite-color-for-user-id [user-id]))] | |
[:div favorite-color])) | |
(def favorite-color-by-user-id-component | |
(ui/constructor {:renderer favorite-color-by-user-id-renderer | |
:subscription-deps [:favorite-color-for-user-id])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment