Skip to content

[Merged by Bors] - Add apply_or_insert functions to reflected component and resources - #5201

Closed
Shatur wants to merge 3 commits into
bevyengine:mainfrom
gardum-game:apply-or-insert
Closed

Shatur wants to merge 3 commits into
bevyengine:mainfrom
gardum-game:apply-or-insert

Conversation

@Shatur

@Shatur Shatur commented Jul 4, 2022 •

Copy link
Copy Markdown
Contributor

Objective

ReflectResource and ReflectComponent will panic on apply method if there is no such component. It's not very ergonomic. And not very good for performance since I need to check if such component exists first.

Solution

  • Add ReflectComponent::apply_or_insert and ReflectResource::apply_or_insert functions.
  • Rename ReflectComponent::add into ReflectComponent::insert for consistency.

Changelog

Added

  • ReflectResource::apply_or_insert and ReflectComponent::apply_on_insert.

Changed

  • Rename ReflectComponent::add into ReflectComponent::insert for consistency.
  • Use ReflectComponent::apply_on_insert in DynamicScene instead of manual checking.

Migration Guide

  • Rename ReflectComponent::add into ReflectComponent::insert.

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types labels Jul 4, 2022
Comment thread crates/bevy_ecs/src/reflect.rs Resolved
Comment thread crates/bevy_ecs/src/reflect.rs Resolved

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM once the doc comment changes are in.

@Shatur

Shatur commented Jul 4, 2022

Copy link
Copy Markdown
Contributor Author

While working on it I decided to open an issue with naming suggestions: #5202

@Shatur Shatur changed the title Add apply_or_insert_* functions to reflected component and resources Add apply_or_insert functions to reflected component and resources Jul 6, 2022
@Shatur

Shatur commented Jul 6, 2022

Copy link
Copy Markdown
Contributor Author

@alice-i-cecile rebased after #5219.

@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Jul 7, 2022

@jakobhellermann jakobhellermann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change looks good to me.
Long term I wonder whether we can get rid of ReflectComponent and ReflectResource and built these APIs on top of the raw untyped methods + ReflectFromPtr, but that can be considered separately.

@alice-i-cecile

Copy link
Copy Markdown
Member

bors r+

bors Bot pushed a commit that referenced this pull request Jul 11, 2022
…5201)

# Objective

`ReflectResource` and `ReflectComponent` will panic on `apply` method if there is no such component. It's not very ergonomic. And not very good for performance since I need to check if such component exists first.

## Solution

* Add `ReflectComponent::apply_or_insert` and `ReflectResource::apply_or_insert` functions.
* Rename `ReflectComponent::add` into `ReflectComponent::insert` for consistency.

---

## Changelog

### Added

* `ReflectResource::apply_or_insert` and `ReflectComponent::apply_on_insert`.

### Changed

* Rename `ReflectComponent::add` into `ReflectComponent::insert` for consistency.
* Use `ReflectComponent::apply_on_insert` in `DynamicScene` instead of manual checking.

## Migration Guide

* Rename `ReflectComponent::add` into `ReflectComponent::insert`.
@bors bors Bot changed the title Add apply_or_insert functions to reflected component and resources [Merged by Bors] - Add apply_or_insert functions to reflected component and resources Jul 11, 2022
@bors bors Bot closed this Jul 11, 2022
inodentry pushed a commit to IyesGames/bevy that referenced this pull request Aug 8, 2022
…evyengine#5201)

# Objective

`ReflectResource` and `ReflectComponent` will panic on `apply` method if there is no such component. It's not very ergonomic. And not very good for performance since I need to check if such component exists first.

## Solution

* Add `ReflectComponent::apply_or_insert` and `ReflectResource::apply_or_insert` functions.
* Rename `ReflectComponent::add` into `ReflectComponent::insert` for consistency.

---

## Changelog

### Added

* `ReflectResource::apply_or_insert` and `ReflectComponent::apply_on_insert`.

### Changed

* Rename `ReflectComponent::add` into `ReflectComponent::insert` for consistency.
* Use `ReflectComponent::apply_on_insert` in `DynamicScene` instead of manual checking.

## Migration Guide

* Rename `ReflectComponent::add` into `ReflectComponent::insert`.
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
…evyengine#5201)

# Objective

`ReflectResource` and `ReflectComponent` will panic on `apply` method if there is no such component. It's not very ergonomic. And not very good for performance since I need to check if such component exists first.

## Solution

* Add `ReflectComponent::apply_or_insert` and `ReflectResource::apply_or_insert` functions.
* Rename `ReflectComponent::add` into `ReflectComponent::insert` for consistency.

---

## Changelog

### Added

* `ReflectResource::apply_or_insert` and `ReflectComponent::apply_on_insert`.

### Changed

* Rename `ReflectComponent::add` into `ReflectComponent::insert` for consistency.
* Use `ReflectComponent::apply_on_insert` in `DynamicScene` instead of manual checking.

## Migration Guide

* Rename `ReflectComponent::add` into `ReflectComponent::insert`.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…evyengine#5201)

# Objective

`ReflectResource` and `ReflectComponent` will panic on `apply` method if there is no such component. It's not very ergonomic. And not very good for performance since I need to check if such component exists first.

## Solution

* Add `ReflectComponent::apply_or_insert` and `ReflectResource::apply_or_insert` functions.
* Rename `ReflectComponent::add` into `ReflectComponent::insert` for consistency.

---

## Changelog

### Added

* `ReflectResource::apply_or_insert` and `ReflectComponent::apply_on_insert`.

### Changed

* Rename `ReflectComponent::add` into `ReflectComponent::insert` for consistency.
* Use `ReflectComponent::apply_on_insert` in `DynamicScene` instead of manual checking.

## Migration Guide

* Rename `ReflectComponent::add` into `ReflectComponent::insert`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants