Skip to content
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

Send/receive error details with widgets #4492

Merged
merged 15 commits into from
Nov 9, 2024
Merged

Conversation

AndrewFerr
Copy link
Member

@AndrewFerr AndrewFerr commented Nov 1, 2024

Depends on matrix-org/matrix-widget-api#100

Signed-off-by: Andrew Ferrazzutti andrewf@element.io

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • Sign-off given on the changes (see CONTRIBUTING.md).

@@ -147,6 +149,26 @@ export class RoomWidgetClient extends MatrixClient {
) {
super(opts);

const transportSend = this.widgetApi.transport.send.bind(this.widgetApi.transport);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this bind?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used as a way to preserve the original send method so it can still be used by the function that replaces it.

Alternatively this could have been an arrow function, but that would require specifying a parameter list. Using bind gets around that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a really nasty pattern, this looks like somewhere a subclass makes far more sense rather than overwriting class methods, what's the rationale for not doing it in a more conventional way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the send methods don't belong to WidgetApi, but to ITransport, meaning that subclassing (or even a composition-based approach) would have to work harder to get to them.

Any non-bind approach I can think of ends up being more complicated / requires much more copied code than this.

src/embedded.ts Outdated Show resolved Hide resolved
src/embedded.ts Outdated Show resolved Hide resolved
src/embedded.ts Outdated Show resolved Hide resolved
@AndrewFerr AndrewFerr added this pull request to the merge queue Nov 9, 2024
Merged via the queue into develop with commit 98f7637 Nov 9, 2024
26 checks passed
@AndrewFerr AndrewFerr deleted the af/widget-errors branch November 9, 2024 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants