@@ -1,3 +1,4 @@
1module Reflex.Dom.Xhr
2module Reflex.Dom.Xhr
2 ( module Reflex.Dom.Xhr
3 ( module Reflex.Dom.Xhr
3 , XMLHttpRequest
4 , XMLHttpRequest
@@ -33,19 +34,19 @@ import Reflex.Dom.Class
33import Reflex.Dom.Xhr.Foreign
34import Reflex.Dom.Xhr.Foreign
34import Data.Typeable
35import Data.Typeable
36−data XhrRequest
37+data XhrRequest a
37 = XhrRequest { _xhrRequest_method :: String
38 = XhrRequest { _xhrRequest_method :: String
38 , _xhrRequest_url :: String
39 , _xhrRequest_url :: String
39− , _xhrRequest_config :: XhrRequestConfig
40+ , _xhrRequest_config :: XhrRequestConfig a
41 deriving (Show, Read, Eq, Ord, Typeable)
42 deriving (Show, Read, Eq, Ord, Typeable)
43−data XhrRequestConfig
44+data XhrRequestConfig a
44 = XhrRequestConfig { _xhrRequestConfig_headers :: Map String String
45 = XhrRequestConfig { _xhrRequestConfig_headers :: Map String String
45 , _xhrRequestConfig_user :: Maybe String
46 , _xhrRequestConfig_user :: Maybe String
46 , _xhrRequestConfig_password :: Maybe String
47 , _xhrRequestConfig_password :: Maybe String
47 , _xhrRequestConfig_responseType :: Maybe String
48 , _xhrRequestConfig_responseType :: Maybe String
48− , _xhrRequestConfig_sendData :: Maybe String
49+ , _xhrRequestConfig_sendData :: a
50 deriving (Show, Read, Eq, Ord, Typeable)
51 deriving (Show, Read, Eq, Ord, Typeable)
@@ -54,18 +55,18 @@ data XhrResponse
55 deriving (Show, Read, Eq, Ord, Typeable)
56 deriving (Show, Read, Eq, Ord, Typeable)
57−instance Default XhrRequestConfig where
58+instance a ~ () => Default (XhrRequestConfig a) where
58 def = XhrRequestConfig { _xhrRequestConfig_headers = Map.empty
59 def = XhrRequestConfig { _xhrRequestConfig_headers = Map.empty
59 , _xhrRequestConfig_user = Nothing
60 , _xhrRequestConfig_user = Nothing
60 , _xhrRequestConfig_password = Nothing
61 , _xhrRequestConfig_password = Nothing
61 , _xhrRequestConfig_responseType = Nothing
62 , _xhrRequestConfig_responseType = Nothing
62− , _xhrRequestConfig_sendData = Nothing
63+ , _xhrRequestConfig_sendData = ()
65−xhrRequest :: String -> String -> XhrRequestConfig -> XhrRequest
66+xhrRequest :: String -> String -> XhrRequestConfig a -> XhrRequest a
66xhrRequest = XhrRequest
67xhrRequest = XhrRequest
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
69newXMLHttpRequest req cb = do
70newXMLHttpRequest req cb = do
70 wv <- askWebView
71 wv <- askWebView
71 postGui <- askPostGui
72 postGui <- askPostGui
@@ -92,12 +93,12 @@ newXMLHttpRequest req cb = do
92 _ <- xmlHttpRequestSend xhr (_xhrRequestConfig_sendData c)
93 _ <- xmlHttpRequestSend xhr (_xhrRequestConfig_sendData c)
93 return xhr
94 return xhr
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)
96performRequestAsync req = performEventAsync $ ffor req $ \r cb -> do
97performRequestAsync req = performEventAsync $ ffor req $ \r cb -> do
97 _ <- newXMLHttpRequest r $ liftIO . cb
98 _ <- newXMLHttpRequest r $ liftIO . cb
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))
101performRequestsAsync req = performEventAsync $ ffor req $ \rs cb -> do
102performRequestsAsync req = performEventAsync $ ffor req $ \rs cb -> do
102 resps <- forM rs $ \r -> do
103 resps <- forM rs $ \r -> do
103 resp <- liftIO newEmptyMVar
104 resp <- liftIO newEmptyMVar