Mortar-Flow-Dagger2-demo icon indicating copy to clipboard operation
Mortar-Flow-Dagger2-demo copied to clipboard

Scope name collisions will create weird bevavior/issues, hard to debug

Open Lakedaemon opened this issue 9 years ago • 1 comments

The way used to name scopes will create awfull issues (hard to understand/debug) :

You shouldn't use the class name for scopes like this :

@Override public Context setUpContext(Path path, Context parentContext) { MortarScope scope = screenScoper.getScreenScope(parentContext, path.getClass().getName(), path); return new TearDownContext(parentContext, scope); }

It took me 1 week to understand that this was causing all the problems I had in my app. See there : https://github.com/square/mortar/issues/163

This is related to https://github.com/square/mortar/issues/149 And a fix was suggested upstream there : https://github.com/square/mortar/pull/161

Lakedaemon avatar Jun 23 '15 12:06 Lakedaemon

This is a very simple example where each screen is unique in the scope graph, and thus the class name is fine as naming policy.

The screen adapter for the view pager use another policy for scope naming, in order to avoid collision: https://github.com/lukaspili/Mortar-Flow-Dagger2-demo/blob/master/app/src/main/java/com/lukaspili/mortardemo/app/adapter/SlidePagerAdapter.java

Also, you may want to check my lib Mortar-architect, which is a kind of replacement of Flow. I use there a ScopeNamer that tracks names of scopes, and ensures they are unique, while still being saved & restored in order to survive process kill: https://github.com/lukaspili/Mortar-architect/blob/master/architect/src/main/java/architect/ScopeNamer.java

lukaspili avatar Jun 23 '15 14:06 lukaspili