ViewModelWithLocalState

public protocol ViewModelWithLocalState : ViewModelWithState

A special case of ViewModel used to select part of the Katana app state and ViewControllerWithLocalState‘s LocalState that is of interest for the View.

   struct CounterState: State {
     var counter: Int = 0
   }
   struct ScreenLocalState: LocalState {
     var isCounting: Bool = false
   }
   struct CounterViewModel: ViewModelWithState {
     var countDescription: String

     init(state: CounterState?, localState: ScreenLocalState) {
       if let state = state, localState.isCounting {
         self.countDescription = "the counter is at \(state.counter)"
       } else {
         self.countDescription = "we are not counting yet"
       }
     }
   }