Skip to content

Instantly share code, notes, and snippets.

@dburles
Forked from tmeasday/gist:9086145
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dburles/9086392 to your computer and use it in GitHub Desktop.
Save dburles/9086392 to your computer and use it in GitHub Desktop.
var relations = {};
Meteor.Collection.prototype.relations = function(obj) {
relations[this._name] = obj;
};
if (Meteor.isClient) {
Meteor.subscribeReactive = function(name) {
Meteor.subscribe(name);
Deps.autorun(function() {
// Meteor.subscribe(...)
});
};
}
if (Meteor.isServer) {
Cursor = Object.getPrototypeOf(new Meteor.Collection('_void').find()).constructor;
Cursor.prototype.join = function(name) {
this._joins = name;
return this;
};
Meteor.publishReactive = function(name, fn) {
var cursor = fn();
var collectionName = cursor._cursorDescription.collectionName;
Meteor.publish(name, function() {
return fn.apply(this, arguments);
});
Meteor.publish(name + '_' + cursor._joins, function() {
return relations[collectionName][cursor._joins];
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment