Skip to content

Commit c363e5d

Browse files
authored
Merge pull request #3 from purescript-web/compiler/0.12
Compiler/0.12
2 parents bef0383 + cfdeb52 commit c363e5d

17 files changed

+409
-213
lines changed

.eslintrc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 5
4+
},
5+
"extends": "eslint:recommended",
6+
"env": {
7+
"commonjs": true,
8+
"browser": true
9+
},
10+
"rules": {
11+
"strict": [2, "global"],
12+
"block-scoped-var": 2,
13+
"consistent-return": 2,
14+
"eqeqeq": [2, "smart"],
15+
"guard-for-in": 2,
16+
"no-caller": 2,
17+
"no-extend-native": 2,
18+
"no-loop-func": 2,
19+
"no-new": 2,
20+
"no-param-reassign": 2,
21+
"no-return-assign": 2,
22+
"no-unused-expressions": 2,
23+
"no-use-before-define": 2,
24+
"radix": [2, "always"],
25+
"indent": [2, 2],
26+
"quotes": [2, "double"],
27+
"semi": [2, "always"]
28+
}
29+
}

.gitignore

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
/.*
2+
!/.gitignore
3+
!/.eslintrc.json
4+
!/.travis.yml
5+
package-lock.json
16
/bower_components/
27
/node_modules/
3-
/.pulp-cache/
48
/output/
5-
/.psc*
6-
/.psa*
7-
/.purs*
8-
/.vscode
9-
/package-lock.json

.travis.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ language: node_js
22
dist: trusty
33
sudo: required
44
node_js: stable
5+
env:
6+
- PATH=$HOME/purescript:$PATH
57
install:
6-
- npm install
8+
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
9+
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
10+
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
11+
- chmod a+x $HOME/purescript
712
- npm install -g bower
8-
- bower install --production
13+
- npm install
914
script:
15+
- bower install
1016
- npm run -s build
1117
after_success:
1218
- >-
1319
test $TRAVIS_TAG &&
1420
echo $GITHUB_TOKEN | pulp login &&
15-
echo y | pulp publish --no-push ||
16-
git status
21+
echo y | pulp publish --no-push

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
# purescript-web-xhr
22

3-
Low-level bindings for `XMLHttpRequest`.
3+
[![Latest release](http://img.shields.io/github/release/purescript-web/purescript-web-xhr.svg)](https://github.com/purescript-web/purescript-web-xhr/releases)
4+
[![Build status](https://travis-ci.org/purescript-web/purescript-web-xhr.svg?branch=master)](https://travis-ci.org/purescript-web/purescript-web-xhr)
5+
6+
Type definitions and low level interface implementations for the W3C XmlHttpRequest API.
7+
8+
## Installation
9+
10+
```
11+
bower install purescript-web-xhr
12+
```
13+
14+
## Documentation
15+
16+
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-web-xhr).

bower.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,10 @@
1616
"output"
1717
],
1818
"dependencies": {
19-
"purescript-prelude": "^3.0.0",
20-
"purescript-console": "^3.0.0",
21-
"purescript-dom": "^4.0.0",
22-
"purescript-datetime": "^3.0.0",
23-
"purescript-foreign": "^4.0.0",
24-
"purescript-nullable": "^3.0.0",
25-
"purescript-eff": "^3.1.0",
26-
"purescript-proxy": "^2.0.0",
27-
"purescript-unsafe-coerce": "^3.0.0",
28-
"purescript-maybe": "^3.0.0",
29-
"purescript-arraybuffer-types": "^1.0.0"
30-
},
31-
"devDependencies": {
32-
"purescript-psci-support": "^3.0.0"
19+
"purescript-arraybuffer-types": "^2.0.0",
20+
"purescript-datetime": "^4.0.0",
21+
"purescript-http-methods": "^4.0.0",
22+
"purescript-web-dom": "^1.0.0",
23+
"purescript-web-file": "^1.0.0"
3324
}
3425
}

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"private": true,
33
"scripts": {
4-
"build": "pulp build -- --strict --censor-lib"
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "eslint src && pulp build -- --censor-lib --strict"
56
},
67
"devDependencies": {
7-
"pulp": "^12.0.0",
8-
"purescript": "^0.11.6",
9-
"purescript-psa": "^0.5.0"
8+
"eslint": "^4.19.1",
9+
"pulp": "^12.2.0",
10+
"purescript-psa": "^0.6.0",
11+
"rimraf": "^2.6.2"
1012
}
1113
}

