Skip to content

Commit 771ce47

Browse files
committed
Move DOM.Types and some http to simple-dom
Use many HTTP-related types now present in simple-dom.
1 parent cdf9c0e commit 771ce47

File tree

5 files changed

+109
-253
lines changed

5 files changed

+109
-253
lines changed

MODULE.md

Lines changed: 24 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -377,44 +377,44 @@
377377

378378
### Types
379379

380-
type Config a b c d = { responseType :: ResponseType, withCredentials :: Boolean, timeout :: Either Number (Promise c d), cache :: Either Boolean Cache, xsrfCookieName :: String, xsrfHeaderName :: String, headers :: Headers, "data" :: RequestData b, params :: { | a }, url :: Url, method :: Method }
380+
type Config a b c d = { responseType :: D.ResponseType, withCredentials :: Boolean, timeout :: Either Number (Promise c d), cache :: Either Boolean Cache, xsrfCookieName :: String, xsrfHeaderName :: String, headers :: Headers, "data" :: RequestData b, params :: { | a }, url :: D.Url, method :: D.HttpMethod }
381381

382382
data Http :: *
383383

384384
type HttpResponse e r a b c d = HttpEff e (Promise (Response r a b c d) (Response r a b c d))
385385

386-
type Response r a b c d = { statusText :: String, config :: Config a b c d, headers :: [String] -> String, status :: Status, "data" :: ResponseData r }
386+
type Response r a b c d = { statusText :: String, config :: Config a b c d, headers :: [String] -> String, status :: Status, "data" :: D.HttpData r }
387387

388388

389389
### Values
390390

391391
config :: forall a b c d. Config a b c d
392392

393-
del :: forall e r a b c d. Url -> Http -> HttpResponse e r a b c d
393+
del :: forall e r a b c d. D.Url -> Http -> HttpResponse e r a b c d
394394

395-
del' :: forall e r a b c d. Url -> Config a b c d -> Http -> HttpResponse e r a b c d
395+
del' :: forall e r a b c d. D.Url -> Config a b c d -> Http -> HttpResponse e r a b c d
396396

397-
get :: forall e r a b c d. Url -> Http -> HttpResponse e r a b c d
397+
get :: forall e r a b c d. D.Url -> Http -> HttpResponse e r a b c d
398398

399-
get' :: forall e r a b c d. Url -> Config a b c d -> Http -> HttpResponse e r a b c d
399+
get' :: forall e r a b c d. D.Url -> Config a b c d -> Http -> HttpResponse e r a b c d
400400

401-
head :: forall e r a b c d. Url -> Http -> HttpResponse e r a b c d
401+
head :: forall e r a b c d. D.Url -> Http -> HttpResponse e r a b c d
402402

403-
head' :: forall e r a b c d. Url -> Config a b c d -> Http -> HttpResponse e r a b c d
403+
head' :: forall e r a b c d. D.Url -> Config a b c d -> Http -> HttpResponse e r a b c d
404404

405405
http :: forall e r a b c d. Config a b c d -> Http -> HttpResponse e r a b c d
406406

407-
jsonp :: forall e r a b c d. Url -> Http -> HttpResponse e r a b c d
407+
jsonp :: forall e r a b c d. D.Url -> Http -> HttpResponse e r a b c d
408408

409-
jsonp' :: forall e r a b c d. Url -> Config a b c d -> Http -> HttpResponse e r a b c d
409+
jsonp' :: forall e r a b c d. D.Url -> Config a b c d -> Http -> HttpResponse e r a b c d
410410

411-
post :: forall e r a b c d. Url -> RequestData b -> Http -> HttpResponse e r a b c d
411+
post :: forall e r a b c d. D.Url -> RequestData b -> Http -> HttpResponse e r a b c d
412412

413-
post' :: forall e r a b c d. Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
413+
post' :: forall e r a b c d. D.Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
414414

415-
put :: forall e r a b c d. Url -> RequestData b -> Http -> HttpResponse e r a b c d
415+
put :: forall e r a b c d. D.Url -> RequestData b -> Http -> HttpResponse e r a b c d
416416

417-
put' :: forall e r a b c d. Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
417+
put' :: forall e r a b c d. D.Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
418418

419419

420420
## Module Angular.Injector
@@ -888,23 +888,6 @@
888888
timeoutk :: forall e f r. Number -> Boolean -> Timeout -> Eff f r -> TimeoutEff e (TimeoutPromise r)
889889

890890

891-
## Module DOM.Types
892-
893-
### Types
894-
895-
data ArrayBuffer :: *
896-
897-
data Blob :: *
898-
899-
data Document :: *
900-
901-
data MozBlob :: *
902-
903-
data MozChunkedArrayBuffer :: *
904-
905-
data MozChunkedText :: *
906-
907-
908891
## Module Angular.Http.Internal
909892

