Skip to content

Instantly share code, notes, and snippets.

@BrianGenisio
Created November 25, 2012 17:41
Show Gist options
  • Save BrianGenisio/4144503 to your computer and use it in GitHub Desktop.
Save BrianGenisio/4144503 to your computer and use it in GitHub Desktop.
Backbone.rsync.js usage. Request for comments.
public class QuestionHub : BackboneModelHub<Question>
{
private static readonly List<Question> questions = new List<Question>();
protected override Question CreateModel(Question question)
{
question.Id = Guid.NewGuid();
questions.Add(question);
return question;
}
protected override Question UpdateModel(Question model)
{
var location = questions.FindIndex(q => q.Id == model.Id);
if (location < 0) return model;
questions[location] = model;
return model;
}
protected override Question FindModel(Question model)
{
return questions.Find(q => q.Id == model.Id);
}
protected override IEnumerable<Question> FindModels()
{
return questions;
}
protected override Question DeleteModel(Question model)
{
var existing = questions.Find(q => q.Id == model.Id);
if (existing == null) return null;
questions.Remove(existing);
return existing;
}
}
App.Collections.Questions = Backbone.Collection.extend({
model: App.Models.Question,
signalRHub: new Backbone.SignalR("questionHub"),
initialize: function() {
this.signalRHub.syncUpdates(this);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment