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

Fix: event serialization fails for non-DOM-events #79

Merged

Conversation

maartenbreddels
Copy link
Collaborator

We did not test the serialization in #76 which introduced a bug (#78). This PR adds tests for both case and fixes #78. Although it does not test example in #78 we know this goes through the same codepath.

Ideally, we also test component event (https://vuejs.org/guide/components/events.html) but we do not support them in templates. Also, without ipyvuetify we do not have a widget that can emit a component event with a non-Event object as argument. We could decide to depend on ipvuetify for the test, or rely on the fact that the custom events in templates share a similar codepath.

@@ -77,8 +77,11 @@ function pickSerializable(object, depth=0, max_depth=2) {
export function eventToObject(event) {
if (event == null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This if is redundant

@@ -77,8 +77,11 @@ function pickSerializable(object, depth=0, max_depth=2) {
export function eventToObject(event) {
if (event == null) {
return event;
} else if(event instanceof Event) {
return pickSerializable(event);
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit-pick, but else can also be left out

Copy link
Collaborator Author

@maartenbreddels maartenbreddels Sep 6, 2023

Choose a reason for hiding this comment

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

you mean you prefer

    if (event instanceof Event) {
        return pickSerializable(event);
    }
    return event;

over

    if (event instanceof Event) {
        return pickSerializable(event);
    } else {
        return event;
    }

right?
I do too, and I do this in Python by default, but I'm not sure it is idiomatic JS.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, I prefer the first one. I never thought of that being language dependent.

assert box is not None
# if we pass floats (like 12.5) we get back ints from the
# event (12 in the case of 12.5), so we cast to int
cx = int(box["x"] + box["width"] / 2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not important, but for my context; why do we need to click the center? Isn't an offset of top and left of 1px enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, it seems that not even an offset was needed, just box['x']. My brain was wired to do this due to flakey-tests.

Copy link
Collaborator

@mariobuikhuizen mariobuikhuizen Sep 6, 2023

Choose a reason for hiding this comment

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

I now see in your change that even the offset isn't necessary :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

GitHub is confused :)
image

(6 minutes ago is before 5 minutes ago)

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah

@maartenbreddels maartenbreddels force-pushed the fix_event_serialization branch 2 times, most recently from 78d6a56 to 5974ca1 Compare September 6, 2023 11:08
If the event object was a string, we would call pickSerializable
on it which would convert it to an object, which results in a dict
on the Python side.
@mariobuikhuizen mariobuikhuizen changed the title Fix: event serialization Fix: event serialization fails for non-DOM-events Sep 7, 2023
@mariobuikhuizen mariobuikhuizen merged commit b208df1 into widgetti:master Sep 7, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Event serialization breaks "simple" events
2 participants