Revision control
Copy as Markdown
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
import UIKit
@testable import Redux
let windowUUID = UUID(uuidString: "D9D9D9D9-D9D9-D9D9-D9D9-CD68A019860B")!
class FakeReduxViewController: UIViewController, StoreSubscriber {
typealias SubscriberStateType = FakeReduxState
var receivedStateCounterValue: Int?
var isInPrivateMode: Bool?
override func viewDidLoad() {
super.viewDidLoad()
subscribeToRedux()
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
unsubscribeFromRedux()
}
// MARK: - Redux
func subscribeToRedux() {
store.subscribe(self)
let action = FakeReduxAction(windowUUID: windowUUID, actionType: FakeReduxActionType.requestInitialValue)
store.dispatch(action)
}
func unsubscribeFromRedux() {
store.unsubscribe(self)
}
func newState(state: FakeReduxState) {
receivedStateCounterValue = state.counter
isInPrivateMode = state.isInPrivateMode
}
// MARK: - Helper functions (Legacy Actions)
func increaseCounter() {
let action = FakeReduxAction(windowUUID: windowUUID, actionType: FakeReduxActionType.increaseCounter)
store.dispatch(action)
}
func decreaseCounter() {
let action = FakeReduxAction(windowUUID: windowUUID, actionType: FakeReduxActionType.decreaseCounter)
store.dispatch(action)
}
func setPrivateMode(to value: Bool) {
let action = FakeReduxAction(privateMode: value,
windowUUID: windowUUID,
actionType: FakeReduxActionType.setPrivateModeTo)
store.dispatch(action)
}
// MARK: - Helper functions (Modern Actions)
func increaseCounter_ModernAction() {
store.dispatch(FakeReduxModernAction.increaseCounter, forWindowUUID: windowUUID)
}
func decreaseCounter_ModernAction() {
store.dispatch(FakeReduxModernAction.decreaseCounter, forWindowUUID: windowUUID)
}
func setPrivateMode_ModernAction(to value: Bool) {
store.dispatch(FakeReduxModernAction.setPrivateModeTo(isPrivate: value), forWindowUUID: windowUUID)
}
}