Skip to content

Commit

Permalink
basic client
Browse files Browse the repository at this point in the history
  • Loading branch information
myguidingstar committed Nov 15, 2020
1 parent 7e0cbee commit 1e5b501
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions src/conduit/client.cljs
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
(ns conduit.client
(:require [fulcro.client :as fc]
[conduit.ui.root :as root]
[conduit.ui.other :refer [token-store]]
[fulcro.client.network :as net]))
(:require
[com.fulcrologic.fulcro.application :as app]
[com.fulcrologic.fulcro.networking.http-remote :as http]
[com.fulcrologic.fulcro.components :as comp :refer [defsc]]
[com.fulcrologic.fulcro.data-fetch :as df]
[com.fulcrologic.fulcro.inspect.preload]
[com.fulcrologic.fulcro.dom :as dom]))

(defn wrap-with-token [req]
(if-let [token @token-store]
(assoc-in req [:headers "Authorization"] token)
req))
(def secured-request-middleware
(-> (or js/fulcro_network_csrf_token "TOKEN-NOT-IN-HTML!")
(http/wrap-csrf-token)
(http/wrap-fulcro-request)))

(def remote
(net/fulcro-http-remote
{:url "/api"
:request-middleware (net/wrap-fulcro-request wrap-with-token)}))
(def app-remote
(http/fulcro-http-remote {:url "/api"
:request-middleware secured-request-middleware}))

(defonce app (atom (fc/new-fulcro-client
:reconciler-options {:shared-fn #(select-keys % [:user/whoami])}
:started-callback root/started-callback
:networking {:remote remote})))
(def app
(app/fulcro-app
{:remotes {:remote app-remote}}))

(defsc Person [this {:person/keys [id name age] :as props} {:keys [onDelete]}]
{:query [:person/id :person/name :person/age]
:ident (fn [] [:person/id (:person/id props)])}
(dom/li
(dom/h5 (str name " (age: " age ")") (dom/button {:onClick #(onDelete id)} "X"))))

(defsc Root [this props]
(dom/div "hello inspect"))

(defn ^:export init
[]
(app/mount! app Root "app")
(df/load app [:person/id 1] Person)
(js/console.log "Loaded"))

(init)

0 comments on commit 1e5b501

Please sign in to comment.