Skip to content

Commit f2c097e

Browse files
Add bindings to EventEmitter
0 parents  commit f2c097e

File tree

8 files changed

+705
-0
lines changed

8 files changed

+705
-0
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
# Run CI when a PR is opened against the branch `main`
4+
# and when one pushes a commit to `main`.
5+
on:
6+
push:
7+
branches: [master]
8+
pull_request:
9+
branches: [master]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- uses: purescript-contrib/setup-purescript@main
19+
with:
20+
purescript: "0.15.7"
21+
purs-tidy: "0.9.2"
22+
psa: "0.8.2"
23+
spago: "0.20.9"
24+
psa: "0.7.2"
25+
26+
- name: Cache PureScript dependencies
27+
uses: actions/cache@v2
28+
with:
29+
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
30+
path: |
31+
.spago
32+
output
33+
34+
- name: Set up Node toolchain
35+
uses: actions/setup-node@v2
36+
with:
37+
node-version: "16"
38+
39+
# Compile the library/project
40+
# censor-lib: ignore warnings emitted by dependencies
41+
# strict: convert warnings into errors
42+
# Note: `purs-args` actually forwards these args to `psa`
43+
- name: Build the project
44+
run: |
45+
spago build --purs-args "--censor-lib --strict"
46+
47+
- name: Run tests
48+
run: |
49+
spago test
50+
51+
- name: Check Formatting
52+
run: |
53+
purs-tidy check src test

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/bower_components/
2+
/node_modules/
3+
/.pulp-cache/
4+
/output/
5+
/generated-docs/
6+
/.psc-package/
7+
/.psc*
8+
/.purs*
9+
/.psa*
10+
/.spago

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# purescript-node-event-emitter
2+
3+
Bindings for the [`event-emitter`](https://nodejs.org/api/events.html#class-eventemitter) class.

packages.dhall

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let upstream =
2+
https://github.com/purescript/package-sets/releases/download/psc-0.15.7-20230118/packages.dhall
3+
sha256:973809c5d08a285ac10c6e66be04ca2c85a2d26493644e9196a6a411359f84b9
4+
5+
in upstream

spago.dhall

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{ name = "node-event-emitters"
2+
, dependencies =
3+
[ "effect"
4+
, "functions"
5+
, "prelude"
6+
, "safe-coerce"
7+
, "unsafe-coerce"
8+
]
9+
, packages = ./packages.dhall
10+
, sources = [ "src/**/*.purs" ]
11+
}

src/Node/EventEmitter.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import events from "node:events";
2+
3+
const newImpl = function () {
4+
return new events.EventEmitter();
5+
}
6+
export { newImpl as new };
7+
8+
export function listenersLengthImpl(emitter, event) {
9+
return emitter.listeners(event).length;
10+
}
11+
12+
export function setMaxListenersImpl(emitter, max) {
13+
emitter.setMaxListeners(max);
14+
}
15+
16+
export function onImpl(emitter, eventName, cb) {
17+
emitter.on(eventName, cb);
18+
return cb;
19+
}
20+
21+
export function offImpl(emitter, eventName, cb) {
22+
emitter.off(eventName, cb);
23+
}
24+
25+
export function onceEventListener(emitter, eventName, cb) {
26+
emitter.once(eventName, cb);
27+
}
28+
29+
export function emitImpl(emitter, eventName) {
30+
return function (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
31+
emitter.emit(eventName, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
32+
};
33+
}
34+
const undefined_ = undefined
35+
export { undefined_ as undefined }

0 commit comments

Comments
 (0)