Skip to content

Instantly share code, notes, and snippets.

@dfcarpenter
Last active September 2, 2015 19:32
Show Gist options
  • Save dfcarpenter/75ea0958553c3cb15cad to your computer and use it in GitHub Desktop.
Save dfcarpenter/75ea0958553c3cb15cad to your computer and use it in GitHub Desktop.
Re-frame / cljs-http problem
(ns shouter.handlers
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [re-frame.core :as re-frame]
[shouter.db :as db]
[reagent.session :as session]
[cljs-http.client :as http]
[cljs.core.async :refer [<! >! chan put!]]))
(re-frame/register-handler
:initialize-db
(fn [_ _]
db/default-db))
(re-frame/register-handler
:set-active-panel
(fn [db [_ active-panel]]
(assoc db :active-panel active-panel)))
(re-frame/register-handler
:get-github-users
(fn []
(go (let [{data :body} (<! (http/get "https://api.github.com/users" {:with-credentials? false}))]
(re-frame/dispatch [:process-github-users (<! data)])))))
(re-frame/register-handler
:bad-response
(fn
[db [_ response]]
(-> db
(assoc :github-answered? false)
(assoc :github-error (js->clj response)))))
(re-frame/register-handler
:process-github-users
(fn
[db [_ response]]
(-> db
(assoc-in :github-answered? true)
(assoc-in :github-data (js->clj response)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment