Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use a state on recursive screens? #499

Closed
toomozoo opened this issue Dec 9, 2022 · 4 comments
Closed

How to use a state on recursive screens? #499

toomozoo opened this issue Dec 9, 2022 · 4 comments

Comments

@toomozoo
Copy link

toomozoo commented Dec 9, 2022

For example, when you have UserState in ViewControler that displays a user and posts, what is the best practice to do?

  • UserViewController -> UserViewController -> UserViewController...
  • UserViewController -> PostViewController -> UserViewController -> PostViewController...
struct UserState: Equatable {
    var user: User
    var posts: [Post] = []
}

Can I implement something like below?

struct AppState: Equatable {
    // var user = UserState()
    var users: [UserState] = []
}

I am new to ReSwift and would appreciate any advice you could give me 🙇

@DivineDominion
Copy link
Contributor

DivineDominion commented Dec 9, 2022

That sounds about right to get started!

You can find similar ideas expressed in discussions about the old Router:
https://github.com/ReSwift/ReSwift-Router

To mix [UserVC,PostVC,ImageVC,UserVC,UserVC] in a stack, you might need an enum or express the commonality in a similar way

@toomozoo
Copy link
Author

@DivineDominion

Thank you for your comment!
I checked ReSwift-Router but I could not figure out how to implement recursive way...
What you are saying is that I should refer to Route with parameters?

@DivineDominion
Copy link
Contributor

To be honest I'm not sure about which issue in particular it was, or if it was something that came up every now and then 🤔

https://github.com/ReSwift/ReSwift-Router/issues?q=is%3Aissue+is%3Aclosed+multiple

So each same controller's route would need some "identifier" that is unique to disambiguate.

Anything you find that can help other newcomers to ReSwift-Router in a position similar to yours, please consider taking notes and sharing the result in a PR for a readme or documentation example!

@DivineDominion
Copy link
Contributor

https://www.jessesquires.com/blog/2022/12/15/powerful-navigation-api/ Possibly useful to let UIKit's nav controller handle the diffing and map an array of states to UIViewControllers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants