Vector icon indicating copy to clipboard operation
Vector copied to clipboard

Add the ability to handle global state changes

Open haroldadmin opened this issue 5 years ago • 0 comments

Is your feature request related to a problem? Please describe. There are several pieces of state in an app that need to be accessed globally, such as a user's auth status. Additionally, there are also some events that can be dispatched from anywhere in the app to affect this global state, for example an auth token expiration triggering a logout.

These events are not a part of a single screen's state, but rather the global state, but Vector currently does not do anything to help handle these cases.

Describe the solution you'd like

  • Implement a global state store alongside the existing state-stores for each screen. This global state store should be accessible everywhere, without having to use a ViewModel for it.

  • Add support for dispatching actions to this state store, so that any part of an app can send events to it.

  • Add ability to observe this state-changes in this store.

  • Maybe look into the ability to have multiple global state stores, such as one for Navigation, another for Authentication, etc? This effect can also be achieved by using a generic single state-store containing all different state classes as children of a parent sealed class.

Describe alternatives you've considered An alternative to this would be to use an activity scoped ViewModel with multiple Fragments and share this ViewModel between them. This effectively leads to a global state store for all these fragments. While this solution will work well for single activity apps, it doesn't work when multiple activities are involved.

haroldadmin avatar Jan 29 '20 04:01 haroldadmin