You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Watch an object and it's properties for changes, including nested properties.
Install
component install ripplejs/model
Example
varmodel=require('model');// Creates a new model contructorvarViewModel=model();// Create a new view-model object with these propertiesvarmodel=newViewModel{firstname: "Tom",lastname: "Dickson",items: [1,2,3],data: {height: '175cm'}});// Watch arrays for items added, removed or sortedmodel.change('items',function(){console.log('array changed');});// Watch computed properties for changesmodel.change('fullname',function(val){console.log(val);});// Watch nested properties for changesmodel.change('data.height',function(){console.log('height changed');});// Values must be changed with #setmodel.set('firstname','Richard');// Get nested propertiesmodel.get('data.height');// '175cm'// Get computed propertiesmodel.get('fullname');// 'Richard Dickson'// Arrays can be used as normalmodel.get('items').push(4);// 'array changed'
About
Watch an object and all of it's properties for changes