Skip to content

Commit f444001

Browse files
authored
Update performance article (#1642)
* Update performance doc to mention specifying view store type. * wip
1 parent ff0e4e7 commit f444001

File tree

1 file changed

+18
-9
lines changed
  • Sources/ComposableArchitecture/Documentation.docc/Articles

1 file changed

+18
-9
lines changed

Sources/ComposableArchitecture/Documentation.docc/Articles/Performance.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,14 @@ incurring unnecessary costs for sending actions.
486486
In very large SwiftUI applications you may experience degraded compiler performance causing long
487487
compile times, and possibly even compiler failures due to "complex expressions." The
488488
``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.
491491

492492
For example, if your view looks like this:
493493

494494
```swift
495495
struct FeatureView: View {
496-
let store: Store<FeatureState, FeatureAction>
496+
let store: StoreOf<Feature>
497497

498498
var body: some View {
499499
WithViewStore(self.store, observe: { $0 }) { viewStore in
@@ -503,16 +503,25 @@ struct FeatureView: View {
503503
}
504504
```
505505

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`:
507516

508517
```swift
509518
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>
512521

513-
init(store: Store<FeatureState, FeatureAction>) {
522+
init(store: StoreOf<Feature>) {
514523
self.store = store
515-
self.viewStore = ViewStore(self.store)
524+
self.viewStore = ViewStore(self.store, observe: { $0 })
516525
}
517526

518527
var body: some View {
@@ -521,4 +530,4 @@ struct FeatureView: View {
521530
}
522531
```
523532

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

Comments
 (0)