Advertisement
TurboTapir

Untitled

Jan 27th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns search.core
  2.  (:require-macros [cljs.core.async.macros :refer [go]])
  3.   (:require [rum.core :as rum]
  4.   [cljs-http.client :as http]
  5.     [cljs.core.async :refer [<!]]))
  6.  
  7. (enable-console-print!)
  8.  
  9.  
  10.  
  11. (defn fetch-data-from-api
  12.       [searchVal]
  13.         ( go (let [response  (<! (http/get "moje-API/query" {:accept "application/json" :query-params {"results" 5 "search-string" searchVal}}))]
  14.        
  15.  
  16.          (prn  response)
  17.         )))
  18.  
  19.        
  20.      
  21.  
  22. (rum/defc search-input []
  23.   [:form#search-input-container  {
  24.     :on-submit (fn [e]
  25.                   (
  26.                    
  27.                     .preventDefault e
  28.                  
  29.                     (def searchVal (.-value (js/document.getElementById "search-input")))
  30.                     (fetch-data-from-api searchVal)
  31.                     )
  32.                  
  33.                 )}
  34.     [:input#search-input.input { :type "text"}]
  35.     [:button#search-button {:type "submit"}[:span.fa.fa-search]]
  36.     ])
  37.  
  38. (rum/defc container [text]
  39.   [:div#search-container])
  40.  
  41.  
  42.  (rum/mount (container) (js/document.getElementById "search-app"))
  43.  (rum/mount (search-input) (js/document.getElementById "search-container"))
  44.  
  45.  
  46. (defn on-js-reload []
  47.   ;; optionally touch your app-state to force rerendering depending on
  48.   ;; your application
  49.   ;; (swap! app-state update-in [:__figwheel_counter] inc)
  50. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement