StateSubject Class Reference
@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 publishing 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 publish an event to all
ObserversDeclaration
Swift
public var value: Element { get set } -
Creates a state subject with an initial value.
Declaration
Swift
public init(_ initialValue: Element)Parameter Description initialValueThe initial state value.
-
Publishes a new state value.
Declaration
Swift
public override func publish(_ element: Element)Parameter Description 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 }
-
Publishes the new event only if the new one is different from the last one
Declaration
Swift
func publishIfChanged(_ element: Element)