Skip to content

Commit 9e5fb7a

Browse files
authored
Merge pull request #2 from purescript-web/compiler/0.12
Compiler/0.12
2 parents 9b6a2df + 6209420 commit 9e5fb7a

15 files changed

+446
-9
lines changed

.eslintrc.json

+29
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

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Dependencies
2-
.psci_modules
3-
bower_components
4-
node_modules
5-
6-
# Generated files
7-
.psci
8-
output
1+
/.*
2+
!/.gitignore
3+
!/.eslintrc.json
4+
!/.travis.yml
5+
package-lock.json
6+
/bower_components/
7+
/node_modules/
8+
/output/

.travis.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: node_js
2+
dist: trusty
3+
sudo: required
4+
node_js: stable
5+
env:
6+
- PATH=$HOME/purescript:$PATH
7+
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
12+
- npm install -g bower
13+
- npm install
14+
script:
15+
- bower install
16+
- npm run -s build
17+
after_success:
18+
- >-
19+
test $TRAVIS_TAG &&
20+
echo $GITHUB_TOKEN | pulp login &&
21+
echo y | pulp publish --no-push

README.md

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

bower.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "purescript-web-socket",
3+
"homepage": "https://github.com/purescript-web/purescript-web-socket",
4+
"license": "MIT",
5+
"repository": {
6+
"type": "git",
7+
"url": "git://github.com/purescript-web/purescript-web-socket.git"
8+
},
9+
"ignore": [
10+
"**/.*",
11+
"bower_components",
12+
"node_modules",
13+
"output",
14+
"bower.json",
15+
"package.json"
16+
],
17+
"dependencies": {
18+
"purescript-arraybuffer-types": "^2.0.0",
19+
"purescript-web-file": "^1.0.0"
20+
}
21+
}

package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"clean": "rimraf output && rimraf .pulp-cache",
5+
"build": "eslint src && pulp build -- --censor-lib --strict"
6+
},
7+
"devDependencies": {
8+
"eslint": "^4.19.1",
9+
"pulp": "^12.2.0",
10+
"purescript-psa": "^0.6.0",
11+
"rimraf": "^2.6.2"
12+
}
13+
}

src/Web/Socket/BinaryType.purs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module Web.Socket.BinaryType where
2+
3+
import Prelude
4+
import Data.Enum (Cardinality(..), class BoundedEnum, defaultPred, defaultSucc, class Enum)
5+
import Data.Maybe (Maybe(..))
6+
7+
data BinaryType
8+
= Blob
9+
| ArrayBuffer
10+
11+
derive instance eqBinaryType :: Eq BinaryType
12+
derive instance ordBinaryType :: Ord BinaryType
13+
14+
instance boundedBinaryType :: Bounded BinaryType where
15+
bottom = Blob
16+
top = ArrayBuffer
17+
18+
instance enumBinaryType :: Enum BinaryType where
19+
succ = defaultSucc toEnumBinaryType fromEnumBinaryType
20+
pred = defaultPred toEnumBinaryType fromEnumBinaryType
21+
22+
instance boundedEnumBinaryType :: BoundedEnum BinaryType where
23+
cardinality = Cardinality 2
24+
toEnum = toEnumBinaryType
25+
fromEnum = fromEnumBinaryType
26+
27+
instance showBinaryType :: Show BinaryType where
28+
show Blob = "Blob"
29+
show ArrayBuffer = "ArrayBuffer"
30+
31+
toEnumBinaryType :: Int -> Maybe BinaryType
32+
toEnumBinaryType =
33+
case _ of
34+
0 -> Just Blob
35+
1 -> Just ArrayBuffer
36+
_ -> Nothing
37+
38+
fromEnumBinaryType :: BinaryType -> Int
39+
fromEnumBinaryType =
40+
case _ of
41+
Blob -> 0
42+
ArrayBuffer -> 1
43+
44+
printBinaryType :: BinaryType -> String
45+
printBinaryType =
46+
case _ of
47+
Blob -> "blob"
48+
ArrayBuffer -> "arraybuffer"

src/Web/Socket/Event/CloseEvent.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
exports.code = function (e) {
4+
return e.code;
5+
};
6+
7+
exports.reason = function (e) {
8+
return e.reason;
9+
};
10+
11+
exports.wasClean = function (e) {
12+
return e.wasClean;
13+
};

src/Web/Socket/Event/CloseEvent.purs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module Web.Socket.Event.CloseEvent 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 CloseEvent :: Type
9+
10+
fromEvent :: Event -> Maybe CloseEvent
11+
fromEvent = unsafeReadProtoTagged "CloseEvent"
12+
13+
toEvent :: CloseEvent -> Event
14+
toEvent = unsafeCoerce
15+
16+
foreign import code :: CloseEvent -> Int
17+
18+
foreign import reason :: CloseEvent -> String
19+
20+
foreign import wasClean :: CloseEvent -> Boolean

