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

Make ReRx-enabled view controllers strictly pure #1

Open
svdo opened this issue Aug 27, 2017 · 2 comments
Open

Make ReRx-enabled view controllers strictly pure #1

svdo opened this issue Aug 27, 2017 · 2 comments

Comments

@svdo
Copy link
Owner

svdo commented Aug 27, 2017

When using react and redux, there is a module called react-redux that is the inspiration for ReRxSwift. Using that module allows you to cleanly separate stateful and pure components. I would like to make view controllers strictly pure as well, meaning that they have no explicit dependency on anything other than their props and actions. In the current form, this is broken by the requirement to have a connection property in your view controller, which needs the application store as one of its parameters.

ReRxSwift can only be implemented if your view controller has two additional properties: props and actions. The current implementation uses protocol extensions to reduce the requirement to one single connection property; props and actions are forwarded to the connection instance.

In general, properties can be added to classes by defining subclasses, or by using the Objective-C runtime in the form of associated objects. I don't like the subclass-route, because if ReRxSwift would provide a ViewController subclass that you have to use, you can no longer benefit from UITableViewController, UICollectionViewController, etc. And the Objective-C route is not desirable because it breaks Swift strong typing, and because I'm not convinced that it is very future-proof as a similar mechanism doesn't exist in Swift.

Do you have any ideas on how to improve this?

@egv
Copy link

egv commented Aug 28, 2017

Well, to separate things even more you can inject connection into view controllers using Swinject оr any other DI container. This will move initialization of connection with store and other things to some external class, leaving view controller without explicit dependency on store

@svdo
Copy link
Owner Author

svdo commented Aug 28, 2017

Indeed @egv, that's an option that I hadn't considered yet, thanks! At this moment I don't feel like including it in my framework, because I don't want to require the additional complexity of DI for people to use this, but I can definitely see cases where you would want to solve it that way.

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