Skip to content

Commit

Permalink
Add second "contextless" example
Browse files Browse the repository at this point in the history
  • Loading branch information
cart committed Aug 8, 2024
1 parent 1ce21a1 commit ffc3c64
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion crates/bevy_ecs/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl World {
/// #[derive(Event, Clone, Debug)]
/// struct Foo(usize);
///
/// #[derive(Event, Debug)]
/// #[derive(Event, Clone, Debug)]
/// struct Bar(bool);
///
/// #[derive(Event, Debug)]
Expand All @@ -460,6 +460,29 @@ impl World {
/// println!("Combined Event: {:?}", trigger.event());
/// });
/// ```
///
/// ```
/// # use bevy_ecs::prelude::*;
/// # use bevy_ecs::observer::trigger_map;
/// # let mut world = World::new();
///
/// #[derive(Event, Clone, Debug)]
/// struct Foo(usize);
///
/// #[derive(Event, Clone, Debug)]
/// struct Bar(bool);
///
/// // If you don't care about capturing the original event context,
/// // you can just use a unit struct.
/// #[derive(Event, Debug)]
/// struct Combined;
///
/// world.observe(trigger_map(|event: Foo| Combined));
/// world.observe(trigger_map(|event: Bar| Combined));
/// world.observe(|trigger: Trigger<Combined>| {
/// println!("Combined Event");
/// });
/// ```
pub fn trigger_map<T: Event + Clone, U: Event, F: Fn(T) -> U + Send + Sync + 'static>(
map: F,
) -> impl ObserverSystem<T, ()> {
Expand Down

0 comments on commit ffc3c64

Please sign in to comment.