-
Notifications
You must be signed in to change notification settings - Fork 7
/
server.js
39 lines (31 loc) · 1.28 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Meteor } from "meteor/meteor";
import { METADATA_COLLECTION, constructId } from "./utils";
export const FindFromPublication = {};
FindFromPublication.publish = function(publicationName, fn) {
Meteor.publish(publicationName, function() {
let rank = 0;
const oldAdded = this.added.bind(this);
const oldRemoved = this.removed.bind(this);
this.added = (collectionName, documentId, doc) => {
oldAdded(collectionName, documentId, doc);
oldAdded(METADATA_COLLECTION, constructId(collectionName, publicationName, documentId), {
collectionName,
documentId,
publicationName,
// NOTE: this rank is incremented across all collections
// probably doesn't matter?
rank
});
rank += 1;
};
this.removed = (collectionName, documentId) => {
// the only way this can get called is when all documents are removed
// from the subscription as it's torn down, we know that the underlying document
// will also be removed, and this will pick it up.
if (collectionName === METADATA_COLLECTION) return;
oldRemoved(METADATA_COLLECTION, constructId(collectionName, publicationName, documentId));
oldRemoved(collectionName, documentId);
};
return fn.apply(this, arguments);
});
};