Explaining “The ViewModel does not require a root object” warning
No edit summary
(Automatically adding template at the end of the page.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
ViewModels can either take their starting point in an Object you provide as a root or not. If they do they typically make use of that object – something like this:
ViewModels can either take their starting point in an object you provide as a root or not. If they do, they typically make use of that object – something like this:
[[File:Explaining -1.png|none|frame]]
[[File:Explaining -1.png|none|frame]]


The assigned root object is accessed with “self” on the green Root ViewModel class above.
The assigned root object is accessed with “self” on the green Root ViewModel class above.


But a ViewModel may also be constructed as not having the need for a root object – this is the typical case for Seekers or Browsers that look thru everything in class. The Browser pattern is very common for managing small value stores. Like this:
However, a ViewModel may also be constructed without needing a root object. This is the typical case for Seekers or Browsers that look through everything in Class. The Browser pattern is very common for managing small value stores. Like this:
[[File:Explaining -2.png|none|frame]]
[[File:Explaining -2.png|none|frame]]


When using this pattern you do not use “self” in the Root-ViewModel-class.
When using this pattern, you do not use “self” in the Root ViewModel class.


Since both these scenarios are legit it easy to imagine situations where you “forget” the intention of a ViewModel – was it Rooted or was it not?
Since both these scenarios are legit, it is easy to imagine situations where you “forget” the intention of a ViewModel – was it Rooted, or was it not?


If it was intended to be rooted, the action bringing the viewmodel up really should supply a root object like this:
If it was intended to be rooted, the action bringing the ViewModel up should supply a root object like this:
[[File:Explaining - 3.png|none|frame]]
[[File:Explaining - 3.png|none|frame]]


But if it was not intended to be rooted – as in the ViewAllThings case – then it would be no point in submitting a RootObject from the action:
But if it was not intended to be rooted – as in the ViewAllThings case – then there would be no point in submitting a RootObject from the action:
[[File:Explaining - 4.png|none|frame]]
[[File:Explaining - 4.png|none|frame]]


To clarify your intentions it is good style to check the “Requires root”-checkbox:
To clarify your intentions, it is a good style to check the “Requires root”-checkbox:
[[File:Explaining - 5.png|none|frame]]
[[File:Explaining - 5.png|none|frame]]


Because if you make your intensions clear this way the environment can help you to make sure that you follow thru.
If you make your intentions clear this way, the environment can help you ensure you follow through.


When you have a ViewModel that RequiresRoot but you have an action that does not supply a RootObject you get a Warning:<blockquote>''“WARNING: If the ViewModel requires a root object [RequiresRootObject on ViewModel] you should not have it empty ViewOneThing”''</blockquote>And if you have a ViewModel that does not Require a Root but an action submits a RootObject you get another warning:<blockquote>''“WARNING: The ViewModel does not require a root object [RequiresRootObject on ViewModel] but there is a Expression in ViewModelRootObjectExpressionViewOneThing”''</blockquote>
When you have a ViewModel that RequiresRoot, but you have an action that does not supply a RootObject you get a warning: <blockquote>''“WARNING: If the ViewModel requires a root object [RequiresRootObject on ViewModel] you should not have it empty ViewOneThing”''</blockquote>And if you have a ViewModel that does not Require a Root, but an action submits a RootObject you get another warning:<blockquote>''“WARNING: The ViewModel does not require a root object [RequiresRootObject on ViewModel] but there is a Expression in ViewModelRootObjectExpressionViewOneThing”''</blockquote>
[[Category:View Model]]
[[Category:View Model]]
{{Edited|July|12|2024}}

Latest revision as of 15:34, 10 February 2024

ViewModels can either take their starting point in an object you provide as a root or not. If they do, they typically make use of that object – something like this:

Explaining -1.png

The assigned root object is accessed with “self” on the green Root ViewModel class above.

However, a ViewModel may also be constructed without needing a root object. This is the typical case for Seekers or Browsers that look through everything in Class. The Browser pattern is very common for managing small value stores. Like this:

Explaining -2.png

When using this pattern, you do not use “self” in the Root ViewModel class.

Since both these scenarios are legit, it is easy to imagine situations where you “forget” the intention of a ViewModel – was it Rooted, or was it not?

If it was intended to be rooted, the action bringing the ViewModel up should supply a root object like this:

Explaining - 3.png

But if it was not intended to be rooted – as in the ViewAllThings case – then there would be no point in submitting a RootObject from the action:

Explaining - 4.png

To clarify your intentions, it is a good style to check the “Requires root”-checkbox:

Explaining - 5.png

If you make your intentions clear this way, the environment can help you ensure you follow through.

When you have a ViewModel that RequiresRoot, but you have an action that does not supply a RootObject – you get a warning:

“WARNING: If the ViewModel requires a root object [RequiresRootObject on ViewModel] you should not have it empty ViewOneThing”

And if you have a ViewModel that does not Require a Root, but an action submits a RootObject – you get another warning:

“WARNING: The ViewModel does not require a root object [RequiresRootObject on ViewModel] but there is a Expression in ViewModelRootObjectExpressionViewOneThing”

This page was edited 93 days ago on 02/10/2024. What links here