Publishing/subscribing multiple subsets of the same server collection

Could you not just use the same query client-side when you want to look at the items? In a lib directory: enabledItems = function() { return Items.find({enabled: true}); } processedItems = function() { return Items.find({processed: true}); } On the server: Meteor.publish(‘enabled_items’, function() { return enabledItems(); }); Meteor.publish(‘processed_items’, function() { return processedItems(); }); On the client … Read more

Why would one use the Publish/Subscribe pattern (in JS/jQuery)?

It’s all about loose coupling and single responsibility, which goes hand to hand with MV* (MVC/MVP/MVVM) patterns in JavaScript which are very modern in the last few years. Loose coupling is an Object-oriented principle in which each component of the system knows its responsibility and doesn’t care about the other components (or at least tries … Read more

Difference between Observer, Pub/Sub, and Data Binding

There are two major differences between Observer/Observable and Publisher/Subscriber patterns: Observer/Observable pattern is mostly implemented in a synchronous way, i.e. the observable calls the appropriate method of all its observers when some event occurs. The Publisher/Subscriber pattern is mostly implemented in an asynchronous way (using message queue). In the Observer/Observable pattern, the observers are aware … Read more

How to unsubscribe from a socket.io subscription?

From looking at the source of socket.io.js (couldn’t find it in documentation anywhere), I found these two functions: removeListener = function(name, fn) removeAllListeners = function(name) I used removeAllListeners successfully in my app; you should be able to choose from these: socket.removeListener(“news”, cbProxy); socket.removeAllListeners(“news”); Also, I don’t think your solution of cbProxy = _blank would actually … Read more

How does the messages-count example in Meteor docs work?

Thanks for prompting me to write a clearer explanation. Here’s a fuller example with my comments. There were a few bugs and inconsistencies that I’ve cleaned up. Next docs release will use this. Meteor.publish is quite flexible. It’s not limited to publishing existing MongoDB collections to the client: we can publish anything we want. Specifically, … Read more

Understanding Meteor Publish / Subscribe

Collections, publications and subscriptions are a tricky area of Meteor, that the documentation could discuss in more detail, so as to avoid frequent confusion, which sometimes get amplified by confusing terminology. Here’s Sacha Greif (co-author of DiscoverMeteor) explaining publications and subscriptions in one slide: To properly understand why you need to call find() more than … Read more

tech