Fix bug in _SessionDocumentView where objects are not maps.

Generally clean up use of 'in'.
This commit is contained in:
David Glasser
2012-12-12 14:48:58 -08:00
parent c915c375c7
commit 36fe3033cb
2 changed files with 16 additions and 6 deletions

View File

@@ -8,7 +8,6 @@ var Fiber = __meteor_bootstrap__.require('fibers');
Meteor._SessionDocumentView = function (id) {
var self = this;
self.id = id;
self.existsIn = {}; // set of subId
self.dataByKey = {}; // key-> [ {subscriptionId, value} by precedence]
};
@@ -43,12 +42,12 @@ _.extend(Meteor._SessionDocumentView.prototype, {
changeField: function (subscriptionId, key, value, changeCollector, isAdd) {
var self = this;
var precedenceList = self.dataByKey[key];
if (!precedenceList) {
if (!_.has(self.dataByKey, key)) {
self.dataByKey[key] = [{subscriptionId: subscriptionId, value: value}];
changeCollector[key] = value;
return;
}
var precedenceList = self.dataByKey[key];
var elt;
if (!isAdd)
elt = _.find(precedenceList, function (precedence) {
@@ -412,7 +411,7 @@ _.extend(Meteor._LivedataSession.prototype, {
processNext();
};
if (msg.msg in self.protocol_handlers)
if (_.has(self.protocol_handlers, msg.msg))
self.protocol_handlers[msg.msg].call(self, msg, unblock);
else
self.sendError('Bad request', msg);
@@ -442,7 +441,7 @@ _.extend(Meteor._LivedataSession.prototype, {
return;
}
if (msg.id in self.named_subs)
if (_.has(self.named_subs, msg.id))
// subs are idempotent, or rather, they are ignored if a sub
// with that id already exists. this is important during
// reconnect.
@@ -489,7 +488,7 @@ _.extend(Meteor._LivedataSession.prototype, {
// check for a replayed method (this is important during
// reconnect)
if (msg.id in self.result_cache) {
if (_.has(self.result_cache, msg.id)) {
// found -- just resend whatever we sent last time
var payload = _.clone(self.result_cache[msg.id]);
delete payload.when;

View File

@@ -343,3 +343,14 @@ Tinytest.add('livedata - sessionview - added becomes changed', function (test) {
v.removed('B', ['A1']);
v.expectResult({fun: 'removed', ids: ['A1']});
});
Tinytest.add('livedata - sessionview - weird key names', function (test) {
var v = newView(test);
v.added('A', "A1", {});
v.expectResult({fun: 'added', id: "A1", fields: {}});
v.changed('A', "A1", {constructor: 'bla'});
v.expectResult({fun: 'changed', id: 'A1', changed: {constructor: 'bla'},
cleared: []});
});