May 2017
Intermediate to advanced
388 pages
7h 30m
English
The way we can get real-time updates from the server is through the Publishing and Subscribing messaging pattern of Meteor.
The server publishes an event and on the other side, the client subscribes to that event and listens to data changes.
On the server, in our case in the server/main.js file, we can publish an event in a very simple way:
import { Meteor } from 'meteor/meteor'; Meteor.startup(() => { // code to run on server at startup Meteor.publish('time', function() { ... });});
The publish function takes two arguments: name of the collection and a callback function that will be executed on each subscription from the client.
On the client, we can subscribe to it as shown here:
Meteor.subscribe('time');Read now
Unlock full access