Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions MiniSlice.swiftpm/Sources/MiniSliceApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ private var editor = EditorViewModel(preview: preview)
@main
struct MiniSliceApp: App {
var body: some Scene {
WindowGroup {
ContentView()
DocumentGroup(newDocument: RecipeDocument()) { configuration in
ContentView(document: configuration.$document)
.environmentObject(preview)
.environmentObject(editor)
}
Expand Down
10 changes: 10 additions & 0 deletions MiniSlice.swiftpm/Sources/View/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import SwiftUI

struct ContentView: View {
@Binding var document: RecipeDocument
@EnvironmentObject private var editor: EditorViewModel

var body: some View {
HStack {
EditorView()
PreviewView()
}
.onAppear {
// TODO: Is this sufficient? The user should be able to open documents, which might not cause the ContentView to 're-appear' but only update? We don't listen to document changes directly to prevent a listener cycle.
editor.rawRecipe = document.raw
}
.onChange(of: editor.rawRecipe) { raw in
document.raw = raw
}
}
}