I am trying to write webapp using Meteor, and I definitely cannot understand something about subscribing to published datasets. The whole application is on github (related to the last commit for posterity), but I will try to summarize below.
I have a collection called commands, available for both client and server:
Teams = new Meteor.Collection( "teams" );
On the server, I want to publish a list of all the commands:
Meteor.publish( "allteams", function() { ...
There is a very simple cursor that makes up this published list:
var handle = Teams.find( {} ).observeChanges({ added: function( id ) { console.log( "New team added" ); if ( !initializing ) { console.log( "Telling subscribers it all change" ); self.added( "teams", id, {} ); self.ready(); } } });
The client subscribes to this source, and when elements are added, the client will add pins to the map:
Meteor.autorun( function() { Meteor.subscribe( "allteams", function() { console.log( "All teams has been updated" );
When the list is initially populated, autostart works fine, but if I add another item to the collection, the publisher method writes “I noticed this,” but nothing happens in the subscriber.
The purpose of the foregoing is to:
- The server has a list of commands consisting of a name and a long / part detail.
- When a client connects, they receive this list of commands and they are displayed on the map.
- If the command is added to the list on the server side, each client is notified and a new contact appears on the map.
In terms of the app, I probably don't need the pins to magically appear, but this is a useful way to teach publishing and subscribing, especially when I don't understand! In the end, "allteams" is likely to be a little smaller than the entire list of commands, so I think it is like looking at the data.
Am I missing something completely obvious?
Edit: I worked through and put the answer below. tl; dr I did not subscribe to the source of reactive data at all.