@@ -84,20 +84,36 @@ class HasReflexClient layout where
84 -> Client (Input layout) (Output layout)
84 -> Client (Input layout) (Output layout)
87−-- -- | If you have a 'Get' endpoint in your API, the client
87+-- | If you have a 'Get' endpoint in your API, the client
88−-- -- side querying function that is created when calling 'client'
88+-- side querying function that is created when calling 'client'
89−-- -- will just require an argument that specifies the scheme, host
89+-- will just require an argument that specifies the scheme, host
90−-- -- and port to send the request to.
90+-- and port to send the request to.
91−-- instance
91+instance
92−-- #if MIN_VERSION_base(4,8,0)
92+#if MIN_VERSION_base(4,8,0)
93−-- {-# OVERLAPPABLE #-}
93+ {-# OVERLAPPABLE #-}
95−-- (MimeUnrender ct result) => HasReflexClient (Get (ct ': cts) result) where
95+ (MimeUnrender ct result) => HasReflexClient (Get (ct ': cts) result) where
96−-- type Input (Get (ct ': cts) result) = ()
96+ type Input (Get (ct ': cts) result) = ()
97−-- -- type Output (Get (ct' : cts) result) = result
97+ type Output (Get (ct' : cts) result) = result
98−-- type Client (Get (ct ': cts) result) = Final result
99−-- clientWithRoute Proxy req baseurl _ =
98+ clientWithRoute Proxy req baseurl trigEvents = performAJAX requestBuilder responseParser
100−-- snd <$> performRequestCT (Proxy :: Proxy ct) H.methodGet req baseurl
99+ where
100+ requestBuilder _ = XhrRequest "GET" (showBaseUrl baseurl) def
101+ responseParser xhrResp =
104+ :: (MonadWidget t m)
105+ => (a -> XhrRequest)
106+ -- ^ Function to build the request
107+ -> (XhrResponse -> b)
108+ -- ^ Function to parse the response
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)
103#if MIN_VERSION_base(4,8,0)
119#if MIN_VERSION_base(4,8,0)
@@ -106,7 +122,6 @@ instance
106 HasReflexClient (Get (ct ': cts) ()) where
122 HasReflexClient (Get (ct ': cts) ()) where
107 type Input (Get (ct ': cts) ()) = ()
123 type Input (Get (ct ': cts) ()) = ()
108 type Output (Get (ct ': cts) ()) = ()
124 type Output (Get (ct ': cts) ()) = ()
109− -- type Client (Get (ct ': cts) ()) = Final ()
110 clientWithRoute Proxy req baseurl trigEvents =
125 clientWithRoute Proxy req baseurl trigEvents =
111 performAJAX requestBuilder responseParser trigEvents
126 performAJAX requestBuilder responseParser trigEvents