Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BackboneFirebase example
// Create a new instance of the Rooms collections
FireDrop.Rooms = new FireDrop.collections.Rooms();
// Fetch the initial data from Firebase
FireDrop.Rooms.fetch({ success: function (response) {
// Keep this collection in sync with Firebase.
// You could save this as a property on the collection for later access.
new BackboneFirebase(FireDrop.Rooms);
// Create a view for each model and append it to the list.
FireDrop.Rooms.each(function(room) {
// Only create the view if the model doesn't already have one.
if (!room.listItemView) {
new FireDrop.views.roomListItem({
model: room
});
}
// Not included in this gist but it's just a jQuery object.
$roomList.append(room.listItemView.render().el);
});
}});
// If a model is added to the list remotely create a view for it
FireDrop.Rooms.bind('add', function(room) {
if (!room.listItemView) {
new FireDrop.views.roomListItem({
model: room
});
}
$roomList.append(room.listItemView.render().el);
});
// If a model is removed from the list remotely remove the view
FireDrop.Rooms.bind('remove', function(room) {
if (room.listItemView) room.listItemView.remove();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.