Skip to content

Commit 22e3826

Browse files
Update FFI to EffectFnX types; update repo to purescript-web standards (#3)
* Update FFI to EffectFnX types * Add a changelog * Update eslint config to match web-dom's Keeping these files the same helps when updating the ecosystem due to compiler breaking changes * Add .github folder from web-dom * Add modified ci.yml file from form-urlencoded * Drop comments in packages.dhall file * Update Show instances * Add functions to dependencies
1 parent be30f4e commit 22e3826

28 files changed

+450
-454
lines changed

.eslintrc.json

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
{
2-
"parserOptions": {
3-
"ecmaVersion": 6,
4-
"sourceType": "module"
5-
},
6-
"extends": "eslint:recommended",
7-
"env": {
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-
}
2+
"parserOptions": {
3+
"ecmaVersion": 6,
4+
"sourceType": "module"
5+
},
6+
"extends": "eslint:recommended",
7+
"env": {
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"]
2928
}
30-
29+
}

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
name: Feature request
3+
about: Suggest types, functions, properties that may be missing
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
### Prerequisites
11+
12+
- [ ] Before opening an issue, please check the [W3C Web Workers standard](https://html.spec.whatwg.org/multipage/workers.html). If it doesn't appear in this spec, it may be present in the spec for one of the other `purescript-web` projects. Although MDN is a great resource, it is not a suitable reference for this project.
13+
14+
### Description
15+
16+
<!-- A summary of the thing to include, with a link to the relevant section of the spec -->

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**Prerequisites**
2+
3+
- [ ] Before opening a pull request, please check the DOM standard (https://dom.spec.whatwg.org/). If it doesn't appear in this spec, it may be present in the spec for one of the other `purescript-web` projects. Although MDN is a great resource, it is not a suitable reference for this project.
4+
5+
**Description of the change**
6+
7+
Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR.
8+
9+
---
10+
11+
**Checklist:**
12+
13+
- [ ] Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
14+
- [ ] Linked any existing issues or proposals that this pull request should close
15+
- [ ] Updated or added relevant documentation
16+
- [ ] Added a test for the contribution (if applicable)

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Set up a PureScript toolchain
16+
uses: purescript-contrib/setup-purescript@main
17+
with:
18+
purescript: "unstable"
19+
purs-tidy: "latest"
20+
21+
- name: Cache PureScript dependencies
22+
uses: actions/cache@v2
23+
with:
24+
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
25+
path: |
26+
.spago
27+
output
28+
29+
- name: Install dependencies
30+
run: spago install
31+
32+
- name: Build source
33+
run: spago build --no-install --purs-args '--censor-lib --strict'
34+
35+
- name: Check formatting
36+
run: purs-tidy check src

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Changelog
2+
3+
Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4+
5+
## [Unreleased]
6+
7+
Breaking changes:
8+
- Refactored `Worker` to better match the spec
9+
- Refactored `Credentials`' `Show` instance to be more `Show`-like; use `printCredentials` now
10+
11+
New features:
12+
- Added `SharedWorker` bindings
13+
- Added `Show` instance to `WorkerType`
14+
15+
Bugfixes:
16+
17+
Other improvements:
18+
- Added documentation
19+
- Migrated from `pulp`/`bower` to `spago`
20+
- Updated FFI to use `EffectFnX` types
21+
- Added CI and GitHub issue/pr templates
22+
- Added `purs-tidy` formatter to CI
23+
24+
## [v1.1.0](https://github.com/purescript-web/purescript-web-workers/releases/tag/v1.1.0) - 2022-05-2
25+
26+
- purty and export MessageEvent.ports
27+
-
28+
## [v1.0.0](https://github.com/purescript-web/purescript-web-workers/releases/tag/v1.0.0) - 2022-05-17
29+
30+
- Update README.md
31+
32+
## [v0.2.0](https://github.com/purescript-web/purescript-web-workers/releases/tag/v0.2.0) - 2022-05-16
33+
34+
Update `bower.json`
35+
36+
## [v0.1.0](https://github.com/purescript-web/purescript-web-workers/releases/tag/v0.1.0) - 2022-05-16
37+
38+
- Initial release

packages.dhall

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,3 @@
1-
{-
2-
Welcome to your new Dhall package-set!
3-
4-
Below are instructions for how to edit this file for most use
5-
cases, so that you don't need to know Dhall to use it.
6-
7-
## Use Cases
8-
9-
Most will want to do one or both of these options:
10-
1. Override/Patch a package's dependency
11-
2. Add a package not already in the default package set
12-
13-
This file will continue to work whether you use one or both options.
14-
Instructions for each option are explained below.
15-
16-
### Overriding/Patching a package
17-
18-
Purpose:
19-
- Change a package's dependency to a newer/older release than the
20-
default package set's release
21-
- Use your own modified version of some dependency that may
22-
include new API, changed API, removed API by
23-
using your custom git repo of the library rather than
24-
the package set's repo
25-
26-
Syntax:
27-
where `entityName` is one of the following:
28-
- dependencies
29-
- repo
30-
- version
31-
-------------------------------
32-
let upstream = --
33-
in upstream
34-
with packageName.entityName = "new value"
35-
-------------------------------
36-
37-
Example:
38-
-------------------------------
39-
let upstream = --
40-
in upstream
41-
with halogen.version = "master"
42-
with halogen.repo = "https://example.com/path/to/git/repo.git"
43-
44-
with halogen-vdom.version = "v4.0.0"
45-
with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies
46-
-------------------------------
47-
48-
### Additions
49-
50-
Purpose:
51-
- Add packages that aren't already included in the default package set
52-
53-
Syntax:
54-
where `<version>` is:
55-
- a tag (i.e. "v4.0.0")
56-
- a branch (i.e. "master")
57-
- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977")
58-
-------------------------------
59-
let upstream = --
60-
in upstream
61-
with new-package-name =
62-
{ dependencies =
63-
[ "dependency1"
64-
, "dependency2"
65-
]
66-
, repo =
67-
"https://example.com/path/to/git/repo.git"
68-
, version =
69-
"<version>"
70-
}
71-
-------------------------------
72-
73-
Example:
74-
-------------------------------
75-
let upstream = --
76-
in upstream
77-
with benchotron =
78-
{ dependencies =
79-
[ "arrays"
80-
, "exists"
81-
, "profunctor"
82-
, "strings"
83-
, "quickcheck"
84-
, "lcg"
85-
, "transformers"
86-
, "foldable-traversable"
87-
, "exceptions"
88-
, "node-fs"
89-
, "node-buffer"
90-
, "node-readline"
91-
, "datetime"
92-
, "now"
93-
]
94-
, repo =
95-
"https://github.com/hdgarrood/purescript-benchotron.git"
96-
, version =
97-
"v7.0.0"
98-
}
99-
-------------------------------
100-
-}
1011
let upstream =
1022
https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20230105/packages.dhall
1033
sha256:3e9fbc9ba03e9a1fcfd895f65e2d50ee2f5e86c4cd273f3d5c841b655a0e1bda

spago.dhall

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{ name = "web-workers"
2-
, dependencies = [ "effect", "foreign", "maybe", "prelude", "unsafe-coerce", "web-events" ]
2+
, dependencies =
3+
[ "effect"
4+
, "foreign"
5+
, "functions"
6+
, "maybe"
7+
, "prelude"
8+
, "unsafe-coerce"
9+
, "web-events"
10+
]
311
, packages = ./packages.dhall
412
, sources = [ "src/**/*.purs" ]
513
}
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
/* @globals self */
22

3-
export function name () {
3+
export function name() {
44
return self.name;
55
}
66

7-
export function postMessageImpl(data) {
8-
return function(tr) {
9-
return function () {
10-
self.postMessage(data, tr.length > 0 ? tr : undefined);
11-
};
12-
};
7+
export function postMessageImpl(data, tr) {
8+
self.postMessage(data, tr.length > 0 ? tr : undefined);
139
}
1410

1511
export function close() {
1612
self.close();
1713
}
1814

19-
export function onMessage(f) {
20-
return function () {
21-
self.onmessage = function (ev) {
22-
f(ev)();
23-
};
24-
};
15+
export function onMessageImpl(f) {
16+
self.onmessage = f;
2517
}
2618

27-
export function onMessageError(f) {
28-
return function () {
29-
self.onmessageerror = function (ev) {
30-
f(ev)();
31-
};
32-
};
33-
}
19+
export function onMessageErrorImpl(f) {
20+
self.onmessageerror = f;
21+
}

src/Web/Worker/DedicatedWorkerGlobalScope.purs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,38 @@ module Web.Worker.DedicatedWorkerGlobalScope
66
, postMessage
77
, postMessage'
88
, module GlobalScope
9-
)
10-
where
9+
) where
1110

1211
import Prelude
12+
1313
import Effect (Effect)
14-
import Web.Worker.Types (Transferable)
14+
import Effect.Uncurried (EffectFn1, EffectFn2, mkEffectFn1, runEffectFn1, runEffectFn2)
15+
import Web.Worker.GlobalScope (importScripts, location, navigator, onError, onLanguageChange, onOffline, onOnline, onRejectionHandled, onUnhandledRejection) as GlobalScope
1516
import Web.Worker.MessageEvent (MessageEvent)
16-
import Web.Worker.GlobalScope (importScripts, location, navigator, onError, onLanguageChange, onOffline
17-
, onOnline, onRejectionHandled, onUnhandledRejection
18-
) as GlobalScope
17+
import Web.Worker.Types (Transferable)
1918

2019
foreign import name :: Effect String
2120

22-
foreign import postMessageImpl :: forall msg. msg -> Array Transferable -> Effect Unit
23-
2421
-- | sends a message to the main thread that spawned it.
2522
postMessage :: forall msg. msg -> Effect Unit
26-
postMessage msg = postMessageImpl msg []
23+
postMessage msg = postMessage' msg []
2724

2825
postMessage' :: forall msg. msg -> Array Transferable -> Effect Unit
29-
postMessage' = postMessageImpl
26+
postMessage' msg tr = runEffectFn2 postMessageImpl msg tr
27+
28+
foreign import postMessageImpl :: forall msg. EffectFn2 msg (Array Transferable) Unit
3029

3130
-- | upon calling close, any queued tasks present in the event loop are discarded and the web worker scope is closed.
3231
foreign import close :: Effect Unit
3332

3433
-- | fired when the worker receives a message from its parent.
35-
foreign import onMessage :: (MessageEvent -> Effect Unit) -> Effect Unit
34+
onMessage :: (MessageEvent -> Effect Unit) -> Effect Unit
35+
onMessage cb = runEffectFn1 onMessageImpl (mkEffectFn1 cb)
36+
37+
foreign import onMessageImpl :: EffectFn1 (EffectFn1 MessageEvent Unit) Unit
3638

3739
-- | fired when a worker receives a message that can't be deserialized.
38-
foreign import onMessageError :: (MessageEvent -> Effect Unit) -> Effect Unit
40+
onMessageError :: (MessageEvent -> Effect Unit) -> Effect Unit
41+
onMessageError cb = runEffectFn1 onMessageErrorImpl (mkEffectFn1 cb)
42+
43+
foreign import onMessageErrorImpl :: EffectFn1 (EffectFn1 MessageEvent Unit) Unit

0 commit comments

Comments
 (0)