Sunday, November 3, 2013

Still Can't KeyEvent in Dart


I have not been pushing my #pairwithme sessions much of late, in part because Dart's keyboard events were broken for a long time. I don't have tons of time in the upcoming weeks, but I would at least get to a point where #pairwithme is a possibility again, so let's see if I can fix the build in ICE Code Editor.

When I first tried the build with the most recent version of Dart, there were some 130+ failing tests. As has been the case quite often of late, this was due to one or more libraries undergoing some breaking changes—this time the js-interop. Most of those changes were actually rather pleasant—of the remove old, unnecessary method calls variety. After doing that, I am down to 30 or so, which mostly seem to involve my ctrl-alt-foo keyboard shortcut library.

And, unfortunately, there still seem to be the same old bugs in Dart's KeyEvent—namely that I cannot use it to create a wrapped KeyboardEvent with an actual keycode. Even more unfortunately, the static class hack that I devised no longer seems to be working for me.

To review, I cannot dispatchEvent() because there is no way to generate custom keyboard events with data in tests. I cannot add events to CustomStream because the elements on which I am trying to listen for events are dynamically created.

In other words, if I try to listen for Enter events with the onKeyDown property:
  _handleEnter(el) {
    el.onKeyDown.listen((e){
      if (e.keyCode != KeyCode.ENTER) return;
      // Try to do stuff here...
    });
  }
This will not work with my tests because the wrapped KeyboardEvent—which I try to generate in tests—always has a zero keyCode.

And, If I use the EventStreamProvider interface:
  _handleEnter(el) {
    KeyEvent.keyDownEvent.forTarget(el).listen((e) {
      // Try to do stuff here...
    });
  }
Then Dartium generates the following when I try to use the application itself:
Exception: InvalidStateError: Internal Dartium Exception
(with no stacktrace)

Bummer. I think that I have an open bug for the second problem. I really need to make sure that I have the first one in the system. All I can do is wait patiently after that.


Day #924

No comments:

Post a Comment