Global Variables
The following global variables are available globally.
-
Undocumented
-
Listener filter callback that always returns true. When using this filter callback the Listener will always be notified.
Declaration
Swift
public let alwaysFilter: FilterFunction<Any> = { (oldSubState: Any, newSubState: Any) in -
Listener filter callback that returns true if the old state and the new state are not equal. You can use this filter function when adding a listener if you want your notification function to be called when the state changes.
In order to use this filter block your state types has to implement
SuasDynamicEquatableprotocol Note: if you implementEquatableyou can implementSuasDynamicEquatablewithout any extra code. You only have to includeSuasDynamicEquatablein the list of protocols for your type (check examples).Example
Implementing SuasDynamicEquatable manually
Implementing SuasDynamicEquatable without Equatable
// Implement SuasDynamicEquatable manually struct MyState: SuasDynamicEquatable { let value: Int func isEqual(to other: Any) -> Bool { // Cast to same type guard let other = other as? MyState else { return false } // Compare values return other.value == self.value } } let subscription = store.addListener(forStateType: MyState.self, if: EqualsFilter) { newState in // use new state }Implementing SuasDynamicEquatable as an extension
If your type implement equatable
struct MyState: Equatable { let value: Int static func ==(lhs: MyState, rhs: MyState) -> Bool { ... } }You dont need to implement
SuasDynamicEquatablejust add it as an extension toMyState. No extra code needed.extension MyState: SuasDynamicEquatable { }EqualsFilternow works withMyStatelet subscription = store.addListener(forStateType: MyState.self, if: EqualsFilter) { newState in // use new state }Declaration
Swift
public let EqualsFilter: FilterFunction<Any> = { (oldSubState: Any, newSubState: Any) in
View on GitHub
Global Variables Reference