Created
September 7, 2017 12:09
-
-
Save qleguennec/5887b570de6e675c3235ec7db2dcbe23 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
;; event-db | |
(rf/reg-event-db | |
:auth/ok | |
(fn [db [_ resp]] | |
(assoc db :token (:access_token resp)))) | |
;; event-fx | |
(rf/reg-event-fx | |
:auth | |
(fn [{:keys [db]} _] | |
{:POST | |
{:url "https://api.intra.42.fr/oauth/token" | |
:on-success [:auth/ok] | |
:on-fail [:auth/nok] | |
:params | |
{:grant_type "client_credentials"}}})) | |
;; effect | |
(rf/reg-fx | |
:POST | |
(fn [{:keys [url params on-success on-fail]}] | |
(take! (http/post url {:form-params params}) | |
#(rf/dispatch (conj on-success %))))) | |
;; subscription | |
(rf/reg-sub | |
:token | |
(fn [db] | |
(:token db))) | |
;; component | |
(defn main-panel [] | |
(let [name (rf/subscribe [:name]) | |
token (rf/subscribe [:token])] | |
(prn @token) | |
[:div {:class "main-panel"} | |
[:h1 {:class "title"} @name] | |
[text-input "filter projects: " #(rf/dispatch [:text-input %])] | |
[project-list]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment