Slide 20
Slide 20 text
// socket.io example
var socket = io.connect(‘https://api.andbang.com’),
widgets = new WidgetCollection();
// handler for initial data payload
socket.on(‘initialData’, function (arrayOfWidgets) {
! // inflate your models structure
! widgets.add(arrayOfWidgets);
});
// change handler
socket.on(‘widgetUpdate’, function (payload) {
var widgetModel = widgets.get(payload.id);
if (widgetModel) {
widgetModel.set(payload.attributes);
}
});
Thursday, May 31, 12