Companion factories may be declared in any superclass of a given Mavericks ViewModel. Therefore, when recreating an instance of a ViewModel, we need to store the ViewModel class from the declaration site, instead of the resolved class. In cases where a companion factory was used, we can call the same one that was used to initially create the ViewModel. If a companion factory was not used, we can safely call the constructor of the original declaration site class as before.
In situations where the State class does not have a default constructor and must be provided via a companion factory, this behavior was leading to a crash. This adds a unit test to StateRestorationTest that covers one such scenario.
Companion factories may be declared in any superclass of a given Mavericks ViewModel. Therefore, when recreating an instance of a ViewModel, we need to store the ViewModel class from the declaration site, instead of the resolved class. In cases where a companion factory was used, we can call the same one that was used to initially create the ViewModel. If a companion factory was not used, we can safely call the constructor of the original declaration site class as before.
In situations where the State class does not have a default constructor and must be provided via a companion factory, this behavior was leading to a crash. This adds a unit test to
StateRestorationTest
that covers one such scenario.@BenSchwab