#1 2020-11-12 14:10:51

Javierus
Member
Registered: 2019-09-18
Posts: 55

mORMot and the MVVM pattern

Reading the documentation, it talks about MVC and MVVM
Implementing MVC with mORMot services seems clear
But... MVVM? As I understand it, MVVM is heavily based on binding properties from the View to the VM. That means any change on a View property must be transferred to the VM. And also de opposite: any change on the VM must be transferred to the View
I can not see how it can be done

Is there any example somewhere?

Thanks

Offline

#2 2020-11-13 10:45:25

Javierus
Member
Registered: 2019-09-18
Posts: 55

Re: mORMot and the MVVM pattern

@ab ?

Is for real the MVVM in the documentation, or a typo?

Offline

#3 2020-11-13 11:26:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: mORMot and the MVVM pattern

The ViewModel is the Controller of mORMotMVC.pas.
In practice, the difference between MVC and MVVM is more about marketing and actual implementation details than a real design disruption.
Both MVC and MVVM are meant to separate the Model and View, using a third item, which is called a Controller or a ViewModel.
MVVM is a way of implementing MVC.

In mORMotMVC.pas, this VM/C is in fact an interface type, which defines the interaction between the model and the view.
Changes between the View and the VM/C interface is just to be reflected by changing the output parameters of its methods. Pretty simple.

Offline

#4 2020-11-16 15:14:24

Javierus
Member
Registered: 2019-09-18
Posts: 55

Re: mORMot and the MVVM pattern

ab wrote:

the difference between MVC and MVVM is more about marketing and actual implementation details than a real design disruption.

I don't understand sad

IMHO, MVVM is not the same as MVC;  for what I'm learning, MVVM gives a bigger decoupling than MVC: The VM should know nothing about the View. The view should be linked to the VM only through property binding and parameterless actions

I believe that the difference exists; MVVM might have started from MVC or MVP, but they are not the same

Could you please help me a bit more, to understand how to use MVVM with mORMot?

Offline

#5 2020-11-16 17:16:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: mORMot and the MVVM pattern

In mORMot, you can see the interface and implementation class defining the Controller as the application ViewModel.
The VM doesn't know anything about the View, which may be a Mustache template, another service, or just JSON. It just outputs some information which will be rendered by the View.

Offline

#6 2020-11-16 18:41:42

Javierus
Member
Registered: 2019-09-18
Posts: 55

Re: mORMot and the MVVM pattern

But the problem is the input... In MVVM, the view is bound to properties on the VM, and that binding must be bidirectional, unless it's just a report or something as that, wich is not the MVVM target
The view is expected to be codeless or as near to it as possible, and to alter the VM just through binding (and actions to a lesser degree)

Offline

#7 2020-11-16 20:53:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: mORMot and the MVVM pattern

The Mustache View is codeless.

Feedback from the View to the VM is done by executing another method of the VM interface/class.

Please ensure that you found out how mORMot Web works.

Offline

Board footer

Powered by FluxBB