-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e0cbee
commit 1e5b501
Showing
1 changed file
with
34 additions
and
16 deletions.
There are no files selected for viewing
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
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) |