Skip to content

More robust event mechanism #113

@ccbrown

Description

@ccbrown

In particular, components should be able to dispatch events, and subscribers should be able to choose to either consume them or give another subscriber a chance to handle them.

This could look something like...

hooks.use_events<MyEvent>(|e| {
    if ... {
        // handle the event
        e.stop_propagation();
    }
});

Somewhere else...

let dispatcher = hooks.use_event_dispatcher<MyEvent>();
dispatcher.dispatch(MyEvent::new(...));

Unless stop_propagate is called on the event, the event would bubble up the chain of parent elements with event handlers for that type.

This mechanism could potentially replace the current use_terminal_events hook, if for keystroke events we also had a mechanism to define a focus or "first responder" to which they would be dispatched initially.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions