-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix: event serialization fails for non-DOM-events #79
Conversation
js/src/VueRenderer.js
Outdated
@@ -77,8 +77,11 @@ function pickSerializable(object, depth=0, max_depth=2) { | |||
export function eventToObject(event) { | |||
if (event == null) { |
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 if
is redundant
js/src/VueRenderer.js
Outdated
@@ -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 { |
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.
nit-pick, but else
can also be left out
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.
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.
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.
yeah, I prefer the first one. I never thought of that being language dependent.
tests/ui/test_events.py
Outdated
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) |
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.
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?
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.
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.
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 now see in your change that even the offset isn't necessary :-)
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.
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.
ah
f80b2e2
to
5b00f63
Compare
We did not add tests in widgetti#76.
78d6a56
to
5974ca1
Compare
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.
5974ca1
to
e8cf480
Compare
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.