Publish/Subscribe API
Meteor’s pub/sub system controls which data is sent from the server to the client. Source:packages/ddp-server/livedata_server.js, packages/ddp-client/
Publications (Server)
Meteor.publish()
Publish a record set to clients. Locus: ServerName of the record set. If
null, the set has no name and the record set is automatically sent to all connected clients.Function called on the server each time a client subscribes. Inside the function,
this is the publish handler object.Universal Publications (null)
Publications withnull name are sent to all clients automatically:
Custom Publications
For advanced use cases, manually control published data:Publication Context (this)
Inside a publish function,this provides:
The id of the logged-in user, or
null if no user is logged in.The connection object for this subscription.
Call when the initial snapshot is complete. Triggers
onReady callback on client.Register a callback to run when the subscription is stopped.
Stop this subscription and signal an error to the client.
Stop this subscription.
Inform the subscriber that a document has been added.
Inform the subscriber that a document has been modified.
Inform the subscriber that a document has been removed.
Subscriptions (Client)
Meteor.subscribe()
Subscribe to a record set. Returns a handle that providesstop() and ready() methods.
Locus: Client
Name of the subscription. Matches the name of the server’s
publish() call.Optional arguments passed to publisher function on server.
Optional. May include
onStop and onReady callbacks. If a function is passed instead of an object, it is interpreted as an onReady callback.Subscription Handle
The object returned byMeteor.subscribe() has these methods:
handle.stop()
Stop this subscription.handle.ready()
True if the server has marked the subscription as ready. A reactive data source.handle.subscriptionId
The subscription ID.Reactive Subscriptions
Subscriptions inTracker.autorun automatically resubscribe when dependencies change: