May 2017
Intermediate to advanced
388 pages
7h 30m
English
There are a few options on how we can listen when a collection changes. The first option is to use Meteor's Tracker, which is a tracking system that can track anything that supports reactive updates. In our case, we are interested in the DB collections:
let Stats = new Mongo.Collection('stats');Tracker.autorun(() => { let data = Stats.find({}).fetch() store.dispatch({type: 'RECEIVE_TWEET', tweets: data})});
Tracker.autorun will run each time the Stats collection changes and, in there, we can dispatch the action with the data to the reducer.
Another way is to attach an observer to the collection:
let Stats = new Mongo.Collection('stats');Stats.find({}).observe({ added: function (data) { store.dispatch({ ...Read now
Unlock full access