910893
### Types
@@ -922,17 +905,17 @@
922905

923906
getConfigHeaders :: ForeignConfig -> Headers
924907

925-
getConfigMethod :: ForeignConfig -> Method
908+
getConfigMethod :: ForeignConfig -> D.HttpMethod
926909

927910
getConfigParams :: forall a. ForeignConfig -> { | a }
928911

929912
getConfigRequestData :: forall e a. ForeignConfig -> RequestData a
930913

931-
getConfigResponseType :: ForeignConfig -> ResponseType
914+
getConfigResponseType :: ForeignConfig -> D.ResponseType
932915

933916
getConfigTimeout :: forall a b. ForeignConfig -> Either Number (Promise a b)
934917

935-
getConfigUrl :: ForeignConfig -> Url
918+
getConfigUrl :: ForeignConfig -> D.Url
936919

937920
getConfigWithCredentials :: ForeignConfig -> Boolean
938921

@@ -942,7 +925,7 @@
942925

943926
getResponseConfig :: ForeignResponse -> ForeignConfig
944927

945-
getResponseData :: forall a. ResponseType -> ForeignResponse -> ResponseData a
928+
getResponseData :: forall a. D.ResponseType -> ForeignResponse -> D.HttpData a
946929

947930
getResponseHeaders :: ForeignResponse -> [String] -> String
948931

@@ -954,17 +937,17 @@
954937

955938
setConfigHeaders :: forall e. Headers -> ForeignConfig -> HttpEff e Unit
956939

957-
setConfigMethod :: forall e. Method -> ForeignConfig -> HttpEff e Unit
940+
setConfigMethod :: forall e. D.HttpMethod -> ForeignConfig -> HttpEff e Unit
958941

959942
setConfigParams :: forall e a. { | a } -> ForeignConfig -> HttpEff e Unit
960943

961944
setConfigRequestData :: forall e a. RequestData a -> ForeignConfig -> HttpEff e Unit
962945

963-
setConfigResponseType :: forall e. ResponseType -> ForeignConfig -> HttpEff e Unit
946+
setConfigResponseType :: forall e. D.ResponseType -> ForeignConfig -> HttpEff e Unit
964947

965948
setConfigTimeout :: forall e a b. Either Number (Promise a b) -> ForeignConfig -> HttpEff e Unit
966949

967-
setConfigUrl :: forall e. Url -> ForeignConfig -> HttpEff e Unit
950+
setConfigUrl :: forall e. D.Url -> ForeignConfig -> HttpEff e Unit
968951

969952
setConfigWithCredentials :: forall e. Boolean -> ForeignConfig -> HttpEff e Unit
970953

@@ -994,16 +977,6 @@
994977

995978
type HttpEff e r = Eff (nghttp :: NgHttp | e) r
996979

997-
data Method where
998-
GET :: Method
999-
POST :: Method
1000-
PUT :: Method
1001-
DELETE :: Method
1002-
PATCH :: Method
1003-
HEAD :: Method
1004-
OPTIONS :: Method
1005-
JSONP :: Method
1006-
1007980
data NgHttp :: !
1008981

1009982
data RequestData a where
@@ -1013,31 +986,6 @@
1013986

1014987
type RequestDataFn a = { objectRequestData :: a -> RequestData a, stringRequestData :: String -> RequestData a, noRequestData :: RequestData a }
1015988

1016-
data ResponseData a where
1017-
NoResponseData :: ResponseData a
1018-
DefaultResponseData :: String -> ResponseData a
1019-
ArrayBufferResponseData :: D.ArrayBuffer -> ResponseData a
1020-
BlobResponseData :: D.Blob -> ResponseData a
1021-
DocumentResponseData :: D.Document -> ResponseData a
1022-
JsonResponseData :: a -> ResponseData a
1023-
TextResponseData :: String -> ResponseData a
1024-
MozBlobResponseData :: D.MozBlob -> ResponseData a
1025-
MozChunkedTextResponseData :: D.MozChunkedText -> ResponseData a
1026-
MozChunkedArrayBufferResponseData :: D.MozChunkedArrayBuffer -> ResponseData a
1027-
1028-
type ResponseDataFn a = { mozChunkedArrayBufferResponseData :: D.MozChunkedArrayBuffer -> ResponseData a, mozChunkedTextResponseData :: D.MozChunkedText -> ResponseData a, mozBlobResponseData :: D.MozBlob -> ResponseData a, textResponseData :: String -> ResponseData a, jsonResponseData :: a -> ResponseData a, documentResponseData :: D.Document -> ResponseData a, blobResponseData :: D.Blob -> ResponseData a, arrayBufferResponseData :: D.ArrayBuffer -> ResponseData a, defaultResponseData :: String -> ResponseData a, noResponseData :: ResponseData a }
1029-
1030-
data ResponseType where
1031-
Default :: ResponseType
1032-
ArrayBuffer :: ResponseType
1033-
Blob :: ResponseType
1034-
Document :: ResponseType
1035-
Json :: ResponseType
1036-
Text :: ResponseType
1037-
MozBlob :: ResponseType
1038-
MozChunkedText :: ResponseType
1039-
MozChunkedArrayBuffer :: ResponseType
1040-
1041989
data Status where
1042990
OK :: Status
1043991
Created :: Status
@@ -1049,15 +997,6 @@
1049997
InternalServerError :: Status
1050998
OtherStatus :: Number -> Status
1051999

