From e16692ca5f7d8ecf5263ef679b28d721234084ab Mon Sep 17 00:00:00 2001 From: Andrew Herron Date: Wed, 24 Jan 2024 11:52:21 +1100 Subject: [PATCH] Removed multi-arg event handling. Fixes #25 --- .changes/unreleased/Changed-20240124-114817.yaml | 5 +++++ lib/js/test/module/EventEmitterTestLib.bs.js | 3 +-- src/Event.res | 16 ++++------------ test/module/EventEmitterTestLib.res | 1 - 4 files changed, 10 insertions(+), 15 deletions(-) create mode 100644 .changes/unreleased/Changed-20240124-114817.yaml diff --git a/.changes/unreleased/Changed-20240124-114817.yaml b/.changes/unreleased/Changed-20240124-114817.yaml new file mode 100644 index 0000000..b4e2a89 --- /dev/null +++ b/.changes/unreleased/Changed-20240124-114817.yaml @@ -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" diff --git a/lib/js/test/module/EventEmitterTestLib.bs.js b/lib/js/test/module/EventEmitterTestLib.bs.js index a5a73f6..f0914d1 100644 --- a/lib/js/test/module/EventEmitterTestLib.bs.js +++ b/lib/js/test/module/EventEmitterTestLib.bs.js @@ -10,8 +10,7 @@ var uniqueSymbol = (Symbol("emitter1")); var Events = { symbol: uniqueSymbol, text: "text", - integer: "integer", - textAndInteger: "textAndInteger" + integer: "integer" }; var Emitter1 = { diff --git a/src/Event.res b/src/Event.res index daf471d..9f6e2ac 100644 --- a/src/Event.res +++ b/src/Event.res @@ -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) diff --git a/test/module/EventEmitterTestLib.res b/test/module/EventEmitterTestLib.res index 61b898c..57b5cc6 100644 --- a/test/module/EventEmitterTestLib.res +++ b/test/module/EventEmitterTestLib.res @@ -7,6 +7,5 @@ module Emitter1 = { let symbol: Event.t unit, t> = Event.fromSymbol(uniqueSymbol) let text: Event.t unit, t> = Event.fromString("text") let integer: Event.t unit, t> = Event.fromString("integer") - let textAndInteger: Event.t<(string, int) => unit, t> = Event.fromString2("textAndInteger") } } \ No newline at end of file