From e7250a045fd3c6b817eb7562eb97032511a52d88 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Fri, 1 Aug 2014 15:01:26 -0700 Subject: [PATCH] Eliminate `_fetch` on handles returned from `cursor.observe()` This was originally introduced with f1b77fec966c8c97d53628bfd79196afb0c99498, but it looks like all of our tests now pass. (Maybe eliminating `rewind` in b5a0613f85002ee35732c01a27c0d9b1901ed0de made this no longer necessary?) If we find that this commit did break something, let's make sure to add a failing test before reverting. --- packages/minimongo/observe.js | 27 ------------------- packages/observe-sequence/observe_sequence.js | 2 +- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/packages/minimongo/observe.js b/packages/minimongo/observe.js index 95b92d3d51..191b78333f 100644 --- a/packages/minimongo/observe.js +++ b/packages/minimongo/observe.js @@ -177,32 +177,5 @@ LocalCollection._observeFromObserveChanges = function (cursor, observeCallbacks) var handle = cursor.observeChanges(changeObserver.applyChange); suppressed = false; - if (changeObserver.ordered) { - // Fetches the current list of documents, in order, as an array. Can be - // called at any time. Internal API assumed by the `observe-sequence` - // package (used by Meteor UI for `#each` blocks). Only defined on ordered - // observes (those that listen on `addedAt` or similar). Continues to work - // after `stop()` is called on the handle. - // - // Because we already materialize the full OrderedDict of all documents, it - // seems nice to provide access to the view rather than making the data - // consumer reconstitute it. This gives the consumer a shot at doing - // something smart with the feed like proxying it, since firing callbacks - // like `changed` and `movedTo` basically requires omniscience (knowing old - // and new documents, old and new indices, and the correct value for - // `before`). - // - // NOTE: If called from an observe callback for a certain change, the result - // is *not* guaranteed to be a snapshot of the cursor up to that - // change. This is because the callbacks are invoked before updating docs. - handle._fetch = function () { - var docsArray = []; - changeObserver.docs.forEach(function (doc) { - docsArray.push(transform(EJSON.clone(doc))); - }); - return docsArray; - }; - } - return handle; }; diff --git a/packages/observe-sequence/observe_sequence.js b/packages/observe-sequence/observe_sequence.js index 29cbc04a5c..b736ff88ef 100644 --- a/packages/observe-sequence/observe_sequence.js +++ b/packages/observe-sequence/observe_sequence.js @@ -86,7 +86,7 @@ ObserveSequence = { // more up-to-date information (specifically, the state of the observe // before it was stopped, which may be older than the DB). if (activeObserveHandle) { - lastSeqArray = _.map(activeObserveHandle._fetch(), function (doc) { + lastSeqArray = _.map(lastSeq.fetch(), function (doc) { return {_id: doc._id, item: doc}; }); activeObserveHandle.stop();