//
//  ViewController.swift
//  ComposeUI
//
//  Created by Shadowfacts on 3/4/23.
//

import SwiftUI
import Combine

public protocol ViewController: ObservableObject {
    associatedtype ContentView: View
    
    @ViewBuilder
    var view: ContentView { get }
}

public struct ControllerView<Controller: ViewController>: View {
    @StateObject private var controller: Controller
    
    public init(controller: @escaping () -> Controller) {
        self._controller = StateObject(wrappedValue: controller())
    }
    
    public var body: some View {
        controller.view
            .environmentObject(controller)
    }
}
