Skip to content

Commit 3a0332f

Browse files
committed
Cleanup comments and added missing @inlinable
1 parent 39463f6 commit 3a0332f

File tree

9 files changed

+43
-33
lines changed

9 files changed

+43
-33
lines changed

Sources/SwiftDux/Action/Action.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ public protocol RunnableAction: Action {
3333

3434
/// When the action is dispatched to a store, this method will be called to handle
3535
/// any logic by the action.
36+
///
3637
/// - Parameter store: The store that the action has been dispatched to.
3738
/// - Returns: An optional cancellable.
3839
func run<T>(store: Store<T>) -> AnyCancellable?
3940

41+
/// Send an action that can be cancelled.
42+
///
43+
/// - Parameter dispatcher: The send function that dispatches an action.
44+
/// - Returns: AnyCancellable to cancel the action plan.
45+
func sendAsCancellable(_ dispatcher: ActionDispatcher) -> AnyCancellable
4046
}
4147

4248
/// A noop action used by reducers that may not have their own actions.

Sources/SwiftDux/Action/ActionDispatcher.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ import Foundation
77
/// solely on changes to the state of the application to respond.
88
public protocol ActionDispatcher {
99

10-
/// Sends an action to a reducer to mutate the state of the application.
10+
/// Sends an action to mutate the application state.
11+
///
1112
/// - Parameter action: An action to dispatch to the store.
1213
func send(_ action: Action)
1314
}
1415

