node
node copied to clipboard
[Implement] Naive basic EventEmitter class
Let me start by saying I realize how entirely dangerous this is. Currently there's no good ergonomic way to do this, and in order to implement the backbone of the Stream
classes, we need something that resembles an emitter.
Current Limitations:
- Callback signatures must match runtime assertions
-
EventEmitter
is treated asabstract
- Callback parameters up to length
10
- callback must return
void
- Emit still too large. Requires switch statement to determine callback argument length
- emit function doesn't match @types/node type arguments. It still requires explicit types
emitter.emit<A, B, C, D>(a: A, b: B, c: C, d: D); // etc.
Now the implementation contains a groked callback type verifier that does runtime checking of callback signatures. It requires a global map that contains a set of valid signatures for each event, and is registered once per EventEmitter
class extension.
Not done:
- [x]
EventEmitter
should be abstract. - [ ] Docs needs to be updated for this class so that others can learn how to use this class effectively
- [x] Wait for compiler to support variable argument lengths or inferring of argument length count
- will be a 64bit integer with both the id and the argument length combined
@dcodeio conflicts aside, what's holding this request back? I just need to fix the builtin request. Right?
Other than that, not sure how to make this better.