square / mortar

A simple library that makes it easy to pair thin views with dedicated controllers, isolated from most of the vagaries of the Activity life cycle.
Apache License 2.0
2.16k stars 155 forks source link

It's really difficult to tell if your scope is destroyed #168

Closed rjrjr closed 9 years ago

rjrjr commented 9 years ago

Lately we've been playing with a technique where Views sometimes need to behave differently if their scope is dead, but with the Mortar's recent service-container changes that's really difficult to discover. I think the crux of the problem is that when you call MortarScope#getScope(Context) on a context with a destroyed scope, you get its lowest ancestor that isn't destroyed.

That's the right behavior for services in general, where contexts are supposed to fallback to parents. So was it a mistake to treat MortarScope as just another service? Or if that seems okay, should we add a separate static MortarScope#isDestroyed(Context) that does no fallback?

rjrjr commented 9 years ago

Chatted offline, it seems fair to declare "when you call MortarScope#getScope(Context) on a context with a destroyed scope, you get its lowest ancestor that isn't destroyed" a flat out bug.

rjrjr commented 9 years ago

We fundamentally screwed up service lookup, making destroyed scope behavior ambiguous. Refining the contract s.t. trying to use any service provided by mortar throws an exception if the nearest scope is dead. Also hiding the fact that mortar itself is a system service, making that an implementation detail.

Effects of this:

rjrjr commented 9 years ago

Fixed