src/Web/XHR.purs

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Web/XHR/EventTypes.purs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Web.XHR.EventTypes where
2+
3+
import Web.Event.Event (EventType(..))
4+
5+
loadstart :: EventType
6+
loadstart = EventType "loadstart"
7+
8+
progress :: EventType
9+
progress = EventType "progress"
10+
11+
abort :: EventType
12+
abort = EventType "abort"
13+
14+
error :: EventType
15+
error = EventType "error"
16+
17+
load :: EventType
18+
load = EventType "load"
19+
20+
timeout :: EventType
21+
timeout = EventType "timeout"
22+
23+
loadend :: EventType
24+
loadend = EventType "loadend"

src/Web/XHR/FormData.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
exports["new"] = function() {
4+
return new FormData();
5+
};
6+
7+
exports._append = function(name, value, fd) {
8+
fd.append(name, value);
9+
};
10+
11+
exports._appendBlob = function(name, value, filename, fd) {
12+
fd.append(name, value, filename);
13+
};
14+
15+
exports._delete = function(name, fd) {
16+
fd.delete(name);
17+
};
18+
19+
exports._has = function(name, fd) {
20+
return fd.has(name);
21+
};
22+
23+
exports._set = function(name, value, fd) {
24+
fd.set(name, value);
25+
};
26+
27+
exports._setBlob = function(name, value, filename, fd) {
28+
fd.set(name, value, filename);
29+
};

src/Web/XHR/FormData.purs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
module Web.XHR.FormData
2+
( FormData
3+
, EntryName(..)
4+
, FileName(..)
5+
, new
6+
, append
7+
, appendBlob
8+
, delete
9+
, has
10+
, set
11+
, setBlob
12+
) where
13+
14+
import Prelude
15+
16+
import Data.Maybe (Maybe)
17+
import Data.Newtype (class Newtype)
18+
import Data.Nullable (Nullable, toNullable)
19+
import Effect (Effect)
20+
import Effect.Uncurried as Fn
21+
import Web.File.Blob (Blob)
22+
23+
foreign import data FormData :: Type
24+
25+
newtype EntryName = EntryName String
26+
27+
derive newtype instance eqEntryName :: Eq EntryName
28+
derive newtype instance ordEntryName :: Ord EntryName
29+
derive instance newtypeEntryName :: Newtype EntryName _
30+
31+
newtype FileName = FileName String
32+
33+
derive newtype instance eqFileName :: Eq FileName
34+
derive newtype instance ordFileName :: Ord FileName
35+
derive instance newtypeFileName :: Newtype FileName _
36+
37+
foreign import new :: Effect FormData
38+
39+
append :: EntryName -> String -> FormData -> Effect Unit
40+
append name value fd = Fn.runEffectFn3 _append name value fd
41+
42+
appendBlob :: EntryName -> Blob -> Maybe FileName -> FormData -> Effect Unit
43+
appendBlob name value filename fd = Fn.runEffectFn4 _appendBlob name value (toNullable filename) fd
44+
45+
delete :: EntryName -> FormData -> Effect Unit
46+
delete name fd = Fn.runEffectFn2 _delete name fd
47+
48+
has :: EntryName -> FormData -> Effect Boolean
49+
has name fd = Fn.runEffectFn2 _has name fd
50+
51+
set :: EntryName -> String -> FormData -> Effect Unit
52+
set name value fd = Fn.runEffectFn3 _set name value fd
53+
54+
setBlob :: EntryName -> Blob -> Maybe FileName -> FormData -> Effect Unit
55+
setBlob name value filename fd = Fn.runEffectFn4 _setBlob name value (toNullable filename) fd
56+
57+
-- void append(USVString name, USVString value);
58+
foreign import _append :: Fn.EffectFn3 EntryName String FormData Unit
59+
60+
-- void append(USVString name, Blob blobValue, optional USVString filename);
61+
foreign import _appendBlob :: Fn.EffectFn4 EntryName Blob (Nullable FileName) FormData Unit
62+
63+
-- void delete(USVString name);
64+
foreign import _delete :: Fn.EffectFn2 EntryName FormData Unit
65+
66+
-- boolean has(USVString name);
67+
foreign import _has :: Fn.EffectFn2 EntryName FormData Boolean
68+
69+
-- void set(USVString name, USVString value);
70+
foreign import _set :: Fn.EffectFn3 EntryName String FormData Unit
71+
72+
-- void set(USVString name, Blob blobValue, optional USVString filename);
73+
foreign import _setBlob :: Fn.EffectFn4 EntryName Blob (Nullable FileName) FormData Unit
74+
75+
-- FormDataEntryValue? get(USVString name);
76+
-- sequence<FormDataEntryValue> getAll(USVString name);
77+
-- iterable<USVString, FormDataEntryValue>;

