Comments (5)
Hey @natemann, you are correct that we want all of our state mutations happening in the reducer, but we feel that this is a bit different.
This more akin to "glue" code, or you could call it "adapter" code. The AppState
struct contains a lot of fields, but we only want to share a few of those fields with the counter view. So, we create a custom computed property that shows how to project out the fields we care about (in the get
), and how to plug those fields back into the app state (in the set
).
This is mostly logic-less work, and that's why we feel it's different from the kind of state changes that happen inside a reducer.
Does that make sense?
from episode-code-samples.
@mbrandonw. Thanks. I understand the get, the ‘set’ seems necessary for the pullback operation. But even then, you have setters for both the state and the action, so it seems like the state may be getting mutated twice? I have not tested this though. It seems that the pullback is the only time the set will actually be called for either the state of the action.
Let’s say we didn’t have the pullback, but only had a setter for the action (or vice versa). I believe the AppState will still be mutated at the appropriated times.
from episode-code-samples.
You are right that the set
, and really the whole computed property, is only necessary for the pullback. We need it to get access to the key path that we pull back along.
The app state is not mutated twice though. We extract out a subset of state, CounterViewState
, hand it over to the counter reducer to mutate, and then we plug CounterViewState
back into AppState
. So the app state is only mutated a single time in that situation.
Does that clear things up?
from episode-code-samples.
Yep... that’s makes since. I have been using RxSwift and pure functions for the ViewModel. I like this approach to standardize the architecture ,especially for SwiftUI, but it seems overly verbose at times.
from episode-code-samples.
So appstate is mutated when counterstate gets plugged back in, through the set, but we are also updating the Appaction through the CounterAction. This is where I thought perhaps mutation was happening twice.
from episode-code-samples.
Related Issues (20)
- 0167 Navigation is weird on iPad HOT 1
- Please fix the error Episode #76 ~ HOT 2
- [0171-modularization-pt1] Setting Up HOT 3
- modularization folders architecture HOT 1
- Missing episode 187: URL Route? HOT 1
- Cannot convert value of type - Examples will not compile using Xcode 13.3 HOT 2
- Request: Re-Record Episode 100 to 103 and Update Source Code HOT 3
- Episode 196: Runtime warning work only in half of the cases HOT 1
- minor bug in episode 198 sample HOT 1
- Code sample for episode 220 is missing HOT 1
- Strange navigation on episode 220 HOT 1
- Episode 2 -> Fish playground -> Ambiguous use of 'init(utf8String:)'
- Episode 0228 - Composable Navigation: Destinations sample code not found HOT 1
- navigationDestination not triggered HOT 3
- Issue with running TCA on an M1 device. HOT 2
- 0148 Derived Behaviour - Animation HOT 2
- Is the source code for episode 150 unavailable? HOT 1
- Missing samples episodes code HOT 1
- @FocusState not working with new @BindableState API HOT 5
- UIApplication.shared.windows deprecated in iOS 15 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from episode-code-samples.