-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Session class and Session options decoration by plugins #3464
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one question/change. Otherwise LGTM
app/session.js
Outdated
@@ -141,12 +141,12 @@ module.exports = class Session extends EventEmitter { | |||
} | |||
|
|||
write(data) { | |||
this.pty.write(data); | |||
this.pty && this.pty.write(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.pty && this.pty.write(data); | |
if (!this.pty) { | |
console.error('Attempted to write to a session with no pty'); | |
} | |
this.pty.write(data); |
Maybe this? Looks like otherwise we could silently lose data. Or is there a case where this would be valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I anticipated the case: A plugin overrides the constructor and prevents the pty creation (without override this write
method). It seems legit to fail silently.
But thanks to your comment, I think this is currently pretty hard to prevent this pty creation because it occurs in constructor. Such a plugin can't call super()
and would break other plugins that have previously decorated this Class.
I think we should isolate pty creation in a init(options)
function that plugin would override to prevent this pty creation without breaking constructor chain.
@@ -101,8 +102,9 @@ module.exports = class Window { | |||
extraOptions, | |||
{uid} | |||
); | |||
|
|||
const session = new Session(options); | |||
const options = decorateSessionOptions(defaultOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cool, more extensibility! 🎉
Thanks for addressing my feedback @chabou! Also, thanks for being patience with my response delay, I'm in the process of moving to a new place and these days have been pretty hectic 😅 I think it's reasonable to expect that a plugin that overrides This approach could cause problems if, for example, there's a plugin that overrides |
In short: if a plugin wants to remove the |
Look at My point is that plugin should focus on what it adds and not what it removes. Having base class that have conditional behavior, anticipating that some part could be removed is a good thing. But I totally understand your point that missing pty could be an unwanted error and silent protection could be harmful. I will add some warning. |
This PR implements this RFC
It adds 2 new plugin hook to our API
decorateSessionClass
anddecorateSessionOptions
.It unlocks some awesome new plugin possiblities. I made a plugin as an example (and a proof of concept): https://github.com/chabou/hyper-session-log