Skip to content

Commit 4d580c7

Browse files
minuscorpsebastianvarela
authored andcommitted
Add Action and ActionReducer docs
1 parent 1c62977 commit 4d580c7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Sources/Mini/Action.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616

1717
import Foundation
1818

19+
/**
20+
Protocol that has to be conformed by any object that can be dispatcher
21+
by a `Dispatcher` object.
22+
*/
1923
public 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

4248
extension 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

4856
extension 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

Sources/Mini/ActionReducer.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,27 @@
1717
import Foundation
1818
import RxSwift
1919

20+
/**
21+
The `Reducer` defines the behavior to be executed when a certain
22+
`Action` object is received.
23+
*/
2024
public 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
}

0 commit comments

Comments
 (0)