src/Web/Socket/Event/EventTypes.purs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Web.Socket.Event.EventTypes where
2+
3+
import Web.Event.Event (EventType(..))
4+
5+
onOpen :: EventType
6+
onOpen = EventType "open"
7+
8+
onMessage :: EventType
9+
onMessage = EventType "message"
10+
11+
onError :: EventType
12+
onError = EventType "error"
13+
14+
onClose :: EventType
15+
onClose = EventType "close"

src/Web/Socket/Event/MessageEvent.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
exports.data_ = function (e) {
4+
return e.data;
5+
};
6+
7+
exports.origin = function (e) {
8+
return e.origin;
9+
};
10+
11+
exports.lastEventId = function (e) {
12+
return e.lastEventId;
13+
};
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Web.Socket.Event.MessageEvent where
2+
3+
import Data.Maybe (Maybe)
4+
import Foreign (Foreign)
5+
import Unsafe.Coerce (unsafeCoerce)
6+
import Web.Event.Event (Event)
7+
import Web.Internal.FFI (unsafeReadProtoTagged)
8+
9+
foreign import data MessageEvent :: Type
10+
11+
fromEvent :: Event -> Maybe MessageEvent
12+
fromEvent = unsafeReadProtoTagged "MessageEvent"
13+
14+
toEvent :: MessageEvent -> Event
15+
toEvent = unsafeCoerce
16+
17+
foreign import data_ :: MessageEvent -> Foreign
18+
19+
foreign import origin :: MessageEvent -> String
20+
21+
foreign import lastEventId :: MessageEvent -> String

src/Web/Socket/ReadyState.purs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module Web.Socket.ReadyState where
2+
3+
import Prelude
4+
import Data.Enum (Cardinality(..), class BoundedEnum, defaultPred, defaultSucc, class Enum)
5+
import Data.Maybe (Maybe(..))
6+
7+
data ReadyState
8+
= Connecting
9+
| Open
10+
| Closing
11+
| Closed
12+
13+
derive instance eqReadyState :: Eq ReadyState
14+
derive instance ordReadyState :: Ord ReadyState
15+
16+
instance boundedReadyState :: Bounded ReadyState where
17+
bottom = Connecting
18+
top = Closed
19+
20+
instance enumReadyState :: Enum ReadyState where
21+
succ = defaultSucc toEnumReadyState fromEnumReadyState
22+
pred = defaultPred toEnumReadyState fromEnumReadyState
23+
24+
instance boundedEnumReadyState :: BoundedEnum ReadyState where
25+
cardinality = Cardinality 4
26+
toEnum = toEnumReadyState
27+
fromEnum = fromEnumReadyState
28+
29+
instance showReadyState :: Show ReadyState where
30+
show Connecting = "Connecting"
31+
show Open = "Open"
32+
show Closing = "Closing"
33+
show Closed = "Closed"
34+
35+
toEnumReadyState :: Int -> Maybe ReadyState
36+
toEnumReadyState =
37+
case _ of
38+
0 -> Just Connecting
39+
1 -> Just Open
40+
2 -> Just Closing
41+
3 -> Just Closed
42+
_ -> Nothing
43+
44+
fromEnumReadyState :: ReadyState -> Int
45+
fromEnumReadyState =
46+
case _ of
47+
Connecting -> 0
48+
Open -> 1
49+
Closing -> 2
50+
Closed -> 3

src/Web/Socket/WebSocket.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"use strict";
2+
3+
exports.create = function (url) {
4+
return function (protocols) {
5+
return function () {
6+
return new WebSocket(url, protocols);
7+
};
8+
};
9+
};
10+
11+
exports.url = function (ws) {
12+
return function () {
13+
return ws.url;
14+
};
15+
};
16+
17+
exports.readyStateImpl = function (ws) {
18+
return function () {
19+
return ws.readyState;
20+
};
21+
};
22+
23+
exports.bufferedAmount = function (ws) {
24+
return function () {
25+
return ws.bufferedAmount;
26+
};
27+
};
28+
29+
exports.extensions = function (ws) {
30+
return function () {
31+
return ws.extensions;
32+
};
33+
};
34+
35+
exports.protocol = function (ws) {
36+
return function () {
37+
return ws.protocol;
38+
};
39+
};
40+
41+
exports.close = function (ws) {
42+
return function () {
43+
return ws.close();
44+
};
45+
};
46+
47+
exports.getBinaryTypeImpl = function (ws) {
48+
return function () {
49+
return ws.binaryType;
50+
};
51+
};
52+
53+
exports.setBinaryTypeImpl = function (ws) {
54+
return function (bt) {
55+
return function () {
56+
ws.binaryType = bt;
57+
};
58+
};
59+
};
60+
61+
exports.sendImpl = function (ws) {
62+
return function (value) {
63+
return function () {
64+
ws.send(value);
65+
};
66+
};
67+
};

0 commit comments

Comments
 (0)