cardoso / ReduxMovieDB

🎥 See the upcoming movies! ReSwift + RxSwift 💖 Hacktoberfest 🎃

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about ViewState instantiation

ranhsd opened this issue · comments

Hi @cardoso , Really like this example... Good job!

I only have one question. I noticed that you created ViewState objects which receive the main state and return the state for the specific view. I tried to test your app and noticed that the ViewState objects (for example: MovieListViewState) init function is being called several times. Actually it is being called when any action is being dispatched and I don't know if it is a best practice.

Did you noticed that while developing this example?

BTW! I tried to integrate skipRepeats into your project by implementing the Equatable protocol but its still calling the init function a lot of times

Hi @ranhsd !

When an action is dispatched, it rebuilds the entire state of the application and triggers a re-render of all views. This is intrinsic to the redux pattern.

In case it becomes a burden for performance, it's possible to implement workarounds such as skipRepeats or decide whether or not to re-render a view inside the newState(state:) method.

This is a challenge faced in web development as well: https://stackoverflow.com/questions/41763031/how-to-prevent-react-from-re-rendering-the-whole-component

Hi @cardoso you're right. But in ReSwift you have the ability to skipRepeats and in your it is not implemented.

@ranhsd I can take a look into implementing it in the weekend.

But if you can submit a PR, I'll be happy to merge it. :)

Thanks for the suggestion!

Hi,
since ReSwift 4.0.1 skipRepeats is on by default when the SubStates are Equatable. After doing this, I tested it and newState for MovieList and MovieDetail is called a few times less. So I hope it's fine, if I add a PR to make the two ViewStates Equatable.

@cardoso Should this issue stay open or can it be closed?

Closed. Thanks @fbernutz