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 arrow keys and local storage #329

Merged
merged 3 commits into from
Nov 6, 2024
Merged

fix arrow keys and local storage #329

merged 3 commits into from
Nov 6, 2024

Conversation

WardCunningham
Copy link
Member

I don't know what I was thinking when I replaced a convoluted switch statement with a malformed table lookup.
This expression has been shown to work.

@paul90
Copy link
Member

paul90 commented Nov 4, 2024

Could have just reverted to the original, from the decaffeinate script:

    const direction = (() => { switch (event.which) {
      case LEFTARROW: return -1;
      case RIGHTARROW: return +1;
    } })();

@@ -51,10 +51,9 @@ $(function() {

const LEFTARROW = 37;
const RIGHTARROW = 39;
const dirs = {LEFTARROW:-1, RIGHTARROW:+1};
Copy link
Member

Choose a reason for hiding this comment

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

This should have been

const dirs = {[LEFTARROW]:-1, [RIGHTARROW]:+1};

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking a few lines further down I see more complex case analysis and conclude this is really two distinct event handlers struggling to be one.

@WardCunningham WardCunningham changed the title fix decoding of arrow key events fix arrow keys and local storage Nov 5, 2024
@WardCunningham
Copy link
Member Author

The return was important because it was an early exit, not because anything of value was being returned. There is a structured-programming rule, single entry with single exit, that would have had us coding that as an if-then-else then no return would have been required. The early exit return should be coded as a separate statement to make it clear that the return is important for control flow.

@WardCunningham WardCunningham merged commit 07e5978 into main Nov 6, 2024
3 checks passed
@WardCunningham WardCunningham deleted the ward/arrows branch November 6, 2024 01:21
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