What is difference between two way data binding and reactivity?

All we need is an easy explanation of the problem, so here it is.

As i follow some tuts for angular and ember.js I came across the term Two way data binding. Where data displayed on UI are bind with database and any changes to one is quickly propagated to the other. When I started learning meteor.js i came across term “Reactivity” which for me makes same sense as two way data binding. Can you please tell me fundamental difference between these two terms?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Reactivity is in fact more general than data binding. With reactivity you can implement data binding, in a really simple way, e.g.

var myAwesomeData = "some data";
var myAwseomeDependency = new Tracker.Dependency();    

var getData = function () {
  myAwesomeDependency.depend();
  return myAwesomeData;
};

var setData = function(value) {
  if (value !== myAwesomeData) {
    myAwesomeData = value;
    myAwesomeDependency.changed();
  }
}

Now, every time the getData routine is called within a computation, so basically within Tracker.autorun environment, it gets recomputed. By default the meteor’s collection API is implemented to be reactive, so every time fetch some data from you’r database you can be sure that it gets updated as soon as the data changes.

Also note, that you can use the above reactivity pattern without any database or values, so for example you can trigger and monitor events, states and so on.

Method 2

This Wikipedia Article will help you:
http://en.wikipedia.org/wiki/Reactive_programming

It basically says, that changes of data in specific dataLayers are automatically propagated. This paradigm seems to be the generic term and each framework with databinding / two way databinding is building on it and gives their technique a different name.

Method 3

My understanding is that two-way data binding is a form of reactive programming. Reactive simply means that a flow of changes in your data drives action. Whether the change comes from both the DOM and the data in your application or just one of those, does not really matter.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply