StateSubject
@propertyWrapper
public class StateSubject<Element> : Subject<Element>
A Subject that must always have a value.
You can use it as a property wrapper to make the emitting private in the class where it’s contained, but still expose an ObservableState
to the other classes.
-
The current state. Set a new value to emit an event to all
Observers.Declaration
Swift
public var value: Element { get set } -
Creates a state subject with an initial value.
Declaration
Swift
public init(_ initialValue: Element)Parameters
initialValueThe initial state value.
-
Emits a new state value to all subscribers and updates the stored state.
Declaration
Swift
public override func onNext(_ element: Element)Parameters
elementThe new state value.
-
Converts this
StateSubjectto anObservableStatethat is readonly and can only receive new values.Declaration
Swift
public func asObservableState() -> ObservableState<Element> -
Returns an observable that emits only new updates of this State.
Declaration
Swift
public func updates() -> Observable<Element> -
Returns this state subject as an observable.
Declaration
Swift
public override func asObservable() -> Observable<Element> -
The wrapped observable state value for property wrapper usage.
Declaration
Swift
public override var wrappedValue: ObservableState<Element> { get }
-
Emits the element only if it differs from the current value.
Declaration
Swift
func onNextIfChanged(_ element: Element)
View on GitHub