Comments (2)
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.
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 accessself
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
andEvent
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)
- return state from .submitting state doesn't work
- Management of global objects HOT 1
- Assign to self causes retain cycle HOT 4
- Publishers.system signature changed - feedbacks type changed HOT 1
- Parallel states
- Demo App Crashes on Scrolling HOT 2
- @StateObject for ViewModels instead of @ObservedObject
- What does this userInput() do? 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 modernmvvm.