-
Notifications
You must be signed in to change notification settings - Fork 81
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
[wip] Allow safe handling of Routable calls #59
Conversation
Codecov Report
@@ Coverage Diff @@
## master #59 +/- ##
==========================================
- Coverage 80.38% 71.31% -9.08%
==========================================
Files 5 5
Lines 209 244 +35
==========================================
+ Hits 168 174 +6
- Misses 41 70 +29
Continue to review full report at Codecov.
|
@Ben-G I've just rebased this branch. Could you take a look and see whether anything has been accidentally clobbered? |
@mattdelves I'm curious to understand why the following happens:
Crashing in that case seems appropriate, as the declared route and the actual route no longer match up; a situation from which the router probably cannot recover. Really this shouldn't happen in the first place so I would be interested in finding and hopefully fixing the root cause. |
@Ben-G yeah, completely agree that the best solution is to look for why we are ending up with a route that isn't achievable. Unfortunately, the situation in which our app is in means that that isn't always easy to find out. The desired outcome here is preventing a state that results in a crash. This should be achievable by the changes above and the use of a middleware written in the app. Hope that clears up why we're wanting to make use of this change. |
@mattdelves While I definitely understand how this is causing issues in your app, I don't think we should change the router API based on that. The hard failure via That said; it seems like you should be able to implement the ideas from this PR via |
@Ben-G those are some good points. Unfortunately even when implementing the middleware component in the app we had to commit some rather heinous crimes with regard to the code. As such, since this is likely not something that'll be part of the API, I'm going to close the pr. |
The problem encountered
Rather unfortunately our app gets itself into a state whereby we try to perform a
push
,pop
orchange
action on a route that isn't supported by a routable. This often results infatalError
being called and the app crashing.A possible solution
This is an idea / attempt at fixing the problem though is unfortunately incomplete. By calling a function defined on the routable before calling
push
,pop
orchange
we can check whether the action will in fact work. This is a much more desirable result than afatalError
.Unfortunately by having the check in the
Router
which is a store subscriber, it occurs after the navigation state has been updated. This means that we prevent the call resulting in fatalError but we have a state that is not reflective of where the app is.As such, there's a need to also have a ReSwift Middleware written in the app in order to check whether we can navigate to a route before the state is changed.
A call for help / suggestions
It would be great to get some discussion and input happening around this change. I'm not 100% sure what the best approach here in fact is.