-
Notifications
You must be signed in to change notification settings - Fork 32
Callbacks before and after super call #36
Comments
Do you have a proposal for how this would be supported? |
The easiest solution would look like this. Two events for every lifecycle method, one before and one (the normal) after the NaviActivity @Override protected void onResume() {
base.onResumeBeforeSuper()
super.onResume();
base.onResume();
} NaviEmitter public void onResumeBeforeSuper() {
emitEvent(Event.RESUME_BEFORE_SUPER);
} Possible problemsThe ALL listener would run into problems. It's not possible to distinguish between the before and after events. //cc #30 |
That's the easy part, I meant more about how to modify the interface such that it doesn't make things a lot more complicated. |
Not sure if I got this question correct. But the ALL listener requires this interface as proposed in #30. public interface AllListener<T> {
void call(Event<T> event, T data);
} |
Oh, so you mean a whole second set of events for before. Hmm... I'll have to think about it. |
An alternative solution would be to allow you to specify it when adding the event, aka: <T> void addListener(Event<T> event, Listener<T> listener, boolean beforeSuper); Then the event list would remain the same. Adding a new parameter would make the API slightly more complex but maybe it's worth it for this flexibility. |
All events I can think of have a super call. So, the optional |
The more I think about this, the more I like it. Right now we're actually mixing when we call I think requiring the specification of before/after super will make the API more flexible and more clear, since you don't have to wonder when it's being called in the lifecycle. |
Any news on this? |
When I have spare time I'll be playing around with this more. I've got it half-baked over here. |
In my experience, all of the work in the destruction callbacks is usually done before the super call while the work in the creation callbacks is usually done after the super call. This is backed at least by this SO answer: http://stackoverflow.com/a/9626268/615306. I think Navi should do the same, no need for extra parameters and duplicate events. |
Yeah, I think that's reasonable, as long as it's better documented. The more I played around with the extra parameter, the more I got annoyed with it. It's just a lot of hassle for a corner case. |
Calling the initializer I'm really hoping navi will be general enough to get callbacks for both. |
I thought you just needed to call |
Libraries like Flow execute code before the
super
call. This is currently not supported by navi.The text was updated successfully, but these errors were encountered: