Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialization Differences between JavaViewLoader and FxmlViewLoader #356

Closed
gtnarg opened this issue Jan 27, 2016 · 4 comments
Closed

Initialization Differences between JavaViewLoader and FxmlViewLoader #356

gtnarg opened this issue Jan 27, 2016 · 4 comments

Comments

@gtnarg
Copy link

gtnarg commented Jan 27, 2016

The following results in the initialize method being called on the ViewModel:

FluentViewLoader
    .javaView(MyJavaView.class)
    .viewModel(myJavaViewModel)
    .load();

The initialize method is NOT called for the following:

FluentViewLoader
    .fxmlView(MyFxmlView.class)
    .viewModel(myFxmlViewModel)
    .load();

Is this inconsistency intended?

Thanks

@manuel-mauky
Copy link
Collaborator

No, this is a bug. We have already an eye on this issue but it's not totally clear what the expected/best behaviour is. Should we call the initialize method on the viewModel or not? There are arguments for both. See issues #343 and #314

We had the plan to fix this inconsitency with 1.4.1 but have decided to delay the fix for more discussion about the desired behaviour.

At the moment I think the best would be to not initialize the viewModel when an existing instance is provided via the FluentViewLoader. The reason for this is that one of the use cases of this method is to reuse ViewModel instances for multiple views. In this case you don't want to re-initialize it multiple times.
This means that we should disable the initialization for the JavaViews in your Example.

What do you think about this? What is your use case?

@gtnarg
Copy link
Author

gtnarg commented Jan 27, 2016

I'm injecting the view so that I can provide my own scope instance (see issue #355).

If the framework doesn't call it then I need to (just needs to be documented as such). I think it's reasonable to expect that if you are providing the ViewModel instance then you are responsible for initializing it.

Ultimately, the behaviour should be consistent between the two loaders.

@manuel-mauky
Copy link
Collaborator

You are totally right. It should be consistent and documented. We will fix that

@manuel-mauky
Copy link
Collaborator

This issue is fixed with version 1.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants