Fix KeyboardNavigatable

In b2d053f686, I tried to be clever and create a new KeyboardNavigatable object as a return value for `when`. My approach to cloning was incorrect, and caused the util to break entirely.

My original intent for having this "clone"-based behavior is that a single KeyboardNavigatable instance could be created with multiple listeners, and then "cloned" like this with different "activators" registered via "then" calls. In hindsight, this change introduces more issues than it solves: outside of just not working, the cloned "KeyboardNavigatable" instances have shared internal state (the set of callbacks), and each has write access to this internal state. This is a recipe for unpredictable behavior and confusing bugs, so best to keep things simple for now, and maybe introduce more functional behavior in later releases.

Fixes https://github.com/flarum/QualityAssurance/issues/25
This commit is contained in:
Alexander Skvortsov 2021-05-14 21:21:58 -04:00
parent d1e987a240
commit 05dda5b083

View File

@ -104,7 +104,9 @@ export default class KeyboardNavigatable {
* Provide a callback that determines whether keyboard input should be handled.
*/
when(callback: ShouldHandle): KeyboardNavigatable {
return { ...this, whenCallback: callback };
this.whenCallback = callback;
return this;
}
/**