File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1616
1717import Foundation
1818
19+ /**
20+ Protocol that has to be conformed by any object that can be dispatcher
21+ by a `Dispatcher` object.
22+ */
1923public protocol Action {
24+ /// Equality function between `Action` objects
25+ /// - Returns: If an `Action` is the same as other.
2026 func isEqual( to other: Action ) -> Bool
2127}
2228
@@ -40,12 +46,17 @@ extension Action {
4046}
4147
4248extension Action {
49+ /// Equality operator between `Action` objects.
50+ /// - Returns: If the `Action`s are equal or not.
4351 public static func == ( lhs: Self , rhs: Self ) -> Bool {
4452 return lhs. isEqual ( to: rhs)
4553 }
4654}
4755
4856extension Action where Self: Equatable {
57+ /// Convenience `isEqual` implementation when the `Action` object
58+ /// implements `Equatable`.
59+ /// - Returns: Whether the `Action` object is the same as other.
4960 public func isEqual( to other: Action ) -> Bool {
5061 guard let action = other as? Self else { return false }
5162 return self == action
Original file line number Diff line number Diff line change 1717import Foundation
1818import RxSwift
1919
20+ /**
21+ The `Reducer` defines the behavior to be executed when a certain
22+ `Action` object is received.
23+ */
2024public class Reducer < A: Action > : Disposable {
25+ /// The `Action` type which the `Reducer` listens to.
2126 public let action : A . Type
27+ /// The `Dispatcher` object that sends the `Action` objects.
2228 public let dispatcher : Dispatcher
29+ /// The behavior to be executed when the `Dispatcher` sends a certain `Action`
2330 public let reducer : ( A ) -> Void
2431
2532 private var disposable : Disposable !
2633
34+ /**
35+ Initializes a new `Reducer` object.
36+ - Parameter action: The `Action` type that will be listened to.
37+ - Parameter dispatcher: The `Dispatcher` that sends the `Action`.
38+ - Parameter reducer: The closure that will be executed when the `Dispatcher`
39+ sends the defined `Action` type.
40+ */
2741 public init ( of action: A . Type , on dispatcher: Dispatcher , reducer: @escaping ( A ) -> Void ) {
2842 self . action = action
2943 self . dispatcher = dispatcher
@@ -38,6 +52,7 @@ public class Reducer<A: Action>: Disposable {
3852 return disposable
3953 }
4054
55+ /// Dispose resource.
4156 public func dispose( ) {
4257 disposable. dispose ( )
4358 }
You can’t perform that action at this time.
0 commit comments