square / flow

Name UI states, navigate between them, remember where you've been.
Apache License 2.0
2.79k stars 241 forks source link

Getting to the flow instance from the dispatcher can be awkward #254

Open rjrjr opened 7 years ago

rjrjr commented 7 years ago

Interesting dispatchers redirect, which means that they need access to the Flow instance. That actually be tricky to get, since the only public API is via the Context, and who says that the dispatcher is anywhere near there?

I wonder if we should include a back pointer to the Flow in Traversal? Or add a Flow parameter to the Dispatch method?

Zhuinden commented 7 years ago

Based on that note I added Backstack to my StateChange class which in your case is Flow being available via Traversal.

I think it makes sense.

dcow commented 7 years ago

I put stuff like redirects in a router that sits a little closer to the context and leave my dispatcher to more disptach-y things like making sure info about traversals for different types of keys gets pumped through the chain of routers and transitions get executed on the view controller corresponding to the type of key coming in. But not a bad idea. It would also be nice to have a formal api for a dispatcher to "observe but drop" a traversal. Perhaps a new method on the completion like ignore()? When a traversal is ignored it's not added to the history however the dispatcher may choose to say start an Intent. That way business logic can inform the dispatcher via flow they wish to go somewhere out of your app without pushing the activity reference all the way down to wherever that thing might be sitting.