Giter Club home page Giter Club logo

Comments (2)

lordzsolt avatar lordzsolt commented on May 26, 2024

While I'm not the author of the article, I can at least partly answer your questions 🙂

They are static, because you should never need to access self inside them.


In case of reduce, it's also in the article:

Some of the states have associated values in order to draw them on the UI or to pass to the next state. Similarly, events carry data, which is the only source of information when we produce a new state inside a reduce() function.

In essence, the associated values of State and Event must be enough for you to determine the next state.


In case of feedbacks, either the State should be enough, or dependencies should be passed in as parameters.

However, the author conveniently hardcoded MoviesAPI inside the feedbacks and basically threw any notion of testability straight out the window...
Instead, that dependency must be injected.

The only question is, should it come with the State or should it be a parameter to the feedback function (ex: static func whenLoading(moviesApi: MoviesApi) -> Feedback<State, Event>).
I'm leaning more towards the 2nd approach of passing it as a parameter to the function.

from modernmvvm.

JonnyBeeGod avatar JonnyBeeGod commented on May 26, 2024

While I'm not the author of the article, I can at least partly answer your questions 🙂

They are static, because you should never need to access self inside them.

In case of reduce, it's also in the article:

Some of the states have associated values in order to draw them on the UI or to pass to the next state. Similarly, events carry data, which is the only source of information when we produce a new state inside a reduce() function.

In essence, the associated values of State and Event must be enough for you to determine the next state.

In case of feedbacks, either the State should be enough, or dependencies should be passed in as parameters.

However, the author conveniently hardcoded MoviesAPI inside the feedbacks and basically threw any notion of testability straight out the window...
Instead, that dependency must be injected.

The only question is, should it come with the State or should it be a parameter to the feedback function (ex: static func whenLoading(moviesApi: MoviesApi) -> Feedback<State, Event>).
I'm leaning more towards the 2nd approach of passing it as a parameter to the function.

Makes sense. I am wondering whether you have figured out a way of making conditional presentation of modal views work with this approach. Since this would require to somehow set a Binding in the View based on the state of the viewModel and this does not work in the body func. Subscribing to state in init also does not work since this is an escaping func. Just wondering

from modernmvvm.

Related Issues (9)

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.