// // RootFeature.swift // Root // import Foundation import Facts import CatFactsKit import ComposableArchitecture /// Handles interaction logic for the root of the application. Doesn't otherwise do much itself but it does respond to /// a `viewAppeared` action so that it can show how one might change the state that drives _another_ feature (in this /// example, `FactsFeature`). @Reducer public struct RootFeature { @ObservableState public struct State { var facts: FactsFeature.State = .init(baseURL: URL(string: "https://invalid.barf")!) public var baseURL: URL? public init() { } } public enum Action { case viewAppeared case facts(FactsFeature.Action) } public init() { } public var body: some ReducerOf { // This fun DSL lets me provide a concrete Feature reducer when the Root feature is asked for a scoped store Scope(state: \.facts, action: \.facts) { FactsFeature() } // And then this is everything that's provided by the root. Reduce { state, action in switch action { case .viewAppeared: state.facts = .init(baseURL: URL(string: "https://meowfacts.herokuapp.com/")!) return .none case .facts: return .none } } } }