forked from tuhinc/rethink-livedata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invalidator.js
51 lines (41 loc) · 1.1 KB
/
invalidator.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
40
41
42
43
44
45
46
47
48
49
50
51
var util = Npm.require('util');
var EventEmitter = Npm.require('events').EventEmitter;
function Invalidator(table) {
var self = this;
self._table = table;
self._cursors = [];
self._selectors = [];
}
Invalidator.prototype = Object.create(EventEmitter);
Invalidator.prototype.addCursor = function addCursor(cursor) {
var self = this;
var index = self._cursors.indexOf(cursor);
if(index < 0) {
self._cursors.push(cursor);
}
//add to correct selector
// var added = false;
// for(var lc=0; lc<self._selectors.length; lc++) {
// var selectorInfo = self._selectors[lc];
// if(Meteor.deepEqual(selectorInfo.selector, cursor._selector)) {
// selectorInfo.cursors.push(cursor);
// added = true;
// break;
// }
// }
// if(!added) {
// self._selectors.push({
// selector: cursor._selector,
// cursors: [cursor]
// });
// }
};
// this needs to first test for a selector
Invalidator.prototype.insert = function(doc) {
this._cursors.forEach(function(cursor) {
cursor._added(doc);
});
};
_.extend(Meteor, {
Invalidator: Invalidator
});