This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Katana | |
/// The definition state of the app | |
struct AppState: State { | |
/// Slice of the state for the Dice | |
var diceState = DiceState() | |
} | |
extension AppState { | |
/// Definition of the state of our dice rolls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Katana | |
import Tempura | |
/// The Container for the dependencies of the App | |
class AppDependencies: | |
SideEffectDependencyContainer, | |
NavigationProvider | |
{ | |
// The dispatch function that can be used to dispatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Katana | |
import Tempura | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate, RootInstaller { | |
var window: UIWindow? | |
var store: Store<AppState, AppDependencies>? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Tempura | |
struct DiceRollerVM: ViewModelWithState { | |
private let currentResults: [AppState.DiceState.Die: Int] | |
init(state: AppState) { | |
self.currentResults = state.diceState.currentResults | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DiceRollerView: UIView, ViewControllerModellableView { | |
typealias VM = DiceRollerVM | |
// MARK: - Helper Class | |
/// Small helper class that simplify the logic | |
private class DieButton: UIButton { | |
let die: AppState.DiceState.Die | |
required init(die: AppState.DiceState.Die) { | |
self.die = die | |
super.init(frame: .zero) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Tempura | |
class DiceRollerVC: ViewController<DiceRollerView> { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Katana | |
enum DiceRollerLogic { | |
struct RollDice: AnySideEffect { | |
let die: AppState.DiceState.Die | |
func sideEffect(_ context: AnySideEffectContext) throws { | |
let extreme = die.rawValue | |
let result = Int.random(in: 1...extreme) | |
context.dispatch(UpdateCurrentResult(die: die, result: result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func setupInteraction() { | |
self.rootView.rollDieInteraction = { [unowned self] die in | |
self.dispatch(DiceRollerLogic.RollDice(die: die)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyViewController: UIViewController { | |
var myPath: String | |
var content: [MyModel] | |
// ... | |
func loadContent() { | |
let fileManager = FileManager.default | |
guard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyViewController: UIViewController { | |
var myPath: String | |
var content: [MyModel] | |
// ... | |
func loadContent( | |
fileManager: FileManager, | |
path: String, | |
jsonDecoder: JSONDecoder = JSONDecoder() |