node icon indicating copy to clipboard operation
node copied to clipboard

[Implement] Naive basic EventEmitter class

Open jtenner opened this issue 4 years ago • 2 comments

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:

  1. Callback signatures must match runtime assertions
  2. EventEmitter is treated as abstract
  3. Callback parameters up to length 10
  4. callback must return void
  5. Emit still too large. Requires switch statement to determine callback argument length
  6. 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.

jtenner avatar Jul 25 '19 20:07 jtenner

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

jtenner avatar Jul 25 '19 23:07 jtenner

@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.

jtenner avatar Aug 13 '19 03:08 jtenner