amilner42 / code-tidbit

Share Programming Knowledge Better
GNU General Public License v3.0
9 stars 1 forks source link

179 lang switch #192

Closed amilner42 closed 7 years ago

amilner42 commented 7 years ago

Closes

Closes #179

Description

Identified why the language was changing "randomly" in what seemed to be an indeterministic way. Copying from the commit message:

Language switch-bug found and removed …

  • The subscription was being triggered all the time, regardless of whether the dropdown was even active. Additionally, if you selected a language like Java which still had other languages in the dropdown (Javascript), then if you hit down enough it would wrap around back to the top, and when it wraps to the top it would have it be selected again, so clicking enter would trigger the switch. Lesson:
    • Don't have subscriptions always active unless they are meant to be always active. If your subscription is watching for things like arrow keys and is always active, then you will actually have a bunch of logic being triggered you didn't even realize!. Using a basic if with Sub.none allows you to have subscriptions be conditional

Long story short, the subscription was active and triggering logic even when I didn't think it was (when the dropdown wasn't on the screen). And it just so happened that in a very unique specific situation as described above that it would cause a bug that felt "random". Subscriptions need to only be active when you want them to be...