1052-
type Url = String
1053-
1054-
1055-
### Type Class Instances
1056-
1057-
instance showMethod :: Show Method
1058-
1059-
instance showResponseType :: Show ResponseType
1060-
10611000

10621001
### Values
10631002

@@ -1069,13 +1008,13 @@
10691008

10701009
readHeadersFn :: forall a b. Fn4 (String -> Either String (Unit -> String)) ((Unit -> String) -> Either String (Unit -> String)) (String -> Either String (Unit -> String) -> Header) ForeignHeaders Headers
10711010

1072-
readMethod :: String -> Method
1011+
readMethod :: String -> D.HttpMethod
10731012

10741013
readRequestDataFn :: forall a. Fn2 (RequestDataFn a) ForeignRequestData (RequestData a)
10751014

1076-
readResponseDataFn :: forall a. Fn3 (ResponseDataFn a) String ForeignResponseData (ResponseData a)
1015+
readResponseData :: forall a d. (d -> D.HttpData a) -> ForeignResponseData -> D.HttpData a
10771016

1078-
readResponseType :: String -> ResponseType
1017+
readResponseType :: String -> D.ResponseType
10791018

10801019
readStatus :: Number -> Status
10811020

src/Angular/Http.purs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import Data.Function
2525
import Data.Maybe
2626
import Data.Tuple
2727

