Trait SignalMapExt

Source
pub trait SignalMapExt: SignalMap {
    // Provided methods
    fn for_each<O, IOO, F, M>(self, system: F) -> ForEach<Self, O>
       where Self: Sized,
             Self::Key: 'static,
             Self::Value: 'static,
             O: Clone + 'static,
             IOO: Into<Option<O>> + 'static,
             F: IntoSystem<In<Vec<MapDiff<Self::Key, Self::Value>>>, IOO, M> + SSs { ... }
    fn map_value<O, F, M>(self, system: F) -> MapValue<Self, O>
       where Self: Sized,
             Self::Key: Clone + 'static,
             Self::Value: 'static,
             O: Clone + 'static,
             F: IntoSystem<In<Self::Value>, O, M> + SSs { ... }
    fn map_value_signal<S, F, M>(self, system: F) -> MapValueSignal<Self, S>
       where Self: Sized,
             Self::Key: Ord + Clone + SSs,
             Self::Value: 'static,
             S: Signal + Clone + 'static,
             S::Item: Clone + SSs,
             F: IntoSystem<In<Self::Value>, S, M> + SSs { ... }
    fn key(self, key: Self::Key) -> Key<Self>
       where Self: Sized,
             Self::Key: PartialEq + Clone + SSs,
             Self::Value: Clone + Send + 'static { ... }
    fn debug(self) -> Debug<Self>
       where Self: Sized,
             Self::Key: Debug + Clone + 'static,
             Self::Value: Debug + Clone + 'static { ... }
    fn boxed(self) -> Box<dyn SignalMap<Key = Self::Key, Value = Self::Value>>
       where Self: Sized { ... }
    fn register(self, world: &mut World) -> SignalHandle
       where Self: Sized { ... }
}
Expand description

Extension trait providing combinator methods for SignalMaps.

Provided Methods§

Source

fn for_each<O, IOO, F, M>(self, system: F) -> ForEach<Self, O>
where Self: Sized, Self::Key: 'static, Self::Value: 'static, O: Clone + 'static, IOO: Into<Option<O>> + 'static, F: IntoSystem<In<Vec<MapDiff<Self::Key, Self::Value>>>, IOO, M> + SSs,

Pass the “raw” Vec<MapDiff<Self::Key, Self::Value>> output of this SignalMap to a System, continuing propagation if the System returns Some or terminating for the frame if it returns None. This transforms the SignalMap into a Signal. Unlike most other SignalMap methods, .for_each, returns a Signal, not a SignalMap, since the output type need not be an Option<Vec<MapDiff>>. If the System logic is infallible, wrapping the result in an option is unnecessary.

Source

fn map_value<O, F, M>(self, system: F) -> MapValue<Self, O>
where Self: Sized, Self::Key: Clone + 'static, Self::Value: 'static, O: Clone + 'static, F: IntoSystem<In<Self::Value>, O, M> + SSs,

Pass each Value of this SignalMap to a System, transforming it.

§Example
use bevy_ecs::prelude::*;
use jonmo::prelude::*;

MutableBTreeMap::from([(1, 2), (3, 4)]).signal_map().map_value(|In(x)| x * 2); // outputs `SignalMap -> {1: 2, 3: 4}`
Source

fn map_value_signal<S, F, M>(self, system: F) -> MapValueSignal<Self, S>
where Self: Sized, Self::Key: Ord + Clone + SSs, Self::Value: 'static, S: Signal + Clone + 'static, S::Item: Clone + SSs, F: IntoSystem<In<Self::Value>, S, M> + SSs,

Pass each Value of this SignalMap to a System that produces a Signal, forwarding the output of each resulting Signal.

§Example
use bevy_ecs::prelude::*;
use jonmo::prelude::*;

MutableBTreeMap::from([(1, 2), (3, 4)]).signal_map()
    .map_value_signal(|In(x)|
        SignalBuilder::from_system(move |_: In<()>| x * 2).dedupe()
    ); // outputs `SignalMap -> {1: 4, 3: 8}`
Source

fn key(self, key: Self::Key) -> Key<Self>
where Self: Sized, Self::Key: PartialEq + Clone + SSs, Self::Value: Clone + Send + 'static,

Maps this SignalMap to a Key-lookup Signal which outputs Some<Value> if the Key is present and None otherwise.

§Example
use jonmo::prelude::*;

