Skip to content

Refactor AppDelegate into a trait #283

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

Merged
merged 2 commits into from
Nov 9, 2019
Merged

Refactor AppDelegate into a trait #283

merged 2 commits into from
Nov 9, 2019

Conversation

LiHRaM
Copy link
Collaborator

@LiHRaM LiHRaM commented Nov 9, 2019

While working on #268, @cmyr and I decided it might be worthwhile to implement AppDelegate as a trait rather than an object storing closures.
This is the initial attempt, and it feels nice and simple.

I implemented the trait for an empty struct in multiwin, which smells a bit.
This approach makes it possible for the AppDelegate to maintain state separately from the data which is passed to it via events, any thoughts on how that could be useful? Otherwise this approach might need some tweaking.

@cmyr
Copy link
Member

cmyr commented Nov 9, 2019

An impl for an empty struct is totally reasonable.

The 'should the app delegate have secret state' question is a deep one. I really don't know; the main justification for the previous design was to make this impossible, but I didn't have a good justification for wanting this to be impossible.

More and more, lately, one of my main design principles for druid is that we should make it easy for framework users to implement the hacks they need to get their apps working, and a stateful app delegate is another tool in that drawer.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but this looks right to me. Thanks!

@LiHRaM LiHRaM force-pushed the appdelegate-trait branch from 561b6ef to 30a36bd Compare November 9, 2019 21:24
AppDelegate::new()
let _ = data;
let _ = env;
let _ = ctx;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this about?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, unused warnings? I would annotate this function #[allow(unused)].

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was following the discussion mentioned in #283 (comment), and it seemed to be the most correct solution, but the attribute is also fine with me. 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah gotcha, missed that comment. We have adopted the pattern of using #[allow] on each function with this problem, so let's just keep doing that. 🤷‍♂

Also box the AppDelegate inside the function to make it cleaner to call.
@LiHRaM LiHRaM force-pushed the appdelegate-trait branch from 30a36bd to 7a7a1d0 Compare November 9, 2019 21:44
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me, thanks for the quick turnaround. :)

@cmyr
Copy link
Member

cmyr commented Nov 9, 2019

feel free to merge. :)

@LiHRaM LiHRaM merged commit d0db47c into master Nov 9, 2019
@LiHRaM LiHRaM deleted the appdelegate-trait branch November 9, 2019 22:04
@cmyr cmyr mentioned this pull request Dec 31, 2019
7 tasks
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

Successfully merging this pull request may close these issues.

2 participants