Skip to content

Commit f99f4f2

Browse files
authored
Update README with changes to Article and MyFeature
Updated the README to reflect changes in the Article struct and MyFeature actions, including integrating UndoManager registration and wrapping database operations in undoable.
1 parent d6bb227 commit f99f4f2

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

README.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ prepareDependencies {
1111
$0.defaultDatabase = try! appDatabase()
1212
$0.defaultUndoEngine = try! UndoEngine(
1313
for: $0.defaultDatabase,
14-
tables: Article.self, ProjectEdit.self
14+
tables: Article.self, Author.self
1515
)
1616
}
1717
```
@@ -21,7 +21,7 @@ Pass any `@Table` types to track:
2121
```swift
2222
@Table
2323
struct Article {
24-
@Column(primaryKey: true) var id: Int
24+
let id: Int
2525
var name: String
2626
}
2727
```
@@ -30,11 +30,7 @@ struct Article {
3030

3131
```swift
3232
import SQLiteUndo
33-
```
34-
35-
### Basic
3633

37-
```swift
3834
try await undoable("Set Rating") {
3935
try await database.write { db in
4036
try Article.find(id).update { $0.rating = 5 }.execute(db)
@@ -64,7 +60,7 @@ struct MyFeature {
6460
@ObservableState
6561
struct State { }
6662

67-
enum Action: UndoManageableAction {
63+
enum Action: UndoManageableAction { // ✅ integrate the store for UndoManager registration
6864
case undoManager(UndoManagingAction)
6965
case setRating(Int)
7066
}
@@ -78,26 +74,24 @@ struct MyFeature {
7874
case .undoManager:
7975
return .none
8076
case .setRating(let rating):
81-
return .run { _ in
82-
try await undoable("Set Rating") {
83-
try await database.write { db in
84-
try Article.find(id).update { $0.rating = rating }.execute(db)
85-
}
77+
try undoable("Set Rating") { // ✅ wrap db operations in undoable
78+
try database.write { db in
79+
try Article.find(id).update { $0.rating = rating }.execute(db)
8680
}
8781
}
82+
return .none
8883
}
8984
}
9085
}
9186
}
9287

9388
struct MyView: View {
9489
let store: StoreOf<MyFeature>
95-
9690
var body: some View {
9791
VStack {
9892
// ...
9993
}
100-
.setUndoManager(store: store)
94+
.setUndoManager(store: store) // ✅ pass the view's UndoManager to the system
10195
}
10296
}
10397
```

0 commit comments

Comments
 (0)