@@ -486,14 +486,14 @@ incurring unnecessary costs for sending actions.
486
486
In very large SwiftUI applications you may experience degraded compiler performance causing long
487
487
compile times, and possibly even compiler failures due to " complex expressions." The
488
488
``WithViewStore`` helpers that come with the library can exacerbate that problem for very complex
489
- views. If you are running into issues using ``WithViewStore`` you can make a small change to your
490
- view to use an ` @ObservedObject ` directly .
489
+ views. If you are running into issues using ``WithViewStore``, there are two options for fixing
490
+ the problem .
491
491
492
492
For example, if your view looks like this:
493
493
494
494
```swift
495
495
struct FeatureView: View {
496
- let store: Store<FeatureState, FeatureAction >
496
+ let store: StoreOf<Feature >
497
497
498
498
var body: some View {
499
499
WithViewStore (self .store , observe : { $0 }) { viewStore in
@@ -503,16 +503,25 @@ struct FeatureView: View {
503
503
}
504
504
```
505
505
506
- ... and you start running into compiler troubles, then you can refactor to the following:
506
+ … and you start running into compiler troubles, then you can explicitly specify the type of the
507
+ view store in the closure:
508
+
509
+ ```swift
510
+ WithViewStore (self .store , observe : { $0 }) { (viewStore : ViewStoreOf< Feature> ) in
511
+ // A large, complex view inside here...
512
+ }
513
+ ```
514
+
515
+ Or you can refactor the view to use an `@ObservedObject `:
507
516
508
517
```swift
509
518
struct FeatureView: View {
510
- let store: Store<FeatureState, FeatureAction >
511
- @ObservedObject var viewStore: ViewStore<FeatureState, FeatureAction >
519
+ let store: StoreOf<Feature >
520
+ @ObservedObject var viewStore: ViewStoreOf<Feature >
512
521
513
- init (store : Store<FeatureState, FeatureAction >) {
522
+ init (store : StoreOf<Feature >) {
514
523
self .store = store
515
- self .viewStore = ViewStore (self .store )
524
+ self .viewStore = ViewStore (self .store , observe : { $0 } )
516
525
}
517
526
518
527
var body: some View {
@@ -521,4 +530,4 @@ struct FeatureView: View {
521
530
}
522
531
```
523
532
524
- That should greatly improve the compiler's ability to type- check your view.
533
+ Both of these options should greatly improve the compiler's ability to type- check your view.
0 commit comments