pub trait SignalMapExt: SignalMap {
// Provided methods
fn for_each<O, IOO, F, M>(self, system: F) -> ForEach<Self, O>
where Self: Sized,
Self::Key: Send + Sync + 'static,
Self::Value: Send + Sync + 'static,
O: Clone + Send + Sync + 'static,
IOO: Into<Option<O>> + 'static,
F: IntoSystem<In<Vec<MapDiff<Self::Key, Self::Value>>>, IOO, M> + Send + Sync + 'static { ... }
fn map_value<O, F, M>(self, system: F) -> MapValue<Self, O>
where Self: Sized,
Self::Key: Clone + Send + Sync + 'static,
Self::Value: Send + Sync + 'static,
O: Clone + Send + Sync + 'static,
F: IntoSystem<In<Self::Value>, O, M> + Send + Sync + 'static { ... }
fn map_value_signal<S, F, M>(self, system: F) -> MapValueSignal<Self, S>
where Self: Sized,
Self::Key: Ord + Clone + Send + Sync + 'static,
Self::Value: Send + Sync + 'static,
S: Signal + Clone + 'static,
S::Item: Clone + Send + Sync + 'static,
F: IntoSystem<In<Self::Value>, S, M> + Send + Sync + 'static { ... }
fn key(self, key: Self::Key) -> Key<Self>
where Self: Sized,
Self::Key: PartialEq + Send + Sync + 'static,
Self::Value: Clone + Send + Sync + 'static { ... }
fn debug(self) -> Debug<Self>
where Self: Sized,
Self::Key: Debug + Clone + Send + Sync + 'static,
Self::Value: Debug + Clone + Send + Sync + 'static { ... }
fn boxed(self) -> Box<dyn SignalMap<Key = Self::Key, Value = Self::Value>>
where Self: Sized { ... }
fn boxed_clone(
self,
) -> Box<dyn SignalMapDynClone<Key = Self::Key, Value = Self::Value> + Send + Sync>
where Self: Sized + Clone { ... }
fn schedule<Sched: ScheduleLabel + Default + 'static>(
self,
) -> ScheduledMap<Sched, Self::Key, Self::Value>
where Self: Sized + 'static { ... }
fn register(self, world: &mut World) -> SignalHandle
where Self: Sized { ... }
}Expand description
Extension trait providing combinator methods for SignalMaps.
Provided Methods§
Sourcefn for_each<O, IOO, F, M>(self, system: F) -> ForEach<Self, O>
fn for_each<O, IOO, F, M>(self, system: F) -> ForEach<Self, O>
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.
Sourcefn map_value<O, F, M>(self, system: F) -> MapValue<Self, O>
fn map_value<O, F, M>(self, system: F) -> MapValue<Self, O>
Pass each Value of this SignalMap to a System, transforming
it.
§Example
use bevy_ecs::prelude::*;
use jonmo::prelude::*;
let mut world = World::new();
MutableBTreeMap::builder()
.values([(1, 2), (3, 4)])
.spawn(&mut world)
.signal_map()
.map_value(|In(x)| x * 2); // outputs `SignalMap -> {1: 2, 3: 4}`Sourcefn map_value_signal<S, F, M>(self, system: F) -> MapValueSignal<Self, S>
fn map_value_signal<S, F, M>(self, system: F) -> MapValueSignal<Self, S>
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::*;
let mut world = World::new();
MutableBTreeMap::builder().values([(1, 2), (3, 4)])
.spawn(&mut world)
.signal_map()
.map_value_signal(|In(x)|
signal::from_system(move |In(_)| x * 2).dedupe()
); // outputs `SignalMap -> {1: 4, 3: 8}`Sourcefn key(self, key: Self::Key) -> Key<Self>
fn key(self, key: Self::Key) -> Key<Self>
Maps this SignalMap to a Key-lookup Signal which outputs Some<Value> if the
Key is present and None otherwise.
§Example
use bevy_ecs::prelude::*;
use jonmo::prelude::*;
let mut world = World::new();
MutableBTreeMap::builder()
.values([(1, 2), (3, 4)])
.spawn(&mut world)
.signal_map()
.key(1); // outputs `2`Examples found in repository?
70fn ui_root() -> jonmo::Builder {
71 let active_save = signal::from_resource_changed::<ActiveSave>();
72
73 jonmo::Builder::from(Node {
74 height: Val::Percent(100.0),
75 width: Val::Percent(100.0),
76 justify_content: JustifyContent::Center,
77 ..default()
78 })
79 .child(
80 jonmo::Builder::from(Node {
81 flex_direction: FlexDirection::Column,
82 row_gap: Val::Px(GAP * 2.),
83 padding: UiRect::all(Val::Px(GAP * 4.)),
84 width: Val::Px(WindowResolution::default().physical_width() as f32),
85 justify_content: JustifyContent::Center,
86 ..default()
87 })
88 .child(
89 jonmo::Builder::from(Node {
90 align_self: AlignSelf::Center,
91 width: Val::Percent(100.),
92 ..default()
93 })
94 .child(
95 jonmo::Builder::from(Node {
96 flex_direction: FlexDirection::Row,
97 column_gap: Val::Px(GAP * 2.),
98 ..default()
99 })
100 .children(SAVE_CHARS.chars().map(clone!((active_save) move |save_char| {
101 save_card(save_char, active_save.clone())
102 }))),
103 )
104 .child(
105 sum_container()
106 .child(
107 text_node()
108 .insert((TextColor(BLUE), TextFont::from_font_size(LETTER_SIZE)))
109 .with_component::<Node>(|mut node| node.height = Val::Px(100.))
110 .component_signal(
111 active_save
112 .clone()
113 .switch_signal_vec(move |In(active_save): In<ActiveSave>, save_states: Res<SaveStates>| {
114 get_active_map(&save_states, active_save).signal_vec_entries()
115 })
116 .map_in(|(_, LetterData { count, .. })| count)
117 .sum()
118 .dedupe()
119 .map_in_ref(ToString::to_string)
120 .map_in(Text)
121 .map_in(Some),
122 )
123 ),
124 ),
125 )
126 .children(ROWS.into_iter().map(clone!((active_save) move |row| {
127 jonmo::Builder::from(Node {
128 flex_direction: FlexDirection::Row,
129 column_gap: Val::Px(GAP * 2.),
130 ..default()
131 })
132 .children(row.chars().map(
133 clone!((active_save) move |l| {
134 let letter_data = active_save
135 .clone()
136 .switch_signal_map(move |In(active_save): In<ActiveSave>, save_states: Res<SaveStates>| {
137 get_active_map(&save_states, active_save).signal_map()
138 })
139 .key(l)
140 .map_in(Option::unwrap_or_default);
141 letter(l, letter_data)
142 }),
143 ))
144 .child(
145 sum_container()
146 .child(
147 text_node()
148 .insert((TextColor(BLUE), TextFont::from_font_size(LETTER_SIZE)))
149 .component_signal(
150 active_save
151 .clone()
152 .switch_signal_vec(move |In(active_save): In<ActiveSave>, save_states: Res<SaveStates>| {
153 get_active_map(&save_states, active_save).signal_vec_entries()
154 })
155 .filter(move |In((letter, _))| row.contains(letter))
156 .map_in(|(_, LetterData { count, .. })| count)
157 .sum()
158 .dedupe()
159 .map_in_ref(ToString::to_string)
160 .map_in(Text)
161 .map_in(Some),
162 ),
163 ),
164 )
165 }))),
166 )
167}Sourcefn debug(self) -> Debug<Self>
fn debug(self) -> Debug<Self>
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::builder()
.values([(1, 2), (3, 4)])
.spawn(&mut world);
let signal = map.signal_map().debug();
// `signal` logs `[ Replace { entries: [ (1, 2), (3, 4) ] } ]`
map.write(&mut world).insert(5, 6);
// `signal` logs `[ Insert { key: 5, value: 6 } ]` on next updateSourcefn boxed(self) -> Box<dyn SignalMap<Key = Self::Key, Value = Self::Value>>where
Self: Sized,
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 mut world = World::new();
let condition = true;
let signal = if condition {
MutableBTreeMap::builder()
.values([(1, 2), (3, 4)])
.spawn(&mut world)
.signal_map()
.map_value(|In(x): In<i32>| x * 2)
.boxed() // this is a `MapValue<Source<i32, i32>>`
} else {
MutableBTreeMap::builder()
.values([(1, 2), (3, 4)])
.spawn(&mut world)
.signal_map()
.map_value_signal(|In(x): In<i32>| signal::from_system(move |In(_)| x * 2))
.boxed() // this is a `MapValueSignal<Source<i32, i32>>`
}; // without the `.boxed()`, the compiler would not allow thisSourcefn boxed_clone(
self,
) -> Box<dyn SignalMapDynClone<Key = Self::Key, Value = Self::Value> + Send + Sync>
fn boxed_clone( self, ) -> Box<dyn SignalMapDynClone<Key = Self::Key, Value = Self::Value> + Send + Sync>
Erases the type of this SignalMap, allowing it to be used in conjunction with
SignalMaps of other concrete types, particularly in cases where the consumer requires
Clone, e.g. .switch_signal_map.
§Example
use bevy_ecs::prelude::*;
use jonmo::prelude::*;
signal::from_system(|In(_)| true).switch_signal_map(
|In(condition): In<bool>, world: &mut World| {
if condition {
MutableBTreeMap::builder()
.values([(1, 2), (3, 4)])
.spawn(world)
.signal_map()
.map_value(|In(x): In<i32>| x * 2)
.boxed_clone() // this is a `MapValue<Source<i32, i32>>`
} else {
MutableBTreeMap::builder()
.values([(1, 2), (3, 4)])
.spawn(world)
.signal_map()
.map_value_signal(|In(x): In<i32>| signal::from_system(move |In(_)| x * 2))
.boxed_clone() // this is a `MapValueSignal<Source<i32, i32>>`
} // without the `.boxed_clone()`, the compiler would not allow this
},
);Sourcefn schedule<Sched: ScheduleLabel + Default + 'static>(
self,
) -> ScheduledMap<Sched, Self::Key, Self::Value>where
Self: Sized + 'static,
fn schedule<Sched: ScheduleLabel + Default + 'static>(
self,
) -> ScheduledMap<Sched, Self::Key, Self::Value>where
Self: Sized + 'static,
Assign a schedule to this signal map chain, see SignalExt::schedule.
§Panics
Panics if the schedule has not been registered with
JonmoPlugin::with_schedule.
Sourcefn register(self, world: &mut World) -> SignalHandlewhere
Self: Sized,
fn register(self, world: &mut World) -> SignalHandlewhere
Self: Sized,
Activate this SignalMap and all its upstreams, causing them to be evaluated every frame
until they are SignalHandle::cleanup-ed, see SignalHandle.