Skip to content

Commit

Permalink
Change context.subscribe API to send FR data
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoda committed Aug 8, 2015
1 parent 6fad81e commit ce57b95
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions lib/server/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,23 @@ Context.prototype.subscribe = function(subName /*, params */) {
var subscription = {name: subName, params: params}
var publishContext = new PublishContext(this, subscription);

this.processPublication(publishHandler, publishContext, params);
return this.processPublication(publishHandler, publishContext, params);
} else {
console.warn('There is no such publish handler named:', subName);
return {};
}
};

Context.prototype.processPublication = function(publishHandler, publishContext, params) {
var self = this;

var data = {};
var ensureCollection = function(collectionName) {
self._ensureCollection(collectionName);
if(!data[collectionName]) {
data[collectionName] = [];
}
};

var future = new Future();
//detect when the context is ready to be sent to the client
publishContext.onStop(function() {
Expand Down Expand Up @@ -79,8 +87,10 @@ Context.prototype.processPublication = function(publishHandler, publishContext,
(cursor._cursorDescription)? cursor._cursorDescription.collectionName: null || //for meteor-collections
(cursor._collection)? cursor._collection._name: null; //for smart-collections

self._ensureCollection(collectionName);
self._collectionData[collectionName].push(cursor.fetch());
ensureCollection(collectionName);
var cursorData = cursor.fetch();
data[collectionName].push(cursorData);
self._collectionData[collectionName].push(cursorData);
});

//the subscription is ready
Expand All @@ -104,7 +114,15 @@ Context.prototype.processPublication = function(publishHandler, publishContext,

// wait for the subscription became ready.
future.wait();

// get the data
_.each(publishContext._collectionData, function(collData, collectionName) {
ensureCollection(collectionName);
data[collectionName].push(collData);
});
}

return data;
};

Context.prototype.completeSubscriptions = function(subscription) {
Expand Down

0 comments on commit ce57b95

Please sign in to comment.