MutableBTreeMap::from([(1, 2), (3, 4)]).signal_map().key(1); // outputs `2`
Examples found in repository?
examples/letters.rs (line 96)
48fn ui_root(letters: MutableBTreeMap<char, LetterData>) -> JonmoBuilder {
49    JonmoBuilder::from(Node {
50        height: Val::Percent(100.0),
51        width: Val::Percent(100.0),
52        justify_content: JustifyContent::Center,
53        ..default()
54    })
55    .child(
56        JonmoBuilder::from(Node {
57            flex_direction: FlexDirection::Column,
58            row_gap: Val::Px(GAP * 2.),
59            padding: UiRect::all(Val::Px(GAP * 2.)),
60            width: Val::Px(WindowResolution::default().physical_width() as f32),
61            justify_content: JustifyContent::Center,
62            ..default()
63        })
64        .child(
65            JonmoBuilder::from(Node {
66                align_self: AlignSelf::Center,
67                justify_content: JustifyContent::FlexEnd,
68                width: Val::Percent(100.),
69                // height: Val::Px(100.),
70                padding: UiRect::all(Val::Px(GAP * 2.)),
71                ..default()
72            })
73            .child(
74                text_node()
75                    .insert((TextColor(BLUE), TextFont::from_font_size(LETTER_SIZE)))
76                    .with_component::<Node>(|mut node| node.height = Val::Px(100.))
77                    .component_signal(
78                        letters
79                            .signal_vec_entries()
80                            .map_in(|(_, LetterData { count, .. })| count)
81                            .sum()
82                            .dedupe()
83                            .map_in_ref(ToString::to_string)
84                            .map_in(Text)
85                            .map_in(Some),
86                    ),
87            ),
88        )
89        .children(ROWS.into_iter().map(move |row| {
90            JonmoBuilder::from(Node {
91                flex_direction: FlexDirection::Row,
92                column_gap: Val::Px(GAP * 2.),
93                ..default()
94            })
95            .children(row.chars().map(
96                clone!((letters) move |l| letter(l, letters.signal_map().key(l).map_in(Option::unwrap_or_default))),
97            ))
98            .child(
99                JonmoBuilder::from(Node {
100                    align_self: AlignSelf::Center,
101                    justify_content: JustifyContent::FlexEnd,
102                    flex_grow: 1.,
103                    padding: UiRect::all(Val::Px(GAP * 2.)),
104                    ..default()
105                })
106                .child(
107                    text_node()
108                        .insert((TextColor(BLUE), TextFont::from_font_size(LETTER_SIZE)))
109                        .component_signal(
110                            letters
111                                .signal_vec_entries()
112                                .filter(|In((letter, _))| row.contains(letter))
113                                .map_in(|(_, LetterData { count, .. })| count)
114                                .sum()
115                                .dedupe()
116                                .map_in_ref(ToString::to_string)
117                                .map_in(Text)
118                                .map_in(Some),
119                        ),
120                ),
121            )
122        })),
123    )
124}
Source

fn debug(self) -> Debug<Self>
where Self: Sized, Self::Key: Debug + Clone + 'static, Self::Value: Debug + Clone + 'static,

Adds debug logging to this SignalMap’s raw MapDiff outputs.

§Example
use bevy_ecs::prelude::*;
use jonmo::prelude::*;

let mut world = World::new();
let mut map = MutableBTreeMap::from([(1, 2), (3, 4)]);
let signal = map.signal_map().debug();
// `signal` logs `[ Replace { entries: [ (1, 2), (3, 4) ] } ]`
map.write().insert(5, 6);
world.commands().queue(map.flush());
// `signal` logs `[ Insert { key: 5, value: 6 } ]`
Source

fn boxed(self) -> Box<dyn SignalMap<Key = Self::Key, Value = Self::Value>>
where Self: Sized,

Erases the type of this SignalMap, allowing it to be used in conjunction with SignalMaps of other concrete types.

§Example
use bevy_ecs::prelude::*;
use jonmo::prelude::*;

let condition = true;
let signal = if condition {
    MutableBTreeMap::from([(1, 2), (3, 4)]).signal_map().map_value(|In(x): In<i32>| x * 2).boxed() // this is a `MapValue<Source<i32, i32>>`
} else {
    MutableBTreeMap::from([(1, 2), (3, 4)]).signal_map().map_value_signal(|In(x): In<i32>| SignalBuilder::from_system(move |_: In<()>| x * 2)).boxed() // this is a `MapValueSignal<Source<i32, i32>>`
}; // without the `.boxed()`, the compiler would not allow this
Source

fn register(self, world: &mut World) -> SignalHandle
where Self: Sized,

Activate this SignalMap and all its upstreams, causing them to be evaluated every frame until they are SignalHandle::cleanup-ed, see SignalHandle.

Implementors§

Source§

impl<T> SignalMapExt for T
where T: SignalMap + ?Sized,