Skip to content

Commit

Permalink
Removed multi-arg event handling. Fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpyder committed Jan 24, 2024
1 parent ef7e182 commit e16692c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/Changed-20240124-114817.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Changed
body: Removed multi-argument event handling added in v16, which didn't actually work
time: 2024-01-24T11:48:17.241035+11:00
custom:
GithubIssue: "25"
3 changes: 1 addition & 2 deletions lib/js/test/module/EventEmitterTestLib.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions src/Event.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,29 @@
* The `Event` type represents the strings/symbols used in Node to
* identify event types for `EventEmitter` and its subclasses, including
* streams, sockets, and servers.
*
*
* Given a type signature `Event.t('a => 'b, 'ty)`, the first type
* variable, `'a => 'b`, denotes the type signature of the event listener
* function, and `'ty` denotes the type of the associated `EventEmitter`.
*
*
* These abstract `Event.t` types must be passed to `EventEmitter`
* functions to register event listeners or emit events. By encoding the
* listener function type in a type variable, we can ensure that each
* listener has the correct type. The type parameter for the emitter
* prevents two different emitters from using each other's events.
*
*
* While this gives us some degree of type safety, it is still possible
* to introduce runtime errors with this API. In particular, two or more
* `Event.t` types can be defined from the same string/symbol, but with
* different listener types. Therefore, we strongly recommend using
* 100% unique strings/symbols to define events.
*
*
")
type t<'listener, 'ty>
external fromString: string => t<'a => 'b, 'ty> = "%identity"
external fromString2: string => t<('a, 'b) => 'c, 'ty> = "%identity"
external fromString3: string => t<('a, 'b, 'c) => 'd, 'ty> = "%identity"
external fromSymbol: Js.Types.symbol => t<'a => 'b, 'ty> = "%identity"
external fromSymbol2: Js.Types.symbol => t<('a, 'b) => 'c, 'ty> = "%identity"
external fromSymbol3: Js.Types.symbol => t<('a, 'b, 'c) => 'd, 'ty> = "%identity"
external unsafeToString: t<'a => 'b, 'ty> => string = "%identity"
external unsafeToString2: t<('a, 'b) => 'c, 'ty> => string = "%identity"
external unsafeToString3: t<('a, 'b, 'c) => 'd, 'ty> => string = "%identity"
external unsafeToSymbol: t<'a => 'b, 'ty> => Js.Types.symbol = "%identity"
external unsafeToSymbol2: t<('a, 'b) => 'c, 'ty> => Js.Types.symbol = "%identity"
external unsafeToSymbol3: t<('a, 'b, 'c) => 'd, 'ty> => Js.Types.symbol = "%identity"
type case =
| String(string)
| Symbol(Js.Types.symbol)
Expand Down
1 change: 0 additions & 1 deletion test/module/EventEmitterTestLib.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ module Emitter1 = {
let symbol: Event.t<Js.Types.symbol => unit, t> = Event.fromSymbol(uniqueSymbol)
let text: Event.t<string => unit, t> = Event.fromString("text")
let integer: Event.t<int => unit, t> = Event.fromString("integer")
let textAndInteger: Event.t<(string, int) => unit, t> = Event.fromString2("textAndInteger")
}
}

0 comments on commit e16692c

Please sign in to comment.