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

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: 8 additions & 8 deletions
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 16 additions & 1 deletion
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 48 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 15 additions & 0 deletions
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"

0 commit comments

Comments
 (0)