HubRouting enum
Defines how a Cell.hub decides which spoke (child cell) should receive an incoming signal.
The HubRouting strategy acts like a traffic controller, reading the "address" (the Pulse.type) on a signal to determine its destination.
When to use
- Think of a Cell.hub as a post office and HubRouting as the sorting logic. Depending on the mode, the hub can look for an exact name, a zip code (prefix), or broadcast to everyone.
- exact: When you have one-to-one mapping (e.g., 'command.save' goes only to the 'save' spoke).
- prefix: When you have hierarchical categories (e.g., all signals starting with 'auth.' go to the Auth module).
- pattern: When you need flexible wildcard matching (e.g., 'user.*.success').
- multicast: When multiple parts of your app need to react to the same signal simultaneously.
How it works
When a pulse is HubHandle.emitted to the hub, the hub looks at the Pulse.type.
It then loops through its registered spokes and applies the chosen
routing strategy to find a match.
Non‑obvious
- Priority: If multiple spokes match in a non-multicast mode, the one with the highest priority wins.
- Longest-Prefix: In
prefixmode, the hub automatically selects the most specific match (e.g., 'user.login.success' will prefer a spoke named 'user.login' over a spoke named 'user').
Example
// Setting up a prefix-based router
final router = Cell.hub(
routing: HubRouting.prefix,
spokes: {
'auth': authHandler,
'auth.login': loginHandler, // This will be preferred for 'auth.login'
},
);
Values
- exact → const HubRouting
-
Matches the Pulse.type exactly against the spoke key.
Example: A pulse with type 'save' only goes to a spoke named 'save'.
- prefix → const HubRouting
-
Matches the beginning of the Pulse.type.
This is useful for hierarchical routing. If a pulse type is 'user.profile.update', it will match a spoke named 'user.profile' or just 'user'.
- pattern → const HubRouting
-
Uses wildcard patterns (
*and?) to match the Pulse.type.*matches any sequence of characters.?matches any single character.
Example: 'logs.*' matches 'logs.info' and 'logs.error'.
- multicast → const HubRouting
-
Sends the pulse to every spoke that matches the key.
Unlike the other modes which usually pick the "best" match, multicast treats the signal as a broadcast to all interested parties.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- index → int
-
A numeric identifier for the enumerated value.
no setterinherited
- name → String
-
Available on Enum, provided by the EnumName extension
The name of the enum value.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
-
values
→ const List<
HubRouting> - A constant List of the values in this enum, in order of their declaration.