Skip to content

Commit 3fd1fe1

Browse files
authored
fix: forward dispatch return value (#3368)
1 parent 71358de commit 3fd1fe1

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

lib/dispatcher/dispatcher.js

+3-24
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,9 @@ class Dispatcher extends EventEmitter {
3535
}
3636
}
3737

38-
return new ComposedDispatcher(this, dispatch)
39-
}
40-
}
41-
42-
class ComposedDispatcher extends Dispatcher {
43-
#dispatcher = null
44-
#dispatch = null
45-
46-
constructor (dispatcher, dispatch) {
47-
super()
48-
this.#dispatcher = dispatcher
49-
this.#dispatch = dispatch
50-
}
51-
52-
dispatch (...args) {
53-
this.#dispatch(...args)
54-
}
55-
56-
close (...args) {
57-
return this.#dispatcher.close(...args)
58-
}
59-
60-
destroy (...args) {
61-
return this.#dispatcher.destroy(...args)
38+
return new Proxy(this, {
39+
get: (target, key) => key === 'dispatch' ? dispatch : target[key]
40+
})
6241
}
6342
}
6443

test/dispatcher.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ test('dispatcher implementation', (t) => {
2222
})
2323

2424
test('dispatcher.compose', (t) => {
25-
t = tspl(t, { plan: 10 })
25+
t = tspl(t, { plan: 7 })
2626

2727
const dispatcher = new Dispatcher()
2828
const interceptor = () => (opts, handler) => {}
2929
// Should return a new dispatcher
30-
t.ok(Object.getPrototypeOf(dispatcher.compose(interceptor)) instanceof Dispatcher)
31-
t.ok(Object.getPrototypeOf(dispatcher.compose(interceptor, interceptor)) instanceof Dispatcher)
32-
t.ok(Object.getPrototypeOf(dispatcher.compose([interceptor, interceptor])) instanceof Dispatcher)
3330
t.ok(dispatcher.compose(interceptor) !== dispatcher)
3431
t.throws(() => dispatcher.dispatch({}), Error, 'invalid interceptor')
3532
t.throws(() => dispatcher.dispatch(() => null), Error, 'invalid interceptor')

0 commit comments

Comments
 (0)