Subscription
public struct Subscription<StateType>
Subscription structure that represents a listener subscription. When adding a listener you get a subscription back. You can use this subscription to remove the listener, notify about the current state or link the listener lifecycle with an object.
-
Notify the listener associated with this
Subscription
about the current state. Calls the listener block without dispatching an action.You can use this method to call the listener notification block with the current state, useful when you want to initialize some UI elements for example.
Example
let subscription = store.addListener(...) subscription.informWithCurrentState()
Declaration
Swift
public func informWithCurrentState()
-
Remove the listner associated with this subscription. After calling
removeListener
the listener won’t be notified anymore.Example
let subscription = store.addListener(...) subscription.removeListener()
Declaration
Swift
public func removeListener()
-
Link the listener associated with this subscription with an object. When the object gets deallocated the listener is removed. Useful when adding listeners that updates a UIView. You can link the listener lifecycle to the UIView’s lifecycle. When the UIView is removed (deallocated) the listener will be removed and will stop it from being notified.
Example
let view = SomeUIVIew() // Listener updates the view let subscription = store.addListener(...) // Link the listener lifecycle to the view. No need to manually call `removeListener` anymore. subscription.linkLifeCycleTo(object: view)
Declaration
Swift
public func linkLifeCycleTo(object: NSObject)