mvvmFX icon indicating copy to clipboard operation
mvvmFX copied to clipboard

Support SceneLifecycle for Java based Views

Open manuel-mauky opened this issue 7 years ago • 4 comments

With #381 we introduced a basic lifecycle concept for ViewModels. At the moment this is only available for ViewModels that belong to a FXML-based view. With this issue the same feature should be implemented for Java-based views.

manuel-mauky avatar Feb 03 '17 17:02 manuel-mauky

Just throwing this as a comment, if one really needs to access a dispose/clean-up method in a View, wouldn't the following logic apply: (?)

  • ViewModel that implements SceneLifecycle has it's onViewRemoved() called;
  • in that method, the user implements the view model's cleanup, after that, he adds as a last line in that method the following: publish("Clean view");
  • in the View that implements that ViewModel, the user subscribes to that messages, and when it arrives, it triggers a private method designated by him, in which he performs the view's cleanup and finally unregisters the listener for that message;
  • thus, when the ViewModel has it's onViewRemoved() called, the View's own private method gets called by the use of publish/subscribe;

georgeVasiliu avatar Jan 05 '18 12:01 georgeVasiliu

Hi @georgeVasiliu thanks for your comment. Basically this is correct. It's a valid strategy for cleaning up the View if nessessary.

However, this aspect is not directly related to this issue here. It is not the goal to introduce a dispose/clean-up method in Views. Instead, the goal here is to enable clean-up via lifecycle listeners for ViewModels that belong to Non-FXML views. At the moment the SceneLifesycle only works for ViewModels that belong to an FXMLView, not JavaView. This is what needs to be implemented.

manuel-mauky avatar Jan 05 '18 12:01 manuel-mauky

Hello, thanks for the fast reply. I was not aware of the issue. I will dive and search a bit through the code and see if I can come up with any ideas. If I do, I will be sure to keep you updated.

On 5 Jan 2018 2:58 pm, "Manuel Mauky" [email protected] wrote:

Hi @georgeVasiliu https://github.com/georgevasiliu thanks for your comment. Basically this is correct. It's a valid strategy for cleaning up the View if nessessary.

However, this aspect is not directly related to this issue here. It is not the goal to introduce a dispose/clean-up method in Views. Instead, the goal here is to enable clean-up via lifecycle listeners for ViewModels that belong to Non-FXML views. At the moment the SceneLifesycle only works for ViewModels that belong to an FXMLView, not JavaView. This is what needs to be implemented.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sialcasa/mvvmFX/issues/470#issuecomment-355548846, or mute the thread https://github.com/notifications/unsubscribe-auth/AZXnMbyN5bXx0D5qEvZr62r5VpS6K1Osks5tHhxXgaJpZM4L2lOz .

georgeVasiliu avatar Jan 05 '18 13:01 georgeVasiliu

I'm happy to review Pull-Requests for this. For the topic of your initial comment, we have a separate issue that intends to introduce a lifecycle method for View classes here: #471 I think both approaches are valid. Using a lifecycle in Views or use the publish/subscribe mechanism that you've described.

manuel-mauky avatar Jan 05 '18 13:01 manuel-mauky