-
Notifications
You must be signed in to change notification settings - Fork 3
/
mock_server.cljs
26 lines (24 loc) · 1.2 KB
/
mock_server.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(ns com.example.mock-server
"A mock remote for Fulcro that talks to the in-browser Pathom parser
Inspired heavily by https://github.com/fulcrologic/fulcro-developer-guide/blob/master/src/book/book/pathom.cljs"
(:require
[com.example.pathom :as pathom]
[com.fulcrologic.fulcro.algorithms.tx-processing :as txn]
[com.fulcrologic.fulcro.networking.mock-server-remote :refer [mock-http-server]]))
(defn mock-remote
"A remote in Fulcro is just a map with a `:transmit!` key"
([env]
(let [parser (pathom/new-parser)
transmit! (:transmit! (mock-http-server {:parser (fn [req] (parser env req))}))]
{:transmit! (fn [this send-node]
(js/setTimeout ; simulate some network delay, for fun
#(transmit! this
(update send-node
::txn/result-handler
(fn [handler]
(fn logging-wrapper [res]
(println "MOCK SERVER RESULT> " res)
(when handler (handler res))))))
100))}))
([]
(mock-remote {})))