mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-03-30 13:43:26 +08:00
fix: correct SwiftUI skill ViewModel injection and Equatable comparison
Fix ItemListView to accept viewModel via init with default parameter so previews can inject mocks. Fix ExpensiveChartView Equatable to compare full array instead of only count.
This commit is contained in:
@@ -59,7 +59,11 @@ final class ItemListViewModel {
|
|||||||
|
|
||||||
```swift
|
```swift
|
||||||
struct ItemListView: View {
|
struct ItemListView: View {
|
||||||
@State private var viewModel = ItemListViewModel()
|
@State private var viewModel: ItemListViewModel
|
||||||
|
|
||||||
|
init(viewModel: ItemListViewModel = ItemListViewModel()) {
|
||||||
|
_viewModel = State(initialValue: viewModel)
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
List(viewModel.items) { item in
|
List(viewModel.items) { item in
|
||||||
@@ -215,10 +219,10 @@ For views with expensive bodies, conform to `Equatable` to skip unnecessary re-r
|
|||||||
|
|
||||||
```swift
|
```swift
|
||||||
struct ExpensiveChartView: View, Equatable {
|
struct ExpensiveChartView: View, Equatable {
|
||||||
let dataPoints: [DataPoint]
|
let dataPoints: [DataPoint] // DataPoint must conform to Equatable
|
||||||
|
|
||||||
static func == (lhs: Self, rhs: Self) -> Bool {
|
static func == (lhs: Self, rhs: Self) -> Bool {
|
||||||
lhs.dataPoints.count == rhs.dataPoints.count
|
lhs.dataPoints == rhs.dataPoints
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -233,13 +237,11 @@ Use `#Preview` macro with inline mock data for fast iteration:
|
|||||||
|
|
||||||
```swift
|
```swift
|
||||||
#Preview("Empty state") {
|
#Preview("Empty state") {
|
||||||
ItemListView()
|
ItemListView(viewModel: ItemListViewModel(repository: EmptyMockRepository()))
|
||||||
.environment(ItemListViewModel(repository: EmptyMockRepository()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview("Loaded") {
|
#Preview("Loaded") {
|
||||||
ItemListView()
|
ItemListView(viewModel: ItemListViewModel(repository: PopulatedMockRepository()))
|
||||||
.environment(ItemListViewModel(repository: PopulatedMockRepository()))
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user