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
Deps.autorun, now Tracker.autorun is a reactive computation block. Whereas the observeChanges provides a callback to when something changes.
When you use Deps.autorun, the entire block in function() {...}
, will re-run every time a reactive variable, or document changes, in any way at all (that is updated, removed or inserted), or any other reactive variable change.
The observeChanges callbacks are more fine tuned, and fire the callbacks for added, changed or removed depending on the query.
Based on your code above, in effect both are the same. If you had more reactive variables in the Deps.autorun block then the observeChanges
way of doing it would be more efficient.
In general the first style is more efficient, but as your code stands above they're both nearly the same and it depends on your preference.