1

In my limited understanding, one-way data binding could happen like the following:

On the back-end, I have a Node backend server. In that, I have a layer that communicates with the database (Model). I have a controller that exposes URIs that the frontend server can connect to (Controller).

On the front-end, I have a React frontend server (View). The frontend-server sends requests to the URI-s exposed by the backend server.

If the frontend server wants to get data from the backend, it sends GET requests to the URIs exposed by the server (Controller), the server fetches the data (Model), and sends it to the frontend server (View).

If the frontend server wants to post some data so it will be stored on the server, it sends some POST requests to the server, which in turn handles it and saves the corresponding data.

I read that one-way data binding is basically an observer relationship between the view and the model. The view registers a callback with the model, and when something changes on the backend, the model will call the callback, and it will update things in the view. But why is this necessary, if you can just send and receive data using the URIs exposed by the controller? Is this forced by React? Obviously I'm wrong about something, but for me it seems like its counter-productive because it creates tight coupling without using the Controller, that would behave as an interface between View and the Model.

1
  • 1
    Data binding doesn't happen over the network, but locally. The controller would return a response, and then the client would store that data somewhere (and augment it with some view-specific data). Then you'd somehow manipulate that data on the client; you may want this to cause the user interface to update (maybe there are multiple views of the data, or maybe manipulating it enables/disables part of the UI, or whatever). A data binding mechanism can be used to update the state of the views. Again, this is all happening on the client and has nothing to do with the server-side controller. Jan 7 at 20:32
2

But why is [one-way data binding] necessary, if you can just send and receive data using the URIs exposed by the controller?

It can be necessary if you need to provide live updates in your view of data that is modified by other sources.

For example, you are building an application to track how many available emergency-care beds are available in a particular geographical area. One of the views of that application is a dashboard that gets shown on a big screen.

That dashboard should show up-to-date information, but there is no human sitting next to it to refresh the screen and having it periodically poll the backend for updates might also be undesirable. That is where data binding and notifications from the Model are useful to refresh the dashboard exactly at the moment that the information changes.

This creates some coupling between the View and the Model, but that is entirely acceptable. In the MVC pattern, the View is allowed to know about the Model (and to have read-only access to it), as long as the Model doesn't know more than that "somebody" is interested in receiving change notifications.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.