MappedEvent<V, T> class
A MappedEvent is useful when your event value must be transformed by some function that, usually, needs the store state. You must provide the event and a map-function. The map-function must be able to deal with the spent state (null or false, accordingly).
For example, if state.indexEvt = Event<int>(5)
and you must get
a user from it:
var mapFunction = (index) => index == null ? null : state.users[index];
Event<User> userEvt = MappedEvent<int, User>(state.indexEvt, mapFunction);
Constructors
-
MappedEvent(Event<
V> ? evt, T? mapFunction(V?))
Properties
-
evt
↔ Event<
V> -
getter/setter pair
- hashCode → int
-
- If two objects are equal according to the equals method, then hashcode of both must be the same. Since spent events are all equal, they should produce the same hashcode.
- If two objects are NOT equal, hashcode may be the same or not, but it's better when they are not the same. However, events are mutable, and this could mean the hashcode of the state could be changed when an event is consumed. To avoid this, we make events always return the same hashCode.
no setterinherited - isNotSpent → bool
-
no setterinherited
- isSpent → bool
-
no setteroverride
- mapFunction ↔ T? Function(V?)
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → T?
-
Returns the event state.
no setteroverride
Methods
-
consume(
) → T? -
Returns the event state and consumes the event.
override
-
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 StoreConnector has a
distinct
parameter which may be set totrue
. As a performance optimization,distinct:true
allows the widget to be rebuilt only when the ViewModel changes. If this is not done, then every time any state in the store changes the widget will be rebuilt.inherited