1516
extension ActionDispatcher {
1617

17-
/// Sends an action to a reducer to mutate the state of the application.
18+
/// Sends an action to mutate the application state.
19+
///
1820
/// - Parameter action: An action to dispatch to the store
1921
@inlinable public func callAsFunction(_ action: Action) {
2022
send(action)
2123
}
2224

2325
/// Send an action plan that returns a cancellable object.
26+
///
2427
/// - Parameter actionPlan: The action
2528
/// - Returns: A cancellable to cancel the action.
2629
@inlinable public func sendAsCancellable<T>(_ actionPlan: ActionPlan<T>) -> AnyCancellable {

Sources/SwiftDux/Action/ActionPlan.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public struct ActionPlan<State>: RunnableAction {
131131
/// func signUp() {
132132
/// signUpCancellable = signUpActionPlan(username: username, password: password).sendAsCancellable(dispatch)
133133
/// }
134-
///
135134
/// }
136135
/// ```
137136
///

Sources/SwiftDux/Middleware/CombinedMiddleware.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct CombinedMiddleware<State, A, B>: Middleware where A: Middleware, B
1111
}
1212

1313
/// Unimplemented. It simply calls `store.next(_:)`.
14-
public func run(store: StoreProxy<State>, action: Action) {
14+
@inlinable public func run(store: StoreProxy<State>, action: Action) {
1515
store.next(action)
1616
}
1717

Sources/SwiftDux/Reducer/Reducer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ public protocol Reducer {
4040
/// - action: Any kind of action.
4141
/// - Returns: A new immutable state
4242
func reduceAny(state: State, action: Action) -> State
43-
4443
}
4544

4645
extension Reducer {
@@ -85,11 +84,12 @@ extension Reducer {
8584
}
8685

8786
/// Compose two reducers together.
87+
///
8888
/// - Parameters:
8989
/// - previousReducer: The first reducer to be called.
9090
/// - nextReducer: The second reducer to be called.
9191
/// - Returns: A combined reducer.
92-
public static func + <R>(previousReducer: Self, _ nextReducer: R) -> CombinedReducer<State, Self, R> where R: Reducer, R.State == State {
92+
@inlinable public static func + <R>(previousReducer: Self, _ nextReducer: R) -> CombinedReducer<State, Self, R> where R: Reducer, R.State == State {
9393
CombinedReducer(previousReducer: previousReducer, nextReducer: nextReducer)
9494
}
9595
}

Sources/SwiftDux/Store/StateStorable.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import Foundation
33

44
/// Represents a storable container for a state object.
55
///
6-
/// Extend this protocol to implement new methods for the Store<_> and StoreProxy<_>.
6+
/// Extend this protocol to implement new methods for the Store<_> and StoreProxy<_> types.
77
public protocol StateStorable {
8+
/// The type of the stored state object.
89
associatedtype State
910

10-
/// Retrieves the latest state from the store.
11+
/// The latest state of the store.
1112
var state: State { get }
1213

13-
/// Emits after the specified action was sent to the store.
14+
/// Emits after the state has been changed.
1415
var didChange: StorePublisher { get }
1516
}
1617

Sources/SwiftDux/Store/Store.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
import Combine
22
import Foundation
33

4-
/// The primary container of an application's state.
5-
///
6-
/// The store both contains and mutates the state through a provided reducer as it's sent actions.
7-
/// Use the didChange publisher to be notified of changes.
4+
/// Stores and mutates the state of an application.
85
public final class Store<State>: StateStorable {
96

10-
/// The current state of the store. Use actions to mutate it.
7+
/// The current state of the store.
118
public private(set) var state: State {
129
didSet { didChange.send() }
1310
}
1411

15-
/// Subscribe for state changes. It emits the latest action sent to the store.
12+
/// Publishes when the state has changed.
1613
public let didChange = StorePublisher()
1714

1815
@usableFromInline
1916
internal var reduce: SendAction = { _ in }
2017

21-
/// Creates a new store for the given state and reducer.
18+
/// Initiates a new store for the given state and reducer.
2219
///
2320
/// - Parameters
24-
/// - state: The initial state of the store. A typically use case is to restore a previous application session with a persisted state object.
25-
/// - reducer: A reducer that will mutate the store's state as actions are dispatched to it.
21+
/// - state: The initial state of the store.
22+
/// - reducer: A reducer that mutates the state as actions are dispatched to it.
2623
/// - middleware: A middleware plugin.
2724
public init<R, M>(state: State, reducer: R, middleware: M) where R: Reducer, R.State == State, M: Middleware, M.State == State {
2825
let storeReducer = StoreReducer(rootReducer: reducer)
@@ -41,24 +38,25 @@ public final class Store<State>: StateStorable {
4138
send(StoreAction<State>.prepare)
4239
}
4340

44-
/// Creates a new store for the given state and reducer.
41+
/// Initiates a new store for the given state and reducer.
4542
///
4643
/// - Parameters
47-
/// - state: The initial state of the store. A typically use case is to restore a previous application session with a persisted state object.
48-
/// - reducer: A reducer that will mutate the store's state as actions are dispatched to it.
44+
/// - state: The initial state of the store.
45+
/// - reducer: A reducer that mutates the state as actions are dispatched to it.
4946
public convenience init<R>(state: State, reducer: R) where R: Reducer, R.State == State {
5047
self.init(state: state, reducer: reducer, middleware: NoopMiddleware())
5148
}
5249

53-
/// Create a proxy of the store for a given type that it adheres to.
50+
/// Create a proxy of the store for a given type or protocol.
51+
///
5452
/// - Parameters:
5553
/// - stateType: The type of state for the proxy. This must be a type that the store adheres to.
5654
/// - done: A closure called with an async action has completed.
5755
/// - Returns: A proxy object if the state type matches, otherwise nil.
5856
@inlinable public func proxy<T>(for stateType: T.Type, done: (() -> Void)? = nil) -> StoreProxy<T>? {
5957
guard state is T else { return nil }
6058
return StoreProxy<T>(
61-
getState: { [unowned self] in self.state as! T },
59+
getState: { self.state as! T },
6260
didChange: didChange,
6361
dispatcher: self,
6462
done: done
@@ -68,8 +66,9 @@ public final class Store<State>: StateStorable {
6866

6967
extension Store: ActionDispatcher {
7068

71-
/// Sends an action to the store to mutate its state.
72-
/// - Parameter action: The action to mutate the state.
69+
/// Sends an action to mutate the state.
70+
///
71+
/// - Parameter action: The action to perform.
7372
@inlinable public func send(_ action: Action) {
7473
if let action = action as? RunnableAction {
7574
_ = action.run(store: self)

Sources/SwiftDux/Store/StoreProxy.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,24 @@ public struct StoreProxy<State>: StateStorable, ActionDispatcher {
5353
self.doneBlock = done ?? proxy.doneBlock
5454
}
5555

56-
/// Send an action to the store.
56+
/// Sends an action to mutate the application state.
57+
///
5758
/// - Parameter action: The action to send
5859
@inlinable public func send(_ action: Action) {
5960
dispatcher.send(action)
6061
}
6162

62-
/// Use this in middleware to send an action to the next
63-
/// step in the pipeline. Outside of middleware, it does nothing.
63+
/// Passes an action to the next middleware.
64+
///
65+
/// Outside of the middleware pipeline this method does nothing.
6466
/// - Parameter action: The action to send
6567
@inlinable public func next(_ action: Action) {
6668
nextBlock?(action)
6769
}
6870

69-
/// Used by action plans to tell the store that a publisher has completed or cancelled its work.
70-
/// Only use this if the action plan is not returning a publisher or subscribing via ActionSubscriber.
71-
/// This is not needed by action plans that don't return a cancellable.
71+
/// Used by runnable action to tell the store that a publisher has completed or cancelled its work.
72+
///
73+
/// Only use this if the action returns a cancellable object without using ActionSubscriber.
7274
@inlinable public func done() {
7375
doneBlock?()
7476
}

Sources/SwiftDux/Store/StoreReducer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import Foundation
22

3-
/// Actions performed for the store itself.
3+
/// Actions performed by the store itself.
44
public enum StoreAction<State>: Action {
55

66
/// Called at the initialization step of the store to allow reducers and middleware an oppertunity
7-
/// to set up configurations Store actions may be dispatched at this stage, but other middleware
7+
/// to set up configurations. Store actions may be dispatched at this stage, but other middleware
88
/// and reducers might not be ready yet if they require any preparation themselves.
99
case prepare
1010

0 commit comments

Comments
 (0)