Expand description
§jonmo - Declarative Signals for Bevy
jonmo provides a way to define reactive signal chains in Bevy using a declarative
builder pattern. Signals originate from sources (like component changes, resource changes,
or specific entities) and can be transformed (map
), combined (combine_with
), or
deduplicated (dedupe
).
The core building block is the Signal
trait, representing a value that changes over time.
Chains are constructed starting with methods like SignalBuilder::from_component
or
SignalBuilder::from_resource
, followed by combinators like SignalExt::map
or
[SignalExt::combine_with
]. Signal chains must implement Clone
to be used with combinators
like combine_with
or to be cloned into closures.
Finally, a signal chain is activated by calling SignalExt::register
, which registers
the necessary Bevy systems and returns a [SignalHandle
] for potential cleanup.
Cleaning up a handle removes all systems created by that specific register
call
by decrementing reference counts. If systems were shared with other signal chains, cleaning up
one handle will only remove those shared systems if their reference count reaches zero.
§Execution Model
Internally, jonmo builds and maintains a dependency graph of Bevy systems. Each frame,
the JonmoPlugin
triggers the execution of this graph starting from the root systems
(created via SignalBuilder::from_*
methods). It pipes the output (Some(O)
) of a parent
system as the input (In<O>
) to its children using type-erased runners. This traversal
continues down each branch until a system returns None
(often represented by the
[TERMINATE
] constant), which halts propagation along that specific path for the current frame.
The signal propagation is managed internally by the JonmoPlugin
which should be added
to your Bevy App
.
Modules§
Structs§
- Combine
- Represents a combine node in the signal chain definition. Implements
Signal
. - Component
Option - Represents a node that extracts an optional component
C
from an entity signal. ImplementsSignal
. - Dedupe
- Represents a node that filters out consecutive duplicate values. Implements
Signal
. - Eq
- Represents a node that compares the upstream signal’s value for equality with a fixed value. Implements
Signal
. - Filter
- Represents a node that filters values based on a predicate system. Implements
Signal
. - Flatten
- Represents a node that flattens a signal of signals. Implements
Signal
. - HasComponent
- Represents a node that checks if an entity signal contains a specific component
C
. ImplementsSignal
. - Jonmo
Builder - A thin facade over a Bevy
Entity
enabling the ergonomic registration of reactive systems and children using a declarative builder pattern. Inspired by Dominator’s DomBuilder and Haalka’s NodeBuilder. - Jonmo
Plugin - The Bevy plugin required for
jonmo
signals to function. - Map
- Represents a map node in the signal chain definition. Implements
Signal
. - MapBool
- MapComponent
- Represents a node that extracts a component
C
from an entity signal. ImplementsSignal
. - MapFalse
- Represents a node that maps a
false
boolean signal value using a system. ImplementsSignal
. Executes the provided systemf
only when the upstream signal emitsfalse
. - MapNone
- Represents a node that maps a
None
signal value using a system. ImplementsSignal
. Executes the provided systemnone_system
only when the upstream signal emitsNone
, passing()
viaIn
. - MapOption
- Represents a node that maps an
Option<T>
signal value using different systems forSome
andNone
. ImplementsSignal
. Executessome_system
if the upstream emitsSome(T)
, passingT
viaIn
. Executesnone_system
if the upstream emitsNone
, passing()
viaIn
. - MapSome
- Represents a node that maps a
Some(T)
signal value using a system. ImplementsSignal
. Executes the provided systemsome_system
only when the upstream signal emitsSome(T)
, passingT
viaIn
. - MapTrue
- Represents a node that maps a
true
boolean signal value using a system. ImplementsSignal
. Executes the provided systemt
only when the upstream signal emitstrue
. - MapVec
- A map node in a
SignalVec
chain. - Mutable
Vec - A mutable vector that tracks changes as
VecDiff
s and sends them as a batch onflush
. This struct isClone
able, sharing the underlying state. - Neq
- Represents a node that compares the upstream signal’s value for inequality with a fixed value. Implements
Signal
. - Not
- Represents a node that applies logical negation to a boolean signal. Implements
Signal
. - Signal
Builder - Provides static methods for creating new signal chains (source signals).
- Signal
Debug - Represents a node that adds debug logging to a signal chain. Implements
Signal
. - Source
- Represents a source node in the signal chain definition. Implements
Signal
. - Source
Vec - A source node for a
SignalVec
chain. Holds the entity ID of the registered source system. - Switch
- Represents a node that dynamically switches between signals based on the upstream value. Implements
Signal
. - Throttle
- Represents a node that throttles the upstream signal based on a duration. Implements
Signal
.
Enums§
- Signal
Either - VecDiff
- Describes the changes to a
Vec
.
Traits§
- Into
Signal Either - Signal
- Represents a value that changes over time and handles internal registration logic.
- Signal
Ext - Extension trait providing combinator methods for types implementing
Signal
. - Signal
Vec - Represents a
Vec
that changes over time, yieldingVecDiff<T>
and handling registration. - Signal
VecExt - Extension trait providing combinator methods for types implementing
SignalVec
andClone
.
Functions§
- identity
- A generic identity system that takes an input
T
and returnsSome(T)
. Useful for signal graph nodes that just pass through data. - pipe_
signal - register_
signal - Helper to register a system, add the [
SystemRunner
] component, and manage [SignalNodeMetadata
].