mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
- fix "observeChanges - callback isolation"
This commit is contained in:
@@ -46,7 +46,6 @@ export default class MethodInvoker {
|
||||
// Invoke the callback, if we have both a result and know that all data has
|
||||
// been written to the local cache.
|
||||
_maybeInvokeCallback() {
|
||||
console.log(this._methodResult, this._dataVisible);
|
||||
if (this._methodResult && this._dataVisible) {
|
||||
// Call the callback. (This won't throw: the callback was wrapped with
|
||||
// bindEnvironment.)
|
||||
|
||||
@@ -1545,9 +1545,7 @@ Server = function (options = {}) {
|
||||
|
||||
socket.on('close', function () {
|
||||
if (socket._meteorSession) {
|
||||
Meteor._runAsync(function() {
|
||||
socket._meteorSession.close();
|
||||
});
|
||||
socket._meteorSession.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -227,7 +227,7 @@ export default class Cursor {
|
||||
* @param {Object} callbacks Functions to call to deliver the result set as it
|
||||
* changes
|
||||
*/
|
||||
observeChanges(options) {
|
||||
async observeChanges(options) {
|
||||
const ordered = LocalCollection._observeChangesCallbacksAreOrdered(options);
|
||||
|
||||
// there are several places that assume you aren't combining skip/limit with
|
||||
@@ -369,7 +369,7 @@ export default class Cursor {
|
||||
|
||||
// run the observe callbacks resulting from the initial contents
|
||||
// before we leave the observe.
|
||||
this.collection._observeQueue.drain();
|
||||
await this.collection._observeQueue.drain();
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -58,34 +58,46 @@ _.each ([{added: 'added', forceOrdered: true},
|
||||
});
|
||||
});
|
||||
|
||||
Tinytest.addAsync("observeChanges - callback isolation", function (test, onComplete) {
|
||||
Tinytest.addAsync('observeChanges - callback isolation', async function(
|
||||
test,
|
||||
onComplete
|
||||
) {
|
||||
var c = makeCollection();
|
||||
withCallbackLogger(test, ["added", "changed", "removed"], Meteor.isServer, function (logger) {
|
||||
var handles = [];
|
||||
var cursor = c.find();
|
||||
handles.push(cursor.observeChanges(logger));
|
||||
// fields-tampering observer
|
||||
handles.push(cursor.observeChanges({
|
||||
added: function(id, fields) {
|
||||
fields.apples = 'green';
|
||||
},
|
||||
changed: function(id, fields) {
|
||||
fields.apples = 'green';
|
||||
},
|
||||
}));
|
||||
await withCallbackLogger(
|
||||
test,
|
||||
['added', 'changed', 'removed'],
|
||||
Meteor.isServer,
|
||||
async function(logger) {
|
||||
var handles = [];
|
||||
var cursor = c.find();
|
||||
handles.push(await cursor.observeChanges(logger));
|
||||
// fields-tampering observer
|
||||
handles.push(
|
||||
await cursor.observeChanges({
|
||||
added: function(id, fields) {
|
||||
fields.apples = 'green';
|
||||
},
|
||||
changed: function(id, fields) {
|
||||
fields.apples = 'green';
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
var fooid = c.insert({apples: "ok"});
|
||||
logger.expectResult("added", [fooid, {apples: "ok"}]);
|
||||
var fooid = await c.insertAsync({ apples: 'ok' });
|
||||
logger.expectResult('added', [fooid, { apples: 'ok' }]);
|
||||
|
||||
c.update(fooid, {apples: "not ok"});
|
||||
logger.expectResult("changed", [fooid, {apples: "not ok"}]);
|
||||
await c.updateAsync(fooid, { apples: 'not ok' });
|
||||
|
||||
test.equal(c.findOne(fooid).apples, "not ok");
|
||||
logger.expectResult('changed', [fooid, { apples: 'not ok' }]);
|
||||
|
||||
_.each(handles, function(handle) { handle.stop(); });
|
||||
onComplete();
|
||||
});
|
||||
test.equal((await c.findOneAsync(fooid)).apples, 'not ok');
|
||||
|
||||
for (const handle of handles) {
|
||||
await handle.stop();
|
||||
}
|
||||
onComplete();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Tinytest.addAsync("observeChanges - single id - initial adds", function (test, onComplete) {
|
||||
|
||||
Reference in New Issue
Block a user