O'Reilly logo

SproutCore Web Application Development by Tyler Keating

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Observing properties for instant updates

While writing an application, you occasionally want to do some action "X" whenever some change "Y" occurs. Traditionally, you may have created a helper function that you would call each time you performed a change. For example, this might result in code that looks something like the following:

MyApp.Item = SC.Object.extend({ quantity: 0, updateServer: function () { // Sends the new information to the server. } }); // Elsewhere in the code … var item = MyApp.Item.create(); item.set('quantity', 100); // Elsewhere in the code at a later date ... item.updateServer(); // Oops.. missed this. Don't forget to update the server! // Elsewhere in the code … item.decrementProperty('quantity'); // Elsewhere in the code ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required