Replies: 4 comments
-
For more background infos, please take a look at the latest blog post: The 1.5.4 has already extended view models with adding stores into the mix: |
Beta Was this translation helpful? Give feedback.
-
More input on the dialog example. What you can do right now, assuming you create the "add customer" dialog inside your customer view controller: createAddCustomerDialog() {
this.addCustomerDialog = Neo.create({
// configs
listeners: {
addCustomersFormSubmit: this.onAddCustomersFormSubmit
}
});
} Once the dialogs form is filled out and a user hits the "submit" button, you can fire a custom event, e.g. This works fine for non complex dialogs, but in case a dialog contains many views & logic it can be limiting (and moving too much logic into a view controller where it does not really fit in). |
Beta Was this translation helpful? Give feedback.
-
Torsten (@Dinkh) had the idea to add a parent config (reference) to vcs & vms. I got to admit that this one is growing on me. You could change the value inside your class & instance definitions: createAddCustomerDialog() {
this.addCustomerDialog = Neo.create({
// configs
model: {
// model configs
parent: this.getModel()
}
});
} For this approach, parentId needs to get an afterSet methods => When dynamically moving a component inside your apps component tree, the parent references can update their values. One benefit of this approach: accessing the parent chain is a bit faster. |
Beta Was this translation helpful? Give feedback.
-
the new parent logic resolves this discussion. i will create a new example app to show it in action. |
Beta Was this translation helpful? Give feedback.
-
Right now, each view model is bound to a component (storing the reference inside the owner config).
component.getModel()
will return the closest view model inside the parent component tree.To do this, we are accessing the
component.parentId
config. This config is also getting used for isolatedrender()
calls. While the config stores a component id most of the time, it could as well contain a DOM id for top level components.The parent id for a viewport is "document.body" by default, but you can as well render your apps into existing nodes of a not necessarily created by neo DOM structure (e.g. using a component like a web component inside a website / app).
For dialogs, the parentId config matches "document.body" by default as well, since most dialogs are supposed to be a floating overlay, not limiting drag&drop inside a parent container.
However, most dialogs do have a "logical root".
Example: You create an admin module. Your customers view has its own view model and view controller. Now the customers view controller creates a "add customer" dialog. It would be nice if this dialog could access the customers view model (as well as the parent model chain).
From a technical perspective, we need a new component config to make this happen.
E.g.
contextParentId
orcontextParentComponentId
(open for naming suggestions!)This config should default to the parentId config, but you can assign different values inside your class or instance definitions.
The second use case are multi window apps. Imagine two browser windows, each containing a MainContainer (Viewport). In case one of these two apps is supposed to be the "main" app, the MainContainer of the "child" app could use
contextParentId
to point to the MainContainer of the "main" app.The result is that both apps share a top level view model (data & stores), which can be helpful for multi window state management.
What are your thoughts on this one?
Best regards,
Tobias
Beta Was this translation helpful? Give feedback.
All reactions