src/Web/XHR/ProgressEvent.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
exports.lengthComputable = function(ev) {
4+
return ev.lengthComputable;
5+
};
6+
7+
exports.lengthComputable = function(ev) {
8+
return ev.lengthComputable;
9+
};
10+
11+
exports.loaded = function(ev) {
12+
return ev.loaded;
13+
};
14+
15+
exports.total = function(ev) {
16+
return ev.total;
17+
};

src/Web/XHR/ProgressEvent.purs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Web.XHR.ProgressEvent where
2+
3+
import Data.Maybe (Maybe)
4+
import Unsafe.Coerce (unsafeCoerce)
5+
import Web.Event.Event (Event)
6+
import Web.Internal.FFI (unsafeReadProtoTagged)
7+
8+
foreign import data ProgressEvent :: Type
9+
10+
fromEvent :: Event -> Maybe ProgressEvent
11+
fromEvent = unsafeReadProtoTagged "ProgressEvent"
12+
13+
toEvent :: ProgressEvent -> Event
14+
toEvent = unsafeCoerce
15+
16+
foreign import lengthComputable :: ProgressEvent -> Boolean
17+
18+
foreign import loaded :: ProgressEvent -> Number
19+
20+
foreign import total :: ProgressEvent -> Number

src/Web/XHR/ReadyState.purs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Web.XHR.ReadyState where
2+
3+
import Prelude
4+
5+
import Data.Enum (class BoundedEnum, class Enum, Cardinality(..), defaultPred, defaultSucc)
6+
import Data.Maybe (Maybe(..))
7+
8+
data ReadyState
9+
= Unsent
10+
| Opened
11+
| HeadersReceived
12+
| Loading
13+
| Done
14+
15+
derive instance eqReadyState :: Eq ReadyState
16+
derive instance ordReadyState :: Ord ReadyState
17+
18+
instance boundedReadyState :: Bounded ReadyState where
19+
bottom = Unsent
20+
top = Done
21+
22+
instance enumReadyState :: Enum ReadyState where
23+
succ = defaultSucc toEnum fromEnum
24+
pred = defaultPred toEnum fromEnum
25+
26+
instance boundedEnumReadyState :: BoundedEnum ReadyState where
27+
cardinality = Cardinality 5
28+
toEnum = toEnum
29+
fromEnum = fromEnum
30+
31+
toEnum :: Int -> Maybe ReadyState
32+
toEnum = case _ of
33+
0 -> Just Unsent
34+
1 -> Just Opened
35+
2 -> Just HeadersReceived
36+
3 -> Just Loading
37+
4 -> Just Done
38+
_ -> Nothing
39+
40+
fromEnum :: ReadyState -> Int
41+
fromEnum = case _ of
42+
Unsent -> 0
43+
Opened -> 1
44+
HeadersReceived -> 2
45+
Loading -> 3
46+
Done -> 4

src/Web/XHR/ResponseType.purs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Web.XHR.ResponseType
2+
( ResponseType
3+
, arrayBuffer
4+
, blob
5+
, document
6+
, string
7+
) where
8+
9+
import Web.File.Blob (Blob)
10+
import Web.DOM.Document (Document)
11+
import Data.ArrayBuffer.Types (ArrayBuffer)
12+
13+
newtype ResponseType res = ResponseType String
14+
15+
arrayBuffer :: ResponseType ArrayBuffer
16+
arrayBuffer = ResponseType "arraybuffer"
17+
18+
blob :: ResponseType Blob
19+
blob = ResponseType "blob"
20+
21+
document :: ResponseType Document
22+
document = ResponseType "document"
23+
24+
string :: ResponseType String
25+
string = ResponseType ""

0 commit comments

Comments
 (0)