Skip to content

Fixed an issue where event handlers with no return value would block … - #60

Merged
mcdurdin merged 2 commits into
keymanapp:masterfrom
Sethyboy0:master
Apr 23, 2017
Merged

Fixed an issue where event handlers with no return value would block …#60
mcdurdin merged 2 commits into
keymanapp:masterfrom
Sethyboy0:master

Conversation

@Sethyboy0

Copy link
Copy Markdown
Contributor

…any further event handlers from executing.

This was caused due to the return value being undefined, and !undefined evaluates to true.
Fixing that alone would have caused the event stack to never get smaller however, so an else was added to the if statement.

I opted to fix it this way when I realized that changing all of the calls to addEventHandler in the toggleUI to include a return statement just wasn't going to be a feasible solution.

…any further event handlers from executing.

This was caused due to the return value being undefined, and !undefined evaluates to true.
Fixing that alone would have caused the event stack to never get smaller however, so an else was added to the if statement.
@mcdurdin

mcdurdin commented Apr 6, 2017

Copy link
Copy Markdown
Member

Thank you for your PR. I will review the change and test here (at a conference so may be a few days). Your fix and explanation looks pretty clear and tidy so I don't anticipate any issues.

And congratulations on your first PR :)

Comment thread source/kmwbase.js Outdated
catch(strExcept) { result=false; }//don't know whether to use true or false here
if(!result) { util.currentEvents.pop(); return false; }
if(result === false) {return false;}
else {util.currentEvents.pop();}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is quite correct. I think what we want is:

if(result === false) { util.currentEvents.pop(); return false; }

Because otherwise the loop is going to possibly pop too many events off the currentEvent stack. It may also be important to review the existing event handlers to make sure this doesn't change their behaviour adversely where more than one event handler is registered. I'll check that separately.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think you are correct there. Looking back at my change, I think I only added the else statement because I misread how the function worked.

Unfortunately you won't be able to properly test behavior when multiple events are defined because that didn't work in the first place. Most UI functions called by events have no return value which meant that (!result) evaluated to true. This would make the callEvent function return before it finished executing all events in the array.

Using util.currentEvents.pop() didn't break anything in my own use of the keyboard, but I think that's only because the handlers are called directly from the events array instead of the currentEvents array. I'll change my local implementation to what you've suggested above and let you know if anything breaks. I suspect it will work fine though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, looking at those UI event function callbacks, I see what you mean. Something that should be explicitly addressed in the future. We'll address that in a code review.

Once you can commit the change to your branch I'll merge the PR.

@Sethyboy0

Copy link
Copy Markdown
Contributor Author

Made the change and pushed it. Don't know if I need to tell you about it but I'm new to this so I will just in case.

@mcdurdin
mcdurdin merged commit 8f63c81 into keymanapp:master Apr 23, 2017
@mcdurdin

Copy link
Copy Markdown
Member

Thank you -- I do get notified on pushes to a PR :) Merged now, preparing to push to live servers.

@mcdurdin mcdurdin added this to the Support milestone Aug 18, 2023
kingsuper195 pushed a commit to kingsuper195/keyman that referenced this pull request Jan 16, 2026
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.

2 participants