28+
import qualified Data.DOM.Simple.Ajax as D
29+
2830
import Angular.Cache (Cache())
2931
import qualified Angular.Http.Internal as I
3032
import Angular.Http.Types
@@ -37,16 +39,16 @@ type HttpResponse e r a b c d = HttpEff e (Promise (Response r a b c d) (Respons
3739
type ForeignHttpResponse e = HttpEff e (Promise I.ForeignResponse I.ForeignResponse)
3840

3941
type Response r a b c d
40-
= { "data" :: ResponseData r
42+
= { "data" :: D.HttpData r
4143
, status :: Status
4244
, headers :: [String] -> String
4345
, config :: Config a b c d
4446
, statusText :: String
4547
}
4648

4749
type Config a b c d
48-
= { method :: Method
49-
, url :: Url
50+
= { method :: D.HttpMethod
51+
, url :: D.Url
5052
, params :: { | a }
5153
, "data" :: RequestData b
5254
, headers :: Headers
@@ -55,15 +57,15 @@ type Config a b c d
5557
, cache :: Either Boolean Cache
5658
, timeout :: Either Number (Promise c d)
5759
, withCredentials :: Boolean
58-
, responseType :: ResponseType
60+
, responseType :: D.ResponseType
5961
}
6062

6163
xsrfHeaderName = "X-XSRF-TOKEN"
6264

6365
xsrfCookieName = "XSRF-TOKEN"
6466

6567
config :: forall a b c d. Config a b c d
66-
config = { method: GET
68+
config = { method: D.GET
6769
, url: "/"
6870
, params: runFn0 emptyParams
6971
, "data": NoRequestData
@@ -73,54 +75,54 @@ config = { method: GET
7375
, cache: Left false
7476
, timeout: Left 0
7577
, withCredentials: false
76-
, responseType: Default }
78+
, responseType: D.Default }
7779

7880
http :: forall e r a b c d. Config a b c d -> Http -> HttpResponse e r a b c d
7981
http c h = (bimap foreignResponse foreignResponse) <$> (foreignConfig c >>= runFn2 httpFn h)
8082

81-
get :: forall e r a b c d. Url -> Http -> HttpResponse e r a b c d
82-
get u = runHttpFn' GET u config
83+
get :: forall e r a b c d. D.Url -> Http -> HttpResponse e r a b c d
84+
get u = runHttpFn' D.GET u config
8385

84-
get' :: forall e r a b c d. Url -> Config a b c d -> Http -> HttpResponse e r a b c d
85-
get' = runHttpFn' GET
86+
get' :: forall e r a b c d. D.Url -> Config a b c d -> Http -> HttpResponse e r a b c d
87+
get' = runHttpFn' D.GET
8688

87-
del :: forall e r a b c d. Url -> Http -> HttpResponse e r a b c d
88-
del u = runHttpFn' DELETE u config
89+
del :: forall e r a b c d. D.Url -> Http -> HttpResponse e r a b c d
90+
del u = runHttpFn' D.DELETE u config
8991

90-
del' :: forall e r a b c d. Url -> Config a b c d -> Http -> HttpResponse e r a b c d
91-
del' = runHttpFn' DELETE
92+
del' :: forall e r a b c d. D.Url -> Config a b c d -> Http -> HttpResponse e r a b c d
93+
del' = runHttpFn' D.DELETE
9294

93-
head :: forall e r a b c d. Url -> Http -> HttpResponse e r a b c d
94-
head u = runHttpFn' HEAD u config
95+
head :: forall e r a b c d. D.Url -> Http -> HttpResponse e r a b c d
96+
head u = runHttpFn' D.HEAD u config
9597

96-
head' :: forall e r a b c d. Url -> Config a b c d -> Http -> HttpResponse e r a b c d
97-
head' = runHttpFn' HEAD
98+
head' :: forall e r a b c d. D.Url -> Config a b c d -> Http -> HttpResponse e r a b c d
99+
head' = runHttpFn' D.HEAD
98100

99-
jsonp :: forall e r a b c d. Url -> Http -> HttpResponse e r a b c d
100-
jsonp u = runHttpFn' JSONP u config
101+
jsonp :: forall e r a b c d. D.Url -> Http -> HttpResponse e r a b c d
102+
jsonp u = runHttpFn' D.JSONP u config
101103

102-
jsonp' :: forall e r a b c d. Url -> Config a b c d -> Http -> HttpResponse e r a b c d
103-
jsonp' = runHttpFn' JSONP
104+
jsonp' :: forall e r a b c d. D.Url -> Config a b c d -> Http -> HttpResponse e r a b c d
105+
jsonp' = runHttpFn' D.JSONP
104106

105-
post :: forall e r a b c d. Url -> RequestData b -> Http -> HttpResponse e r a b c d
106-
post u d = runHttpFn'' POST u d config
107+
post :: forall e r a b c d. D.Url -> RequestData b -> Http -> HttpResponse e r a b c d
108+
post u d = runHttpFn'' D.POST u d config
107109

108-
post' :: forall e r a b c d. Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
109-
post' = runHttpFn'' POST
110+
post' :: forall e r a b c d. D.Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
111+
post' = runHttpFn'' D.POST
110112

111-
put :: forall e r a b c d. Url -> RequestData b -> Http -> HttpResponse e r a b c d
112-
put u d = runHttpFn'' PUT u d config
113+
put :: forall e r a b c d. D.Url -> RequestData b -> Http -> HttpResponse e r a b c d
114+
put u d = runHttpFn'' D.PUT u d config
113115

114-
put' :: forall e r a b c d. Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
115-
put' = runHttpFn'' PUT
116+
put' :: forall e r a b c d. D.Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
117+
put' = runHttpFn'' D.PUT
116118

117-
runHttpFn' :: forall e r a b c d. Method -> Url -> Config a b c d -> Http -> HttpResponse e r a b c d
119+
runHttpFn' :: forall e r a b c d. D.HttpMethod -> D.Url -> Config a b c d -> Http -> HttpResponse e r a b c d
118120
runHttpFn' m u c h = do
119121
conf <- foreignConfig c
120122
res <- runFn4 httpFn' (show m) u conf h
121123
return $ bimap foreignResponse foreignResponse res
122124

123-
runHttpFn'' :: forall e r a b c d. Method -> Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
125+
runHttpFn'' :: forall e r a b c d. D.HttpMethod -> D.Url -> RequestData b -> Config a b c d -> Http -> HttpResponse e r a b c d
124126
runHttpFn'' m u d c h = do
125127
conf <- foreignConfig c
126128
res <- runFn5 httpFn'' (show m) u (writeRequestData d) conf h
@@ -178,7 +180,7 @@ foreign import httpFn'
178180
\ } \
179181
\ } "
180182
:: forall e. Fn4 String
181-
Url
183+
D.Url
182184
I.ForeignConfig
183185
Http
184186
(ForeignHttpResponse e)
@@ -190,7 +192,7 @@ foreign import httpFn''
190192
\ } \
191193
\ } "
192194
:: forall e. Fn5 String
193-
Url
195+
D.Url
194196
ForeignRequestData
195197
I.ForeignConfig
196198
Http

0 commit comments

Comments
 (0)