diff --git a/lib/dispatcher/dispatcher.js b/lib/dispatcher/dispatcher.js index b1e0098ec4b..ecff2a9b168 100644 --- a/lib/dispatcher/dispatcher.js +++ b/lib/dispatcher/dispatcher.js @@ -35,30 +35,9 @@ class Dispatcher extends EventEmitter { } } - return new ComposedDispatcher(this, dispatch) - } -} - -class ComposedDispatcher extends Dispatcher { - #dispatcher = null - #dispatch = null - - constructor (dispatcher, dispatch) { - super() - this.#dispatcher = dispatcher - this.#dispatch = dispatch - } - - dispatch (...args) { - this.#dispatch(...args) - } - - close (...args) { - return this.#dispatcher.close(...args) - } - - destroy (...args) { - return this.#dispatcher.destroy(...args) + return new Proxy(this, { + get: (target, key) => key === 'dispatch' ? dispatch : target[key] + }) } } diff --git a/test/dispatcher.js b/test/dispatcher.js index 1febdf53b4b..fbb56e94bc1 100644 --- a/test/dispatcher.js +++ b/test/dispatcher.js @@ -22,14 +22,11 @@ test('dispatcher implementation', (t) => { }) test('dispatcher.compose', (t) => { - t = tspl(t, { plan: 10 }) + t = tspl(t, { plan: 7 }) const dispatcher = new Dispatcher() const interceptor = () => (opts, handler) => {} // Should return a new dispatcher - t.ok(Object.getPrototypeOf(dispatcher.compose(interceptor)) instanceof Dispatcher) - t.ok(Object.getPrototypeOf(dispatcher.compose(interceptor, interceptor)) instanceof Dispatcher) - t.ok(Object.getPrototypeOf(dispatcher.compose([interceptor, interceptor])) instanceof Dispatcher) t.ok(dispatcher.compose(interceptor) !== dispatcher) t.throws(() => dispatcher.dispatch({}), Error, 'invalid interceptor') t.throws(() => dispatcher.dispatch(() => null), Error, 'invalid interceptor')