StateStorable
public protocol StateStorable
Represents a storable container for a state object.
Extend this protocol to implement new methods for the Store<> and StoreProxy<> types.
-
The type of the stored state object.
Declaration
Swift
associatedtype State
-
The latest state of the store.
Declaration
Swift
var state: State { get }
-
Emits after the state has been changed.
Declaration
Swift
var didChange: StorePublisher { get }
-
publish(_:
Extension method) Publishes the state as it changes with a mapping function.
Declaration
Swift
@inlinable public func publish<Props>(_ mapState: @escaping (State) -> Props) -> Publishers.RemoveDuplicates<Publishers.Map<Publishers.Merge<StorePublisher, Just<()>>, Props>> where Props: Equatable
Parameters
mapState
Maps the state to a more relevant props object.
Return Value
A new publisher that emits non-duplicate updates.
-
publish()
Extension methodPublishes the state as it changes.
Declaration
Swift
@inlinable public func publish() -> Publishers.RemoveDuplicates<Publishers.Map<Publishers.Merge<StorePublisher, Just<()>>, State>>
Return Value
A new publisher that emits non-duplicate updates.
-
proxy(dispatcher:
Extension method) Create a proxy of the
StateStorable
for a given type or protocol.Declaration
Swift
@inlinable public func proxy(dispatcher: ActionDispatcher? = nil) -> StoreProxy<State>
Parameters
dispatcher
An optional dispatcher for the proxy.
Return Value
A proxy object if the state type matches, otherwise nil.
-
proxy(for:
Extension methoddispatcher: ) Create a proxy of the
StateStorable
for a given type or protocol.Declaration
Swift
@inlinable public func proxy<T>(for stateType: T.Type, dispatcher: ActionDispatcher? = nil) -> StoreProxy<T>?
Parameters
stateType
The type of state for the proxy. This must be a type that the store adheres to.
dispatcher
An optional dispatcher for the proxy.
Return Value
A proxy object if the state type matches, otherwise nil.