@@ -84,20 +84,36 @@ class HasReflexClient layout where
8484 -> Client (Input layout) (Output layout)
8585
8686
87−-- -- | If you have a 'Get' endpoint in your API, the client
88−-- -- side querying function that is created when calling 'client'
89−-- -- will just require an argument that specifies the scheme, host
90−-- -- and port to send the request to.
91−-- instance
92−-- #if MIN_VERSION_base(4,8,0)
93−-- {-# OVERLAPPABLE #-}
94−-- #endif
95−-- (MimeUnrender ct result) => HasReflexClient (Get (ct ': cts) result) where
96−-- type Input (Get (ct ': cts) result) = ()
97−-- -- type Output (Get (ct' : cts) result) = result
98−-- type Client (Get (ct ': cts) result) = Final result
99−-- clientWithRoute Proxy req baseurl _ =
100−-- snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req baseurl
87+-- | If you have a 'Get' endpoint in your API, the client
88+-- side querying function that is created when calling 'client'
89+-- will just require an argument that specifies the scheme, host
90+-- and port to send the request to.
91+instance
92+#if MIN_VERSION_base(4,8,0)
93+ {-# OVERLAPPABLE #-}
94+#endif
95+ (MimeUnrender ct result) => HasReflexClient (Get (ct ': cts) result) where
96+ type Input (Get (ct ': cts) result) = ()
97+ type Output (Get (ct' : cts) result) = result
98+ clientWithRoute Proxy req baseurl trigEvents = performAJAX requestBuilder responseParser
99+ where
100+ requestBuilder _ = XhrRequest "GET" (showBaseUrl baseurl) def
101+ responseParser xhrResp =
102+
103+performAJAX
104+ :: (MonadWidget t m)
105+ => (a -> XhrRequest)
106+ -- ^ Function to build the request
107+ -> (XhrResponse -> b)
108+ -- ^ Function to parse the response
109+ -> Event t a
110+ -> m (Event t (a, b))
111+performAJAX mkRequest parseResponse req =
112+ performEventAsync $ ffor req $ \a cb -> do
113+ _ <- newXMLHttpRequest (mkRequest a) $ \response ->
114+ liftIO $ cb (a, parseResponse response)
115+ return ()
116+
101117
102118instance
103119#if MIN_VERSION_base(4,8,0)
@@ -106,7 +122,6 @@ instance
106122 HasReflexClient (Get (ct ': cts) ()) where
107123 type Input (Get (ct ': cts) ()) = ()
108124 type Output (Get (ct ': cts) ()) = ()
109− -- type Client (Get (ct ': cts) ()) = Final ()
110125 clientWithRoute Proxy req baseurl trigEvents =
111126 performAJAX requestBuilder responseParser trigEvents
112127 where