2121-- | ```
2222-- | data Color = Red | Green | Blue
2323-- |
24- -- | barHandle :: EventHandle Foo (Maybe Error -> Color -> Effect Unit) (EffectFn1 (Nullable Error) String Unit)
25- -- | barHandle = EventHandle "bar" $ \psCb -> mkEffectFn2 \nullableError str ->
24+ -- | -- Note: see docs on `EventHandle` for the below naming convention justification of suffixing `H`.
25+ -- | barH :: EventHandle Foo (Maybe Error -> Color -> Effect Unit) (EffectFn1 (Nullable Error) String Unit)
26+ -- | barH = EventHandle "bar" $ \psCb -> mkEffectFn2 \nullableError str ->
2627-- | psCb (toMaybe nullableError) case str of
2728-- | "red" -> Red
2829-- | "green" -> Green
@@ -48,8 +49,8 @@ module Node.EventEmitter
4849 , setUnlimitedListeners
4950 , unsafeEmitFn
5051 , EventHandle (..)
51- , newListenerHandle
52- , removeListenerHandle
52+ , newListenerH
53+ , removeListenerH
5354 , on
5455 , on_
5556 , once
@@ -139,20 +140,23 @@ foreign import unsafeEmitFn :: forall f. EventEmitter -> f Boolean
139140-- | Packs all the type information we need to call `on`/`once`/`prependListener`/`prependOnceListener`
140141-- | with the correct callback function type.
141142-- |
142- -- | Naming convention: If the name of an event is `foo`,
143- -- | the corresponding PureScript `EventHandle` value should be called `fooHandle`.
143+ -- | **Naming convention**: If the name of an event is `foo`,
144+ -- | the corresponding PureScript `EventHandle` value should be called `fooH`.
145+ -- | The `H` suffix is what prevent name conflicts in two situations:
146+ -- | 1. similarly-named methods (e.g. the `"close"` event and the `close` method)
147+ -- | 2. PureScript keywords (e.g. the `"data"` event)
144148data EventHandle :: Type -> Type -> Type -> Type
145149data EventHandle emitterType pureScriptCallback javaScriptCallback =
146150 EventHandle String (pureScriptCallback -> javaScriptCallback )
147151
148152type role EventHandle representational representational representational
149153
150- newListenerHandle :: EventHandle EventEmitter (Either JsSymbol String -> Effect Unit ) (EffectFn1 SymbolOrStr Unit )
151- newListenerHandle = EventHandle " newListener" $ \cb -> mkEffectFn1 \jsSymbol ->
154+ newListenerH :: EventHandle EventEmitter (Either JsSymbol String -> Effect Unit ) (EffectFn1 SymbolOrStr Unit )
155+ newListenerH = EventHandle " newListener" $ \cb -> mkEffectFn1 \jsSymbol ->
152156 cb $ runFn3 symbolOrStr Left Right jsSymbol
153157
154- removeListenerHandle :: EventHandle EventEmitter (Either JsSymbol String -> Effect Unit ) (EffectFn1 SymbolOrStr Unit )
155- removeListenerHandle = EventHandle " removeListener" $ \cb -> mkEffectFn1 \jsSymbol ->
158+ removeListenerH :: EventHandle EventEmitter (Either JsSymbol String -> Effect Unit ) (EffectFn1 SymbolOrStr Unit )
159+ removeListenerH = EventHandle " removeListener" $ \cb -> mkEffectFn1 \jsSymbol ->
156160 cb $ runFn3 symbolOrStr Left Right jsSymbol
157161
158162-- | Adds the listener to the **end** of the `listeners` array.
0 commit comments