ITADN

Experiment: implement callbacks using observers

#19Closedviridia 创建于 2024-08-12
V
viridiacommented
Currently callbacks use one-shot systems. A downside of this is that calling a one-shot system requires access to `mut World`. Observers, like one-shot systems, also support dependency injection. It might be possible to re-implement callbacks using observers, which would allow them to be triggered using Commands. This would simplify many event handlers. The only downside is that it introduces a slight delay - the callback won't be called until the next command flush - but since command flushes generally happen after a system runs, this probably won't be a significant issue. Another advantage is that unlike one-shots, observers can be replaced / overwritten. This would possibly allow for callbacks that can update their captures. Just to review: the whole point of callbacks is that they provide a "handle" which can be Copy/Cloned, allowing a callback to be captured by a closure / event handler without all of the tedious borrowing issues.
关闭于 2024-08-12 1 条评论