Skip to content

Handler compositors

Artem Starikov requested to merge handler-compositors into master

Handler compositors allow writing clearer and shorter code by compositing and decorating handlers.

Previously, in {Stateful,}EventLoop, for each handler_setter we implemented another handler_setter_if that also accepted a predicate that decided whether to run the handler. This was dirty, led to a lot of code duplication, made docs harder to read and didn't allow for any composition. The only advantage of those was better type inference, but thinking about it more, it becomes apparent that composing handlers makes more sense if at least one of passed callbacks is defined outside the call place, and that makes buggy type inference less of a problem.

So this MR removes all that *_if stuff and replaces them with compositors.

Future work:

  • implement more compositors;
  • replace StatefulEventLoop using composition? that'd de-duplicate even more code, but has a few downsides too.
  • replace command_with_description using composition?
Edited by Artem Starikov

Merge request reports