Created
January 22, 2016 17:49
-
-
Save joshkh/cd7ec25d97e91dd17290 to your computer and use it in GitHub Desktop.
Reagent Ajax
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
(ns bluegenes.tools.faketool.core | |
(:require [re-frame.core :as re-frame] | |
[reagent.core :as reagent] | |
[clojure.string :as str] | |
[intermine.imjs :as imjs])) | |
(defn fetch-templates-handler [app-state] | |
(let [mine (js/imjs.Service. (clj->js {:root "www.flymine.org/query"})) | |
tpl-promise (-> mine .fetchTemplates)] | |
(-> tpl-promise (.then (fn [templates] | |
(swap! app-state assoc :templates (js->clj templates))))))) | |
(defn drop-down [app-state] | |
[:div | |
[:select.form-group (for [[k v] (seq (:templates @app-state))] | |
[:option {:value (get v "name")} (get v "title")])]]) | |
(defn text-box [] | |
[:input {:type "text" :value "hi"}]) | |
(defn add-state-button [comms] | |
(println "-- button renredered") | |
[:button.btn | |
{:on-click (fn [] | |
(println "HI") | |
((:append-state comms) {:input (rand-int 100)}))} | |
"Change State"]) | |
(defn ^:export main [] | |
(let [app-state (reagent.core/atom {:templates nil :selected nil :query nil})] | |
(reagent/create-class | |
{:component-did-mount (fn [] | |
fetch-templates-handler app-state) | |
:reagent-render (fn [input comms] | |
[:div | |
[add-state-button comms] | |
[text-box] | |
[drop-down app-state]])}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment