Anonymous functions in constructors make extension more difficult (DebugSession) #8614
Labels
enhancement
issues that are enhancements to current functionality - nice to haves
extensibility
issues to simplify ability to extend Theia
Feature Description:
My particular interest at the moment is in the
DebugSession
class, but it is true more generally that if any anonymous function with a non-trivial implementation appears in a constructor, the whole constructor has to be rewritten if the class is extended and that listener is to be modified.theia/packages/debug/src/browser/debug-session.tsx
Lines 77 to 112 in 5eb6efa
Here, if an adopter wants to modify the behavior of the class on a
continued
,stopped
,thread
, orterminated
event, or access the fullcapabilities
orbreakpoint
event in a custom implementation ofupdateBreakpoint()
orupdateCapabilities()
, they have to rewrite the whole constructor.Instead, it would be better to pass all of these through to named, overridable functions, e.g.
this.on('stopped', (e) => this.handleStopped(e))
The same is true for
init
functions, of course, and it might be worth codifying the avoidance of non-trivial anonymous functions in such contexts in the Coding Guidelines.The text was updated successfully, but these errors were encountered: