Hi,
I try to understand the view model and binding procedure in Octoprint (please note that I´m quite noobish with JavaScript) while I´m coding my own plugin, but I know view models from Qt and they act as a translation part between a UI and a logic part. I assume that JavaScript will use them in the same way.
I read this document for a basic understanding, but I don´t understand it very well.
Let´s assume that my plugin uses the following configuration (I think this configuration isn´t that good, because it´s mine...):
OCTOPRINT_VIEWMODELS.push({
construct: SpoolscaleViewModel,
dependencies: [ "settingsViewModel", "navigationViewModel" ],
elements: [ "#navbar_plugin_SpoolScale", "#settings_plugin_SpoolScale" ]
});
The first part (construct
) is for the construction of my view model. This is clear and without any issues.
The next parts (dependencies
and elements
) are a little bit unclear for me. The docs write:
"List of dependencies the view model needs injected"
What does this mean? As I know it Octoprint uses a lot of predefined view models and my model injects the listed models. Does it mean that each of the listed models will receive the methods and variables from my model (i. e. the function "tare")?
And what is the difference between the view model and the element? From my point of view, I bind automatically to the navbar when I bind to the navigation model because the navigation model is responsible for the navigation bar. The same scenario is used in the following code:
What are the idea of using the settingsViewModel
in the dependencies
field and the settings_plugin
in the elements
field?
And what does the error
Could not bind view model SpoolscaleViewModel to target #navbar_plugin_SpoolScale : Error: You cannot apply bindings multiple times to the same element.
from my model mean? How do I bind my view model to the same element in multiple ways?