The Meteor framework has 3 events on its observers: "added", "changed", and "removed" that match the DDP messages. However, unlike the DDP messages, the events pass the whole object that the event affects.
Asteroid has all of this information, I believe, but the ReactiveQuery only emits 1 event: "change". I'd like to be able to reuse some code that used the native Meteor DDP client, and I'm finding myself reconstructing information that I know Asteroid has. For example, using underscore:
query.on("change", function(id) {
var data = _(this.result).last();
if (data._id != id) {
data = _.find(this.result, {_id: id});
}
// Dispatch to other
if (_(data).isUndefined()) {
onDataWasRemovedWithId(id);
} else {
onDataWasAddedOrChanged(data);
}
});
I wouldn't have created an issue if I could have reconstructed the "on...()" method calls exactly as the "added", "changed", and "removed" event handlers, but these 2 functions are the closest that I could create to those 3 signatures.
onDataWasRemovedWithId(id)
I only have the ID, not the data that was removed. Sometimes, the data (a document) that was removed needs to be archived in another collection, or somewhere else entirely, so it's nessisary to know what was removed even though it would have already been removed at the time of this event.
onDataWasAddedOrChanged(data)
This one is closer to the "added" and "changed" event handler signatures, but it lacks a key piece of information: The handler doesn't know if the data is being added, or if it changed. There's no way that I can see at this point to be able to tell which operation was intended.
Can "added", "changed", and "removed" like events be added to ReactiveQuery easily?
The Meteor framework has 3 events on its observers: "added", "changed", and "removed" that match the DDP messages. However, unlike the DDP messages, the events pass the whole object that the event affects.
Asteroid has all of this information, I believe, but the ReactiveQuery only emits 1 event: "change". I'd like to be able to reuse some code that used the native Meteor DDP client, and I'm finding myself reconstructing information that I know Asteroid has. For example, using underscore:
I wouldn't have created an issue if I could have reconstructed the "on...()" method calls exactly as the "added", "changed", and "removed" event handlers, but these 2 functions are the closest that I could create to those 3 signatures.
Can "added", "changed", and "removed" like events be added to ReactiveQuery easily?