ShouldEmitValue
public enum ShouldEmitValue<StateType>
A predicate that determines if a state change should notify subscribers or not, by comparing previous and new states and returning a Bool true in
case it should emit it, or false in case it should not emit it.
It comes with some standard options like .always, .never, .when(old, new) -> Bool and, for Equatable structures, .whenDifferent.
-
It will always emit changes, regardless of previous and new state
Declaration
Swift
case always -
It will never emit changes, regardless of previous and new state
Declaration
Swift
case never -
It’s a custom-defined predicate, you’ll be given old and new state, and must return a Bool indicating what you’ve decided from that change, being
truewhen you want this change to be notified, orfalsewhen you want it to be ignored.Declaration
Swift
case when((StateType, StateType) -> Bool) -
Evaluates the predicate and returns
truein case this should be emitted, orfalsein case this change should be ignoredDeclaration
Swift
public func shouldEmit(previous: StateType, new: StateType) -> Bool -
Evaluates the predicate and returns
truein case this should be ignored, orfalsein case this change should be emitted. It’s the exact inversion ofshouldEmitand useful for operator.removeDuplicatesthat some Reactive libraries offer.Declaration
Swift
public func shouldRemove(previous: StateType, new: StateType) -> Bool
-
For
Equatablestructures,.whenDifferentwill run==operator between old and new state, and notify when they are different, or ignore when they are equal.Declaration
Swift
public static var whenDifferent: ShouldEmitValue<StateType> { get }
View on GitHub
ShouldEmitValue Enumeration Reference