-
Notifications
You must be signed in to change notification settings - Fork 104
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
Scope Isolation #355
Comments
For this use case we have the possibility to define a name (as String). Each time you open the view you have to define a unique name. |
There are two issues I see with the name approach. @InjectScope("coolId2") ScopeStorage.get(TestScope.class, "cooldId2"); Perhaps when loading a detail view, you could offer an api which references the master view (which in turn could share it's scope object)? eg. FluentViewLoader.fxmlView(View.class,parentViewInstance).load(); |
An even simpler design would be: MyScope myScope = new MyScope();
FluentViewLoader.fxmlView(MasterView.class).scope(myScope).load();
FluentViewLoader.fxmlView(DetailView.class).scope(myScope).load(); "myScope" can then be injected directly into any ViewModels. |
Any other thoughts on this :) |
Sorry for the late response. Your second proposal with the scope instances beeing passed to the FluentViewLoader looks nice. class MasterViewModel implements ViewModel {
@InjectScope
private MyScope scope;
....
}
class SomeOtherViewModel implements ViewModel {
@InjectScope
private MyScope scope;
} The code looks like there is the same global scope instance injected in both classes. However due to the fact that you passed an existing scope instance to the FluentViewLoader for Another issue: |
Concerning included views: |
@sideisra - I like that idea :) I was also thinking that the scope could be a node property on the parent that is accessible from the child view - similar idea to the threadlocal - just a different storage location (traversable from the child by the loader). @lestard - I see where there might be confusion in reasoning about what happens. I think that confusion revolves around the current implementation treating scopes as singletons which is not the purpose of a scope (as far I understand scope). In addition, these scope objects will never get destroyed. If this was a web application, the scope would most likely be tied to a request/response. Since this is a desktop application, I think we need to control the lifecycle of the scope ourselves (similar to the lifecycle of the views themselves). |
I don't get how a ThreadLocal would be any help in this case? Typically all views are loaded in the same JavaFX UI-Thread which means that all views and viewModels would share the same instance of the ThreadLocal. Ok, first let's figure out what scopes is used for. The purpose of scopes is to share data and communicate between parts of the application (think viewModels) without a tight coupling between these components. To archive this we need to have a look at two aspects:
In some usecases a solution for these aspects would be to define the scope at loading time. Either by passing an existing instance of the scope to the However there are some situations where this wouldn't be sufficient.
We are loading the The first and hardest task for all of these problems is: How should the API look like for the developer? In The idea of the current scopes API is this: Another approach that we are thinking of is the following: But again: Many thanks for your suggestions. The current API for the scopes isn't finished but is a work-in-progress. We have added the API to see how it works and what problems are still there. Your feedback and suggestions are very welcome. |
I agree that the I think the isolation of two view hierachies loaded in two different FluentViewLoader runs should come first. For this, it would be sufficient to either pass an instance of the scope to the FluentViewLoader or to create a new instance at ervery run (or support both ;-)). The most important part here is that these scopes are isolated and each view hierachie can work with its own. |
Looking a little more closely at the current implementation, I think much of what we are looking for could be accomplished with a small change to the ScopeStore. It currently creates and holds a reference to a singleton (which never goes out of scope). Instead, it could be modified to instantiate a new ScopeStore with each FluentViewer#load (or series of calls if you want to share the ScopeStore between loads). The pattern would essentially be:
Here is how I see this working within the FluentLoader itself
|
I like your approach, maybe we should provide for this transactional scope creation an additional Scope type : interface TransactionalScope extends Scope to check during the instantiation of a scope that a transaction (ScopeStore.init()) was started. |
It would also be helpful if ScopeStore was a pluggable interface (much like dependency injector). |
We continue this discussion on: #383 |
If I have a master/detail views that are opened multiple times, how do I separate the scope instances for each?
The text was updated successfully, but these errors were encountered: