Search code examples
modelsynchronizationyui

YUI, sync many objects


I am evaluating YUI's model syncing framework. If I understand correctly, it is designed so that each model synchronizes with server by itself.

In my case, though, I'll probably have up to a hundred of distinct objects of different types (it's a complex web application). I don't want to spawn 100 distinct requests to retrieve their data one by one—I'd like to be able to aggregate requests and send them in a single request to save time and bandwidth.

How should I design my code to make this possible with YUI models?


Solution

  • Implement a sync for ModelList, rather than Model.

    You might want to take a look at the example "GitHub Contributors" app, which can load data representing multiple GitHub repos in a single call. Or look at the code for the more generic ModelSync.REST object, which can load data for multiple Models using a single request from a ModelList. In fact, if you're talking to a REST API, you might be able to use ModelSync.REST as-is.