mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Fix bug in _SessionDocumentView where objects are not maps.
Generally clean up use of 'in'.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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: []});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user