Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event de-structuring is cumbersome. #37

Closed
luukvanderduim opened this issue Dec 29, 2022 · 2 comments
Closed

Event de-structuring is cumbersome. #37

luukvanderduim opened this issue Dec 29, 2022 · 2 comments

Comments

@luukvanderduim
Copy link
Collaborator

Currently the event de-structuring looks as such:

while let Ok(ev) = event_stream.next().await.expect("None") {
    let Event::Interfaces(EventInterfaces::Object( ObjectEvents::StateChanged(state_ev))) = ev else { continue; };

    if state_ev.state() == "focused" {
        let Some(sender) = state_ev.sender()? else { continue; };
        println!("Focused by: {sender}")
     }
}

If Event would hold a copy of AtspiEvent (instead of EventInterfaces) and the TryFrom implementations are adjusted to convert from Event to respectively: the signified types or the grouped EventInterfaces, we could:

while let Ok(ev) = event_stream.next().await.expect("None") {
    let ev: StateChangedEvent = ev.try_into()? else { continue; };

    if ev.state() == "focused" {
        let Some(sender) = state_ev.sender()? else { continue; };
        println!("Focused by: {sender}")
     }
}

perhaps have current behaviour as such:

while let Ok(ev) = event_stream.next().await.expect("None") {
    let evs: EventInterfaces = ev.try_into()? else { continue; };

    /// Then do destructuring ...
}
@TTWNO
Copy link
Member

TTWNO commented Dec 29, 2022

It may be cumbersome, but it is very easily typed and has a good structure.

If you want a way to do this with AtspiEvent, then why not with Cache and Availsble events too? And at that point, what's the use of the enum?

I think a good comprimise would be to have all event variant in Event itself, without splitting them into individual, progressively more specific, enums. Either work well for Odilia.

I'll ping @DataTriny and see what they think.

@TTWNO
Copy link
Member

TTWNO commented Jan 18, 2023

Resolved by #50

@TTWNO TTWNO closed this as completed Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants