Kevin Isom's avatar

Using and abusing YUI Models and ModelSync.Rest

I have been building some apps lately with the YUI App Framework a JavaScript MV* framework built with YUI. One of the enhancements of the Model is the ModelSync capabilities provided by the REST module. See the example below.

However it is simple enough to add additional url calls. By specifying the url property of the model. The sync module will take the model attributes and use Y.Lang.sub to process the url property. So what does that mean? Individual methods can set the url property and then make a request to retrieve the data at that endpoint.

Depending on your purposes and url configuration you will want to either set the url property to null after the load is complete or update the url to a default configuration

This also works with the ModelList as well so you can craft custom queries to retrieve data to populate the list.

Extending models and model lists this way is really simple and can help extend your application.I was really pleased to see that this just works out of the box and required no additional changes to the Sync layer.

The next post I’ll be doing on the YUI App Framework will be creating sub apps and modularizing your app to allow for greater composability and better maintenance.