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

Improve encapsulation for commands and add docs #8725

Merged
merged 4 commits into from
May 31, 2023

Conversation

JoJoJet
Copy link
Member

@JoJoJet JoJoJet commented May 31, 2023

Objective

Several of our built-in Command types are too public:

  • GetOrSpawn is public, even though it only makes sense to call it from within Commands::get_or_spawn.
  • Remove and RemoveResource contain public PhantomData marker fields.

Solution

Remove GetOrSpawn and use an anonymous command. Make the marker fields private.


Migration Guide

The Command types Remove and RemoveResource may no longer be constructed manually.

// Before:
commands.add(Remove::<T> {
    entity: id,
    phantom: PhantomData,
});

// After:
commands.add(Remove::<T>::new(id));

// Before:
commands.add(RemoveResource::<T> { phantom: PhantomData });

// After:
commands.add(RemoveResource::<T>::new());

The command type GetOrSpawn has been removed. It was not possible to use this type outside of bevy_ecs.

@JoJoJet JoJoJet added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide C-Code-Quality A section of code that is hard to understand or change labels May 31, 2023
Copy link
Member

@james7132 james7132 left a comment

Choose a reason for hiding this comment

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

Thanks for the docs!

@james7132 james7132 added this pull request to the merge queue May 31, 2023
@james7132 james7132 added this to the 0.11 milestone May 31, 2023
Merged via the queue into bevyengine:main with commit 5472ea4 May 31, 2023
@JoJoJet JoJoJet deleted the command-privacy branch May 31, 2023 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Docs An addition or correction to our documentation M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants