-
Notifications
You must be signed in to change notification settings - Fork 77
Trigger an event when an object has reached the server #10
Comments
i made a small tweak in the code were the _parsemodels in collection initialises the key creation with callback from push i can trigger the event. Also the add and remove function can be given with succces callbacks for oncomplete notification in collection when models have been successfully been pushed. add: function(models, options) {
if(typeof options == "function"){
options = {
success : options
}
} else{
options = {
success : this.oncomplete
}
}
var parsed = this._parseModels(models,options);
for (var i = 0; i < parsed.length; i++) {
var model = parsed[i];
this.firebase.ref().child(model.id).set(model, function(err) {
if (!err) {
if(options.state == "key pushed")
var val = model.toJSON();
options.success(null, val);
} else {
options.success("Could not update model " + model.id, null);
}
});
}
// TODO: Implement options.success
} in the todo.js var TodoList = Backbone.Firebase.Collection.extend({
// Reference to this collection's model.
model: Todo,
// Save all of the todo items in a Firebase.
firebase: new Firebase("https://zml4aw5pc3n1zxm.firebaseio.com/"),
// Filter down the list of all todo items that are finished.
done: function() {
return this.filter(function(todo){ return todo.get('done'); });
},
// Filter down the list to only todo items that are still not finished.
remaining: function() {
return this.without.apply(this, this.done());
},
oncomplete: function(err,val) {
console.log(err,val);
}
}); is this what you intended? |
👍 It'd be awesome to reinstate the built-in Backbone events ( |
We'll add these in the upcoming refresh. They may behave slightly different for Backbone.Firebase.Collection vs Backbone.Collection since the meaning is a bit different for a real-time synced collection. We'll work this out. |
Still figuring out the best way to handle this. I'll post my thoughts here in a bit. |
@davideast chat me up and we can discuss. Probably the |
@davideast include me in that discussion. |
Closing this for now. See #133 for more information. There's going to be an architectural shift towards proper extending of Backbone Models and Collections. |
In some cases it might be useful to know when a particular model has been written to the server (as opposed to just locally), similar to the onComplete callback Firebase provides for push/set. We should expose this in Backfire through an appropriate event on the Collection/Model.
/cc @robv
The text was updated successfully, but these errors were encountered: