Three-way binding versus two-way binding

We have different kinds of bindings. AngularJS made the two-way binding famous. This entails being able to change data from two different directions:

  • A change in the view changes data on the controller
  • A change on the controller is reflected in the view

As for three-way binding, what do we mean? Let's illustrate this with an app; it's best described through an image:

What you need to imagine here is that we developed an application that uses Firebase. We are launching said application in two different browser windows. In the first window, we make a change that is being reflected in the second browser window, for example, adding an item to a list. So, what steps take place?

What we see here is best read from right to left:

  • Instance one: user changes a view
  • Instance one: change propagates to the model
  • This triggers synchronisation with the Firebase database instance
  • The second instance is listening to the synchronisation
  • The model for the second instance is being updated
  • The view for the second instance is being updated

There you have it: change in one place, and see the results in two or more instances depending on how many instances you have spawned.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset