Created
November 25, 2012 17:41
-
-
Save BrianGenisio/4144503 to your computer and use it in GitHub Desktop.
Backbone.rsync.js usage. Request for comments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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