ThirtyInch icon indicating copy to clipboard operation
ThirtyInch copied to clipboard

new Observer API

Open passsy opened this issue 8 years ago • 0 comments

Our TiLifecycleObserver API is great an maybe the best feature of ThirtyInch. It allows everyone to add functionality to TiPresenters. We use it for our rx implementation and the proposed Renderer uses it, too.

Implementing a TiLifecycleObserver is hard because the callbacks has a state and a boolean indicating if the method was called before or after the state callback was called. Worst case scenario: You initialize things twice but only expected the initialization once.

Right now it is required to add a TiLifecycleObserver right after initializing the TiPresenter. If you add it later you won't receive previous emitted events. The TiLifecycleObserver also never receives the created event because there is no way to add the observer before getting it.

And without passing in the Presenter in the constructor it is impossible to know the current presenter state.

Also missing is a callback when the observer is added and removed from a presenter. Cleanup is currently hard/impossible.

TODOs

  • [ ] We should change the API in a way observers receive distinct events for pre- and post lifecycle callbacks.
  • [ ] When a observer is added it should receive all previous events to the current lifecycle state as if it was added in the beginning.
  • [ ] Add events when the observer was added to a presenter or got removed to cleanup resources
  • [ ] add getPresenter() to get the current presenter the observer is attached to and it's state
  • [ ] like now, call destructing events in reversed order to the constructing events

passsy avatar Jul 19 '17 14:07 passsy