GithubHelp home page GithubHelp logo

Comments (5)

mbrandonw avatar mbrandonw commented on August 22, 2024

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.

natemann avatar natemann commented on August 22, 2024

@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.

mbrandonw avatar mbrandonw commented on August 22, 2024

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.

natemann avatar natemann commented on August 22, 2024

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.

natemann avatar natemann commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.