What are the pros/cons between using Deps.autorun
or Collection.observe
to keep a third-party widget in sync with a reactive Meteor.Collection
.
For example, I am using jsTree to visually show a directory tree that I have stored in my MongoDB. I'm using this code to make it reactive:
// automatically reload the fileTree if the data changes
FileTree.find().observeChanges({
added: function() {
$.jstree.reference('#fileTree').refresh();
},
changed: function() {
$.jstree.reference('#fileTree').refresh();
},
removed: function() {
$.jstree.reference('#fileTree').refresh();
}
});
What are the pros/cons of using this method vs a Deps.autorun
call that would look something like this: (untested)
Deps.autorun(function() {
jsonData = FileTree.find().fetch();
$.jstree.reference('#fileTree')({'core': {'data': jsonData} });
});
This is just an example. I'm asking about the pros/cons in general, not for this specific use case.