Skip to content

Commit 7c69a9c

Browse files
committed
Revert "Removed multi-arg event handling. Fixes #25"
This reverts commit e16692c.
1 parent a660689 commit 7c69a9c

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

.changes/unreleased/Changed-20240124-114817.yaml

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

lib/js/test/module/EventEmitterTestLib.bs.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Event.res

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,37 @@
22
* The `Event` type represents the strings/symbols used in Node to
33
* identify event types for `EventEmitter` and its subclasses, including
44
* streams, sockets, and servers.
5-
*
5+
*
66
* Given a type signature `Event.t('a => 'b, 'ty)`, the first type
77
* variable, `'a => 'b`, denotes the type signature of the event listener
88
* function, and `'ty` denotes the type of the associated `EventEmitter`.
9-
*
9+
*
1010
* These abstract `Event.t` types must be passed to `EventEmitter`
1111
* functions to register event listeners or emit events. By encoding the
1212
* listener function type in a type variable, we can ensure that each
1313
* listener has the correct type. The type parameter for the emitter
1414
* prevents two different emitters from using each other's events.
15-
*
15+
*
1616
* While this gives us some degree of type safety, it is still possible
1717
* to introduce runtime errors with this API. In particular, two or more
1818
* `Event.t` types can be defined from the same string/symbol, but with
1919
* different listener types. Therefore, we strongly recommend using
2020
* 100% unique strings/symbols to define events.
21-
*
21+
*
2222
")
2323
type t<'listener, 'ty>
2424
external fromString: string => t<'a => 'b, 'ty> = "%identity"
25+
external fromString2: string => t<('a, 'b) => 'c, 'ty> = "%identity"
26+
external fromString3: string => t<('a, 'b, 'c) => 'd, 'ty> = "%identity"
2527
external fromSymbol: Js.Types.symbol => t<'a => 'b, 'ty> = "%identity"
28+
external fromSymbol2: Js.Types.symbol => t<('a, 'b) => 'c, 'ty> = "%identity"
29+
external fromSymbol3: Js.Types.symbol => t<('a, 'b, 'c) => 'd, 'ty> = "%identity"
2630
external unsafeToString: t<'a => 'b, 'ty> => string = "%identity"
31+
external unsafeToString2: t<('a, 'b) => 'c, 'ty> => string = "%identity"
32+
external unsafeToString3: t<('a, 'b, 'c) => 'd, 'ty> => string = "%identity"
2733
external unsafeToSymbol: t<'a => 'b, 'ty> => Js.Types.symbol = "%identity"
34+
external unsafeToSymbol2: t<('a, 'b) => 'c, 'ty> => Js.Types.symbol = "%identity"
35+
external unsafeToSymbol3: t<('a, 'b, 'c) => 'd, 'ty> => Js.Types.symbol = "%identity"
2836
type case =
2937
| String(string)
3038
| Symbol(Js.Types.symbol)

test/module/EventEmitterTestLib.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ module Emitter1 = {
77
let symbol: Event.t<Js.Types.symbol => unit, t> = Event.fromSymbol(uniqueSymbol)
88
let text: Event.t<string => unit, t> = Event.fromString("text")
99
let integer: Event.t<int => unit, t> = Event.fromString("integer")
10+
let textAndInteger: Event.t<(string, int) => unit, t> = Event.fromString2("textAndInteger")
1011
}
1112
}

0 commit comments

Comments
 (0)