Data management with long-living controllers


#1

Hi all,

Because controllers live much longer in Ionic, the challenge seems to be to keep them up to date - especially when they share data. I know that the ionic events for re-entering/leaving the controller could be used to trigger updates. Yet, this event pattern involves a lot of repetition and I don’t find it scales well.

The catch of my setup is the following:

  • Some of the controllers share the same data. The data can change depending on user interaction.
  • Sometimes controller A modifies the data, which means that controller B has to update dependencies to avoid stale data.

Non-solutions / solutions / ideas

  1. Using services that return promises does not work, because once they are resolved the cannot be retriggered.
  2. Observer-like pattern: controller listens to certain system events and defines a callback that is executed when event occurs.
  3. Destroy controllers and avoid having long-living controllers at all, controllers always fetch new/cached data when instantiated.

Does anyone have experience, ideas, suggestions, corrections how to tackle this problem?
If there are any questions, please do not hesitate to ask.

Thanks!
Ben