@@ -1,3 +1,4 @@
1+{-# LANGUAGE GADTs #-}
12module Reflex.Dom.Xhr
23 ( module Reflex.Dom.Xhr
34 , XMLHttpRequest
@@ -33,19 +34,19 @@ import Reflex.Dom.Class
3334import Reflex.Dom.Xhr.Foreign
3435import Data.Typeable
3536
36−data XhrRequest
37+data XhrRequest a
3738 = XhrRequest { _xhrRequest_method :: String
3839 , _xhrRequest_url :: String
39− , _xhrRequest_config :: XhrRequestConfig
40+ , _xhrRequest_config :: XhrRequestConfig a
4041 }
4142 deriving (Show, Read, Eq, Ord, Typeable)
4243
43−data XhrRequestConfig
44+data XhrRequestConfig a
4445 = XhrRequestConfig { _xhrRequestConfig_headers :: Map String String
4546 , _xhrRequestConfig_user :: Maybe String
4647 , _xhrRequestConfig_password :: Maybe String
4748 , _xhrRequestConfig_responseType :: Maybe String
48− , _xhrRequestConfig_sendData :: Maybe String
49+ , _xhrRequestConfig_sendData :: a
4950 }
5051 deriving (Show, Read, Eq, Ord, Typeable)
5152
@@ -54,18 +55,18 @@ data XhrResponse
5455 }
5556 deriving (Show, Read, Eq, Ord, Typeable)
5657
57−instance Default XhrRequestConfig where
58+instance a ~ () => Default (XhrRequestConfig a) where
5859 def = XhrRequestConfig { _xhrRequestConfig_headers = Map.empty
5960 , _xhrRequestConfig_user = Nothing
6061 , _xhrRequestConfig_password = Nothing
6162 , _xhrRequestConfig_responseType = Nothing
62− , _xhrRequestConfig_sendData = Nothing
63+ , _xhrRequestConfig_sendData = ()
6364 }
6465
65−xhrRequest :: String -> String -> XhrRequestConfig -> XhrRequest
66+xhrRequest :: String -> String -> XhrRequestConfig a -> XhrRequest a
6667xhrRequest = XhrRequest
6768
68−newXMLHttpRequest :: (HasWebView m, MonadIO m, HasPostGui t h m) => XhrRequest -> (XhrResponse -> h ()) -> m XMLHttpRequest
69+newXMLHttpRequest :: (HasWebView m, MonadIO m, HasPostGui t h m, IsXhrPayload a) => XhrRequest a -> (XhrResponse -> h ()) -> m XMLHttpRequest
6970newXMLHttpRequest req cb = do
7071 wv <- askWebView
7172 postGui <- askPostGui
@@ -92,12 +93,12 @@ newXMLHttpRequest req cb = do
9293 _ <- xmlHttpRequestSend xhr (_xhrRequestConfig_sendData c)
9394 return xhr
9495
95−performRequestAsync :: (MonadWidget t m) => Event t XhrRequest -> m (Event t XhrResponse)
96+performRequestAsync :: (MonadWidget t m, IsXhrPayload a) => Event t (XhrRequest a) -> m (Event t XhrResponse)
9697performRequestAsync req = performEventAsync $ ffor req $ \r cb -> do
9798 _ <- newXMLHttpRequest r $ liftIO . cb
9899 return ()
99100
100−performRequestsAsync :: (Traversable f, MonadWidget t m) => Event t (f XhrRequest) -> m (Event t (f XhrResponse))
101+performRequestsAsync :: (Traversable f, MonadWidget t m, IsXhrPayload a) => Event t (f (XhrRequest a)) -> m (Event t (f XhrResponse))
101102performRequestsAsync req = performEventAsync $ ffor req $ \rs cb -> do
102103 resps <- forM rs $ \r -> do
103104 resp <- liftIO newEmptyMVar