Skip to content

Files

Latest commit

 

History

History
59 lines (52 loc) · 1.05 KB

BusinessLogic.md

File metadata and controls

59 lines (52 loc) · 1.05 KB

Implement business logic

  1. Create empty MainFeature.swift file inside exmpl/Main folder in exmpl project
  2. Add imports
import Foundation
import Highway
  1. Add namespace for your module
// ...

enum MainFeature {}
  1. Add state data
// ...

extension MainFeature {
    struct State: Equatable {
        var count = 0
    }
}
  1. Add actions/events
// ...

extension MainFeature {
    enum Action: Equatable {
        case increment
        case decrement
    }
}
  1. Add reducer and business logic for state mutation
// ...

extension MainFeature {
    static func reducer() -> Reducer<MainFeature.State, MainFeature.Action> {
        return .init { state, action in
            switch action {
            case .increment:
                var state = state
                state.count += 1
                return state

            case .decrement:
                var state = state
                state.count -= 1
                return state
            }
        }
    }
}

Next: View