diff --git a/packages/accounts-base/accounts_client.js b/packages/accounts-base/accounts_client.js index ba462f9f0a..1e260551c6 100644 --- a/packages/accounts-base/accounts_client.js +++ b/packages/accounts-base/accounts_client.js @@ -6,18 +6,18 @@ }; var loggingIn = false; - var loggingInListeners = new Meteor.deps._ContextSet; + var loggingInVar = new Deps.Variable; // This is mostly just called within this file, but Meteor.loginWithPassword // also uses it to make loggingIn() be true during the beginPasswordExchange // method call too. Accounts._setLoggingIn = function (x) { if (loggingIn !== x) { loggingIn = x; - loggingInListeners.invalidateAll(); + loggingInVar.changed(); } }; Meteor.loggingIn = function () { - loggingInListeners.addCurrentContext(); + loggingInVar.changed(); return loggingIn; }; @@ -181,10 +181,10 @@ // XXX this can be simplified if we merge in // https://github.com/meteor/meteor/pull/273 var loginServicesConfigured = false; - var loginServicesConfiguredListeners = new Meteor.deps._ContextSet; + var loginServicesConfiguredVar = new Deps.Variable; Meteor.subscribe("meteor.loginServiceConfiguration", function () { loginServicesConfigured = true; - loginServicesConfiguredListeners.invalidateAll(); + loginServicesConfiguredVar.changed(); }); // A reactive function returning whether the @@ -196,7 +196,7 @@ return true; // not yet complete, save the context for invalidation once we are. - loginServicesConfiguredListeners.addCurrentContext(); + Deps.depend(loginServicesConfiguredVar); return false; }; })(); diff --git a/packages/accounts-password/password_tests.js b/packages/accounts-password/password_tests.js index f5ad41eaf0..067774d0c1 100644 --- a/packages/accounts-password/password_tests.js +++ b/packages/accounts-password/password_tests.js @@ -54,7 +54,7 @@ if (Meteor.isClient) (function () { // Set up a reactive context that only refreshes when Meteor.user() is // invalidated. var loaded = false; - var handle = Meteor.autorun(function () { + var handle = Deps.autorun(function () { if (Meteor.user() && Meteor.user().emails) loaded = true; }); @@ -66,7 +66,7 @@ if (Meteor.isClient) (function () { // By the time of the login callback, the user should be loaded. test.isTrue(Meteor.user().emails); // Flushing should get us the autorun as well. - Meteor.flush(); + Deps.flush(); test.isTrue(loaded); handle.stop(); })); diff --git a/packages/accounts-ui-unstyled/login_buttons_dropdown.js b/packages/accounts-ui-unstyled/login_buttons_dropdown.js index 5eee397499..12007dade9 100644 --- a/packages/accounts-ui-unstyled/login_buttons_dropdown.js +++ b/packages/accounts-ui-unstyled/login_buttons_dropdown.js @@ -7,7 +7,7 @@ Template._loginButtons.events({ 'click #login-name-link, click #login-sign-in-link': function () { loginButtonsSession.set('dropdownVisible', true); - Meteor.flush(); + Deps.flush(); correctDropdownZIndexes(); }, 'click .login-close-text': function () { @@ -85,7 +85,7 @@ loginButtonsSession.set('inSignupFlow', true); loginButtonsSession.set('inForgotPasswordFlow', false); // force the ui to update so that we have the approprate fields to fill in - Meteor.flush(); + Deps.flush(); // update new fields with appropriate defaults if (username !== null) @@ -121,7 +121,7 @@ loginButtonsSession.set('inSignupFlow', false); loginButtonsSession.set('inForgotPasswordFlow', true); // force the ui to update so that we have the approprate fields to fill in - Meteor.flush(); + Deps.flush(); // update new fields with appropriate defaults if (email !== null) @@ -141,7 +141,7 @@ loginButtonsSession.set('inSignupFlow', false); loginButtonsSession.set('inForgotPasswordFlow', false); // force the ui to update so that we have the approprate fields to fill in - Meteor.flush(); + Deps.flush(); if (document.getElementById('login-username')) document.getElementById('login-username').value = username; diff --git a/packages/deps/deps.js b/packages/deps/deps.js index bed95aa7e8..a740ffd89e 100644 --- a/packages/deps/deps.js +++ b/packages/deps/deps.js @@ -27,7 +27,7 @@ this.invalidated = false; }; - _.extend(Computation.prototype, { + _.extend(Deps.Computation.prototype, { run: function (f) { var previous = Deps.currentComputation; Deps.currentComputation = this; @@ -60,8 +60,10 @@ this._callbacks.push(f); }, + // Make this computation depend on v. Return true + // if this is a new dependency. depend: function (v) { - v._addDependent(this); + return v._addDependent(this); } }); @@ -69,7 +71,7 @@ this._dependentsById = {}; }; - _.extend(Variable.prototype, { + _.extend(Deps.Variable.prototype, { // Adds `computation` to this set if it is not already // present. Returns true if `computation` is a new member of the set. _addDependent: function (computation) { @@ -98,9 +100,13 @@ }); _.extend(Deps, { + // Make the current computation depend on v. Returns true + // if this is a new dependency. If there is no current + // computation, does nothing and returns false. depend: function (v) { if (Deps.active) - v._addDependent(Deps.currentComputation); + return v._addDependent(Deps.currentComputation); + return false; }, flush: function () { diff --git a/packages/deps/deps_tests.js b/packages/deps/deps_tests.js index 63e4e718ef..f04f2823bb 100644 --- a/packages/deps/deps_tests.js +++ b/packages/deps/deps_tests.js @@ -1,46 +1,46 @@ Tinytest.add('deps - autorun', function (test) { - var listeners = new Meteor.deps._ContextSet; + var v = new Deps.Variable; var x = 0; - var handle = Meteor.autorun(function (handle) { - listeners.addCurrentContext(); + var handle = Deps.autorun(function (handle) { + Deps.depend(v); ++x; }); test.equal(x, 1); - Meteor.flush(); + Deps.flush(); test.equal(x, 1); - listeners.invalidateAll(); + v.changed(); test.equal(x, 1); - Meteor.flush(); + Deps.flush(); test.equal(x, 2); - listeners.invalidateAll(); + v.changed(); test.equal(x, 2); - Meteor.flush(); + Deps.flush(); test.equal(x, 3); - listeners.invalidateAll(); + v.changed(); // Prevent the function from running further. handle.stop(); - Meteor.flush(); + Deps.flush(); test.equal(x, 3); - listeners.invalidateAll(); - Meteor.flush(); + v.changed(); + Deps.flush(); test.equal(x, 3); - Meteor.autorun(function (internalHandle) { - listeners.addCurrentContext(); + Deps.autorun(function (internalHandle) { + Deps.depend(v); ++x; if (x == 6) internalHandle.stop(); }); test.equal(x, 4); - listeners.invalidateAll(); - Meteor.flush(); + v.changed(); + Deps.flush(); test.equal(x, 5); - listeners.invalidateAll(); + v.changed(); // Increment to 6 and stop. - Meteor.flush(); + Deps.flush(); test.equal(x, 6); - listeners.invalidateAll(); - Meteor.flush(); + v.changed(); + Deps.flush(); // Still 6! test.equal(x, 6); }); diff --git a/packages/deps/package.js b/packages/deps/package.js index a38a57f69e..2e13963124 100644 --- a/packages/deps/package.js +++ b/packages/deps/package.js @@ -9,7 +9,7 @@ Package.on_use(function (api, where) { where = where || ['client', 'server']; api.use('underscore', where); - api.add_files(['deps.js', 'deps-utils.js'], where); + api.add_files(['deps.js'], where); }); Package.on_test(function (api) { diff --git a/packages/livedata/livedata_connection.js b/packages/livedata/livedata_connection.js index 7bf2cfebe1..b10620df31 100644 --- a/packages/livedata/livedata_connection.js +++ b/packages/livedata/livedata_connection.js @@ -145,7 +145,8 @@ Meteor._LivedataConnection = function (url, options) { // - id // - name // - params - // - context (the Context in which Meteor.subscribe was called, if any) + // - computation (the Deps.Computation in which Meteor.subscribe was + // called, if any) // - ready (has the 'ready' message been received?) // - readyCallback (an optional callback to call when ready) // - errorCallback (an optional callback to call if the sub terminates with @@ -158,7 +159,7 @@ Meteor._LivedataConnection = function (url, options) { // Reactive userId. self._userId = null; - self._userIdListeners = Meteor.deps && new Meteor.deps._ContextSet; + self._userIdVar = (typeof Deps !== "undefined") && new Deps.Variable; // Block auto-reload while we're waiting for method responses. if (!options.reloadWithOutstanding) { @@ -426,10 +427,10 @@ _.extend(Meteor._LivedataConnection.prototype, { } // Is there an existing sub with the same name and param, run in an - // invalidated Context? This can only happen if the context just got - // invalidated and we haven't fully finished a round of Meteor.flush() + // invalidated Computation? This can only happen if the computation just got + // invalidated and we haven't fully finished a round of Deps.flush() // yet. For example, this will happen with the pattern of: - // Meteor.autorun(function () { + // Deps.autorun(function () { // Meteor.subscribe("foo", Session.get("foo")); // Meteor.subscribe("bar", Session.get("bar")); // }); @@ -440,16 +441,16 @@ _.extend(Meteor._LivedataConnection.prototype, { // being invalidated, we will require N matching subscribe calls to keep // them all active. var existing = _.find(self._subscriptions, function (sub) { - return sub.context && sub.context.invalidated && sub.name === name && - EJSON.equals(sub.params, params); + return sub.computation && sub.computation.invalidated && + sub.name === name && EJSON.equals(sub.params, params); }); - var currentContext = Meteor.deps && Meteor.deps.Context.current; + var currentComputation = Deps.currentComputation; var id; if (existing) { id = existing.id; - // Substitute our current context (if any) for the one on the sub. - existing.context = currentContext; + // Substitute our current computation (if any) for the one on the sub. + existing.computation = currentComputation; if (callbacks.onReady) { // If the sub is not already ready, replace any ready callback with the @@ -472,9 +473,9 @@ _.extend(Meteor._LivedataConnection.prototype, { id: id, name: name, params: params, - context: currentContext, + computation: currentComputation, ready: false, - readyListeners: Meteor.deps && new Meteor.deps._ContextSet, + readyVar: (typeof Deps !== "undefined") && new Deps.Variable, readyCallback: callbacks.onReady, errorCallback: callbacks.onError }; @@ -494,37 +495,34 @@ _.extend(Meteor._LivedataConnection.prototype, { if (!_.has(self._subscriptions, id)) return false; var record = self._subscriptions[id]; - record.readyListeners && record.readyListeners.addCurrentContext(); + record.readyVar && Deps.depend(record.readyVar); return record.ready; } }; - if (currentContext) { - // We're in a reactive context, so we'd like to unsubscribe when the - // context is invalidated... but not if some *OTHER* onInvalidate callback - // on currentContext re-subscribes to the same subscription (eg, as part - // of an autorun). Meteor.flush guarantees that it won't interleave calls - // to currentContext's callbacks and unsubscribeContext's callbacks, so - // this ensures that by the time unsubscribeContext's onInvalidate - // callback is called, we've already re-run the autorun function (if this - // was an autorun context). - var unsubscribeContext = new Meteor.deps.Context; - unsubscribeContext.onInvalidate(function () { - // Did we already unsubscribe from this? Do nothing. - if (!_.has(self._subscriptions, id)) - return; - // Did we substitute a new context in for this constitute in the - // "Substitute" block above? (eg, are we in an autorun and the re-run of - // the function subscribed to this again?) - if (self._subscriptions[id].context !== currentContext) - return; - // Nope, the only reason we are currently subscribed to this - // subscription is that *THIS* subscribe call wanted it to be so, and - // its context is invalidated, so it's time to unsubscribe. - handle.stop(); - }); - currentContext.onInvalidate(function () { - unsubscribeContext.invalidate(); + if (currentComputation) { + // We're in a reactive computation, so we'd like to unsubscribe when the + // computation is invalidated... but not if some *OTHER* onInvalidate + // callback on currentComputation re-subscribes to the same subscription + // (eg, as part of a Deps.autorun). Use Deps.afterFlush to schedule + // this check to happen later in the flush cycle, after all of + // currentComputation's callbacks have been called, and therefore after + // the current Deps.autorun (if any) has been re-run. + currentComputation.onInvalidate(function () { + Deps.afterFlush(function () { + // Did we already unsubscribe from this? Do nothing. + if (!_.has(self._subscriptions, id)) + return; + // Did we substitute a new computation in for this constitute in the + // "Substitute" block above? (eg, are we in an autorun and the re-run of + // the function subscribed to this again?) + if (self._subscriptions[id].computation !== currentComputation) + return; + // Nope, the only reason we are currently subscribed to this + // subscription is that *THIS* subscribe call wanted it to be so, and + // its computation is invalidated, so it's time to unsubscribe. + handle.stop(); + }); }); } @@ -785,19 +783,19 @@ _.extend(Meteor._LivedataConnection.prototype, { /// userId: function () { var self = this; - if (self._userIdListeners) - self._userIdListeners.addCurrentContext(); + if (self._userIdVar) + Deps.depend(self._userIdVar); return self._userId; }, setUserId: function (userId) { var self = this; - // Avoid invalidating listeners if setUserId is called with current value. + // Avoid invalidating dependents if setUserId is called with current value. if (self._userId === userId) return; self._userId = userId; - if (self._userIdListeners) - self._userIdListeners.invalidateAll(); + if (self._userIdVar) + self._userIdVar.changed(); }, // Returns true if we are in a state after reconnect of waiting for subs to be @@ -1116,7 +1114,7 @@ _.extend(Meteor._LivedataConnection.prototype, { return; subRecord.readyCallback && subRecord.readyCallback(); subRecord.ready = true; - subRecord.readyListeners && subRecord.readyListeners.invalidateAll(); + subRecord.readyVar && subRecord.readyVar.changed(); }); }); }, diff --git a/packages/livedata/livedata_connection_tests.js b/packages/livedata/livedata_connection_tests.js index d3ae5187b2..5984ffa7ab 100644 --- a/packages/livedata/livedata_connection_tests.js +++ b/packages/livedata/livedata_connection_tests.js @@ -115,7 +115,7 @@ Tinytest.add("livedata stub - subscribe", function (test) { test.equal(message, {msg: 'sub', name: 'my_data', params: []}); var reactivelyReady = false; - var autorunHandle = Meteor.autorun(function () { + var autorunHandle = Deps.autorun(function () { reactivelyReady = sub.ready(); }); test.isFalse(reactivelyReady); @@ -123,7 +123,7 @@ Tinytest.add("livedata stub - subscribe", function (test) { // get the sub satisfied. callback fires. stream.receive({msg: 'ready', 'subs': [id]}); test.isTrue(callback_fired); - Meteor.flush(); + Deps.flush(); test.isTrue(reactivelyReady); autorunHandle.stop(); @@ -165,7 +165,7 @@ Tinytest.add("livedata stub - reactive subscribe", function (test) { // Subscribe to some subs. var stopperHandle; - var autorunHandle = Meteor.autorun(function () { + var autorunHandle = Deps.autorun(function () { conn.subscribe("foo", rFoo.get(), onReady(rFoo.get())); conn.subscribe("bar", rBar.get(), onReady(rBar.get())); conn.subscribe("completer", onReady("completer")); @@ -216,7 +216,7 @@ Tinytest.add("livedata stub - reactive subscribe", function (test) { // subscription should *NOT* call its new onReady callback, because we only // call at most one onReady for a given reactively-saved subscription. rFoo.set("foo2"); - Meteor.flush(); + Deps.flush(); test.length(stream.sent, 3); message = JSON.parse(stream.sent.shift()); @@ -246,7 +246,7 @@ Tinytest.add("livedata stub - reactive subscribe", function (test) { // Shut down the autorun. This should unsub us from all current subs at flush // time. autorunHandle.stop(); - Meteor.flush(); + Deps.flush(); test.length(stream.sent, 4); // The order of unsubs here is not important. diff --git a/packages/meteor/timers.js b/packages/meteor/timers.js index bdaa636ef8..ac70858e23 100644 --- a/packages/meteor/timers.js +++ b/packages/meteor/timers.js @@ -44,7 +44,7 @@ _.extend(Meteor, { // won't be necessary once we clobber the global setTimeout // // XXX consider making this guarantee ordering of defer'd callbacks, like - // Meteor._atFlush or Node's nextTick (in practice). Then tests can do: + // Deps.afterFlush or Node's nextTick (in practice). Then tests can do: // callSomethingThatDefersSomeWork(); // Meteor.defer(expect(somethingThatValidatesThatTheWorkHappened)); defer: function (f) { diff --git a/packages/minimongo/minimongo.js b/packages/minimongo/minimongo.js index 30bd53b08c..5d5ff1e838 100644 --- a/packages/minimongo/minimongo.js +++ b/packages/minimongo/minimongo.js @@ -140,11 +140,11 @@ LocalCollection.Cursor.prototype.forEach = function (callback) { self.db_objects = self._getRawObjects(true); if (self.reactive) - self._markAsReactive({ - addedBefore: true, - removed: true, - changed: true, - movedBefore: true}); + self._depend({ + addedBefore: true, + removed: true, + changed: true, + movedBefore: true}); while (self.cursor_pos < self.db_objects.length) callback(EJSON.clone(self.db_objects[self.cursor_pos++])); @@ -172,7 +172,7 @@ LocalCollection.Cursor.prototype.count = function () { var self = this; if (self.reactive) - self._markAsReactive({added: true, removed: true}); + self._depend({added: true, removed: true}); if (self.db_objects === null) self.db_objects = self._getRawObjects(true); @@ -339,27 +339,28 @@ LocalCollection.Cursor.prototype._getRawObjects = function (ordered) { // XXX Maybe we need a version of observe that just calls a callback if // anything changed. -LocalCollection.Cursor.prototype._markAsReactive = function (options) { +LocalCollection.Cursor.prototype._depend = function (changers) { var self = this; - var context = Meteor.deps.Context.current; + if (Deps.active) { + var v = new Deps.Variable; + Deps.depend(v); + var notifyChange = _.bind(v.change, v); - if (context) { - var invalidate = _.bind(context.invalidate, context); - var handle; - var newOptions = {_suppress_initial: true}; + var options = {_suppress_initial: true}; _.each(['added', 'changed', 'removed', 'addedBefore', 'movedBefore'], function (fnName) { - if (options[fnName]) - newOptions[fnName] = invalidate; - }); - handle = self.observeChanges(newOptions); + if (changers[fnName]) + options[fnName] = notifyChange; + }); + + var handle = self.observeChanges(options); // XXX in many cases, the query will be immediately // recreated. so we might want to let it linger for a little // while and repurpose it if it comes back. this will save us // work because we won't have to redo the initial find. - context.onInvalidate(handle.stop); + Deps.currentComputation.onInvalidate(handle.stop); } }; diff --git a/packages/past/past.js b/packages/past/past.js index 45b9b4fb66..ebc4fdbb6c 100644 --- a/packages/past/past.js +++ b/packages/past/past.js @@ -1,8 +1,8 @@ // Old under_score version of camelCase public API names. Meteor.is_client = Meteor.isClient; Meteor.is_server = Meteor.isServer; -Meteor.deps.Context.prototype.on_invalidate = - Meteor.deps.Context.prototype.onInvalidate; +//Meteor.deps.Context.prototype.on_invalidate = +// Meteor.deps.Context.prototype.onInvalidate; // See also the "this.is_simulation" assignment in livedata/livedata_common.js // and the retry_count and retry_time fields of self.current_status in // stream/stream_client.js. @@ -10,7 +10,7 @@ Meteor.deps.Context.prototype.on_invalidate = // We used to require a special "autosubscribe" call to reactively subscribe to // things. Now, it works with autorun. -Meteor.autosubscribe = Meteor.autorun; +Meteor.autosubscribe = Deps.autorun; // Instead of the "random" package with Random.id(), we used to have this // Meteor.uuid() implementing the RFC 4122 v4 UUID. diff --git a/packages/session/session.js b/packages/session/session.js index 226668cec0..9a42518a67 100644 --- a/packages/session/session.js +++ b/packages/session/session.js @@ -15,8 +15,8 @@ Session = _.extend({}, { keys: {}, // key -> value - keyDeps: {}, // key -> _ContextSet - keyValueDeps: {}, // key -> value -> _ContextSet + keyVars: {}, // key -> Variable + keyValueVars: {}, // key -> value -> Variable set: function (key, value) { var self = this; @@ -29,14 +29,14 @@ return; self.keys[key] = value; - var invalidateAll = function (cset) { - cset && cset.invalidateAll(); + var changed = function (v) { + v && v.changed(); }; - invalidateAll(self.keyDeps[key]); - if (self.keyValueDeps[key]) { - invalidateAll(self.keyValueDeps[key][oldSerializedValue]); - invalidateAll(self.keyValueDeps[key][value]); + changed(self.keyVars[key]); + if (self.keyValueVars[key]) { + changed(self.keyValueVars[key][oldSerializedValue]); + changed(self.keyValueVars[key][value]); } }, @@ -53,19 +53,18 @@ get: function (key) { var self = this; self._ensureKey(key); - self.keyDeps[key].addCurrentContext(); + Deps.depend(self.keyVars[key]); return parse(self.keys[key]); }, equals: function (key, value) { var self = this; - var context = Meteor.deps.Context.current; // We don't allow objects (or arrays that might include objects) for // .equals, because JSON.stringify doesn't canonicalize object key // order. (We can make equals have the right return value by parsing the // current value and using EJSON.equals, but we won't have a canonical - // element of keyValueDeps[key] to store the context.) You can still use + // element of keyValueVars[key] to store the dependency.) You can still use // "EJSON.equals(Session.get(key), value)". // // XXX we could allow arrays as long as we recursively check that there @@ -80,19 +79,19 @@ throw new Error("Session.equals: value must be scalar"); var serializedValue = stringify(value); - if (context) { + if (Deps.active) { self._ensureKey(key); - if (! _.has(self.keyValueDeps[key], serializedValue)) - self.keyValueDeps[key][serializedValue] = new Meteor.deps._ContextSet; + if (! _.has(self.keyValueVars[key], serializedValue)) + self.keyValueVars[key][serializedValue] = new Deps.Variable; - var isNew = self.keyValueDeps[key][serializedValue].add(context); + var isNew = Deps.depend(self.keyValueVars[key][serializedValue]); if (isNew) { - context.onInvalidate(function () { + Deps.currentComputation.onInvalidate(function () { // clean up [key][serializedValue] if it's now empty, so we don't // use O(n) memory for n = values seen ever - if (self.keyValueDeps[key][serializedValue].isEmpty()) - delete self.keyValueDeps[key][serializedValue]; + if (! self.keyValueVars[key][serializedValue].hasDependents()) + delete self.keyValueVars[key][serializedValue]; }); } } @@ -104,9 +103,9 @@ _ensureKey: function (key) { var self = this; - if (!(key in self.keyDeps)) { - self.keyDeps[key] = new Meteor.deps._ContextSet; - self.keyValueDeps[key] = {}; + if (!(key in self.keyVars)) { + self.keyVars[key] = new Deps.Variable; + self.keyValueVars[key] = {}; } } }); diff --git a/packages/session/session_tests.js b/packages/session/session_tests.js index 97b00d9762..f35261ca3c 100644 --- a/packages/session/session_tests.js +++ b/packages/session/session_tests.js @@ -105,7 +105,7 @@ Tinytest.add('session - context invalidation for get', function (test) { var xGetExecutions = 0; - Meteor.autorun(function () { + Deps.autorun(function () { ++xGetExecutions; Session.get('x'); }); @@ -113,44 +113,44 @@ Session.set('x', 1); // Invalidation shouldn't happen until flush time. test.equal(xGetExecutions, 1); - Meteor.flush(); + Deps.flush(); test.equal(xGetExecutions, 2); // Setting to the same value doesn't re-run. Session.set('x', 1); - Meteor.flush(); + Deps.flush(); test.equal(xGetExecutions, 2); Session.set('x', '1'); - Meteor.flush(); + Deps.flush(); test.equal(xGetExecutions, 3); }); Tinytest.add('session - context invalidation for equals', function (test) { var xEqualsExecutions = 0; - Meteor.autorun(function () { + Deps.autorun(function () { ++xEqualsExecutions; Session.equals('x', 5); }); test.equal(xEqualsExecutions, 1); Session.set('x', 1); - Meteor.flush(); + Deps.flush(); // Changing undefined -> 1 shouldn't affect equals(5). test.equal(xEqualsExecutions, 1); Session.set('x', 5); // Invalidation shouldn't happen until flush time. test.equal(xEqualsExecutions, 1); - Meteor.flush(); + Deps.flush(); test.equal(xEqualsExecutions, 2); Session.set('x', 5); - Meteor.flush(); + Deps.flush(); // Setting to the same value doesn't re-run. test.equal(xEqualsExecutions, 2); Session.set('x', '5'); test.equal(xEqualsExecutions, 2); - Meteor.flush(); + Deps.flush(); test.equal(xEqualsExecutions, 3); Session.set('x', 5); test.equal(xEqualsExecutions, 3); - Meteor.flush(); + Deps.flush(); test.equal(xEqualsExecutions, 4); }); @@ -159,27 +159,27 @@ function (test) { // Make sure the special casing for equals undefined works. var yEqualsExecutions = 0; - Meteor.autorun(function () { + Deps.autorun(function () { ++yEqualsExecutions; Session.equals('y', undefined); }); test.equal(yEqualsExecutions, 1); Session.set('y', undefined); - Meteor.flush(); + Deps.flush(); test.equal(yEqualsExecutions, 1); Session.set('y', 5); test.equal(yEqualsExecutions, 1); - Meteor.flush(); + Deps.flush(); test.equal(yEqualsExecutions, 2); Session.set('y', 3); - Meteor.flush(); + Deps.flush(); test.equal(yEqualsExecutions, 2); Session.set('y', 'undefined'); - Meteor.flush(); + Deps.flush(); test.equal(yEqualsExecutions, 2); Session.set('y', undefined); test.equal(yEqualsExecutions, 2); - Meteor.flush(); + Deps.flush(); test.equal(yEqualsExecutions, 3); }); }()); diff --git a/packages/spark/spark.js b/packages/spark/spark.js index 48533e30fc..1b63319728 100644 --- a/packages/spark/spark.js +++ b/packages/spark/spark.js @@ -352,7 +352,7 @@ var scheduleOnscreenSetup = function (frag, landmarkRanges) { finalized = true; }; - Meteor._atFlush(function () { + Deps.afterFlush(function () { if (finalized) return; @@ -807,7 +807,7 @@ Spark.attachEvents = withRenderer(function (eventMap, html, _renderer) { var landmark = (landmarkRange && landmarkRange.landmark); // Note that the handler can do arbitrary things, like call - // Meteor.flush() or otherwise remove and finalize parts of + // Deps.flush() or otherwise remove and finalize parts of // the DOM. We can't assume `range` is valid past this point, // and we'll check the `finalized` flag at the top of the loop. var returnValue = callback.call(eventData, event, landmark); @@ -837,20 +837,20 @@ Spark.isolate = function (htmlFunc) { var range; var firstRun = true; var retHtml; - Meteor.autorun(function (handle) { + Deps.autorun(function (handle) { if (firstRun) { retHtml = renderer.annotate( htmlFunc(), Spark._ANNOTATION_ISOLATE, function (r) { if (! r) { - // annotation not used; kill our context + // annotation not used; kill this autorun handle.stop(); } else { range = r; range.finalize = function () { // Spark.finalize() was called on our range (presumably // because it was removed from the document.) Kill - // this context and stop rerunning. + // this autorun. handle.stop(); }; } @@ -976,7 +976,7 @@ Spark.list = function (cursor, itemFunc, elseFunc) { }; var later = function (f) { - Meteor._atFlush(function () { + Deps.afterFlush(function () { if (! stopped) withEventGuard(f); }); @@ -1155,15 +1155,9 @@ Spark.createLandmark = function (options, htmlFunc) { landmark = new Spark.Landmark; if (options.created) { // Run callback outside the current Spark.isolate's deps context. - // XXX Can't call run() on null, so this is a hack. Running inside - // a fresh context wouldn't be equivalent. - var oldCx = Meteor.deps.Context.current; - Meteor.deps.Context.current = null; - try { + Deps.nonreactive(function () { options.created.call(landmark); - } finally { - Meteor.deps.Context.current = oldCx; - } + }); } } notes.landmark = landmark; diff --git a/packages/spark/spark_tests.js b/packages/spark/spark_tests.js index 6e3acdeaa2..d0c8a55952 100644 --- a/packages/spark/spark_tests.js +++ b/packages/spark/spark_tests.js @@ -163,7 +163,7 @@ Tinytest.add("spark - replace tag contents", function (test) { return R.get(); }); R.set("three four five six"); - Meteor.flush(); + Deps.flush(); test.equal(this.div.html(), "three four five six"); }); @@ -177,7 +177,7 @@ Tinytest.add("spark - replace tag contents", function (test) { test.equal($(this.node()).find("#morphing td").text(), "HI!"); R.set("BUH BYE!"); - Meteor.flush(); + Deps.flush(); test.equal($(this.node()).find("#morphing td").text(), "BUH BYE!"); }); @@ -191,7 +191,7 @@ Tinytest.add("spark - replace tag contents", function (test) { test.equal($(this.node()).find("#morphing td").text(), "HI!"); R.set("BUH BYE!"); - Meteor.flush(); + Deps.flush(); test.equal($(this.node()).find("#morphing td").text(), "BUH BYE!"); }); @@ -205,7 +205,7 @@ Tinytest.add("spark - replace tag contents", function (test) { test.equal($(this.node()).find("#morphing td").text(), "HI!"); R.set("BUH BYE!"); - Meteor.flush(); + Deps.flush(); test.equal($(this.node()).find("#morphing td").text(), "BUH BYE!"); }); @@ -219,7 +219,7 @@ Tinytest.add("spark - replace tag contents", function (test) { test.equal($(this.node()).find("#morphing li").text(), "HI!"); R.set("
  • BUH BYE!
  • "); - Meteor.flush(); + Deps.flush(); test.equal($(this.node()).find("#morphing li").text(), "BUH BYE!"); }); @@ -233,7 +233,7 @@ Tinytest.add("spark - replace tag contents", function (test) { test.equal($(this.node()).find("#morphing option").text(), "HI!"); R.set(""); - Meteor.flush(); + Deps.flush(); test.equal($(this.node()).find("#morphing option").text(), "BUH BYE!"); }); @@ -261,7 +261,7 @@ Tinytest.add("spark - replace tag contents", function (test) { '' + ''); c.insert({name: 'Chicken Snickers', value: 8}); - Meteor.flush(); + Deps.flush(); test.equal(furtherCanon(this.div.html()), ''); c.remove({value: 1}); c.remove({value: 2}); - Meteor.flush(); + Deps.flush(); test.equal(furtherCanon(this.div.html()), ''); c.remove({}); - Meteor.flush(); + Deps.flush(); test.equal(furtherCanon(this.div.html()), ''); c.insert({name: 'Hamburger', value: 1}); c.insert({name: 'Cheeseburger', value: 2}); - Meteor.flush(); + Deps.flush(); test.equal(furtherCanon(this.div.html()), ''; })).hold(); test.equal(get_checked(), true); - Meteor.flush(); + Deps.flush(); test.equal(get_checked(), true); R.set(false); test.equal(get_checked(), true); - Meteor.flush(); + Deps.flush(); test.equal(get_checked(), false); frag.release(); @@ -1440,19 +1440,19 @@ Tinytest.add("spark - preserve copies attributes", function(test) { var if_blurred = function(v, v2) { return with_focus ? v2 : v; }; test.equal(get_value(), "apple"); - Meteor.flush(); + Deps.flush(); test.equal(get_value(), "apple"); R.set(""); test.equal(get_value(), "apple"); - Meteor.flush(); + Deps.flush(); test.equal(get_value(), if_blurred("", "apple")); R.set("pear"); test.equal(get_value(), if_blurred("", "apple")); - Meteor.flush(); + Deps.flush(); test.equal(get_value(), if_blurred("pear", "apple")); set_value("jerry"); // like user typing R.set("steve"); - Meteor.flush(); + Deps.flush(); // should overwrite user typing if blurred test.equal(get_value(), if_blurred("steve", "jerry")); div.kill(); @@ -1462,14 +1462,14 @@ Tinytest.add("spark - preserve copies attributes", function(test) { })); maybe_focus(div); test.equal(get_value(), ""); - Meteor.flush(); + Deps.flush(); test.equal(get_value(), ""); R.set("tom"); test.equal(get_value(), ""); - Meteor.flush(); + Deps.flush(); test.equal(get_value(), if_blurred("tom", "")); div.kill(); - Meteor.flush(); + Deps.flush(); }); }); @@ -1484,7 +1484,7 @@ Tinytest.add("spark - bad labels", function(test) { })).hold(); R.set(false); - Meteor.flush(); + Deps.flush(); test.equal(frag.html(), html2); frag.release(); }; @@ -1653,14 +1653,14 @@ Tinytest.add("spark - landmark patching", function(test) { fillInElementIdentities(structure, frag.node()); var labeledNodes = collectLabeledNodeData(structure); R.set(true); - Meteor.flush(); + Deps.flush(); test.equal(frag.html(), nodeListToHtml(structure, true) || ""); _.each(labeledNodes, function(x) { test.isTrue(isSameElements(x.parents, getParentChain(x.node))); }); frag.release(); - Meteor.flush(); + Deps.flush(); test.equal(R.numListeners(), 0); } @@ -1686,10 +1686,10 @@ Tinytest.add("spark - landmark constant", function(test) { var nodes = nodesToArray(div.node().childNodes); test.equal(nodes.length, 3); - Meteor.flush(); + Deps.flush(); test.equal(states.length, 1); R.set(1); - Meteor.flush(); + Deps.flush(); test.equal(states.length, 1); // no render callback on constant var nodes2 = nodesToArray(div.node().childNodes); test.equal(nodes2.length, 3); @@ -1697,7 +1697,7 @@ Tinytest.add("spark - landmark constant", function(test) { test.isTrue(nodes[1] === nodes2[1]); test.isTrue(nodes[2] === nodes2[2]); div.kill(); - Meteor.flush(); + Deps.flush(); test.equal(R.numListeners(), 0); // non-top-level @@ -1746,7 +1746,7 @@ Tinytest.add("spark - landmark constant", function(test) { (nodeAfter ? 'foo' : '')); R.set('bar'); - Meteor.flush(); + Deps.flush(); // only non-matching landmark should cause the constant // chunk to be re-rendered @@ -1760,7 +1760,7 @@ Tinytest.add("spark - landmark constant", function(test) { test.equal(crd, matchLandmark ? [1,1,0] : [1,1,1]); R.set('baz'); - Meteor.flush(); + Deps.flush(); // should be repeatable (liveranges not damaged) test.equal(div.text(), @@ -1770,7 +1770,7 @@ Tinytest.add("spark - landmark constant", function(test) { isConstant = false; // no longer constant:true! R.set('qux'); - Meteor.flush(); + Deps.flush(); test.equal(div.text(), (nodeBefore ? 'qux' : '')+ 'blah'+ @@ -1780,7 +1780,7 @@ Tinytest.add("spark - landmark constant", function(test) { isConstant = true; hasSpan = true; R.set('popsicle'); - Meteor.flush(); + Deps.flush(); // we don't get the span, instead old "blah" is preserved test.equal(div.text(), (nodeBefore ? 'popsicle' : '')+ @@ -1789,7 +1789,7 @@ Tinytest.add("spark - landmark constant", function(test) { isConstant = false; R.set('hi'); - Meteor.flush(); + Deps.flush(); // now we get the span! test.equal(div.text(), (nodeBefore ? 'hi' : '')+ @@ -1797,7 +1797,7 @@ Tinytest.add("spark - landmark constant", function(test) { (nodeAfter ? 'hi' : '')); div.kill(); - Meteor.flush(); + Deps.flush(); }); }); }); @@ -1817,26 +1817,26 @@ Tinytest.add("spark - landmark constant", function(test) { }) + ''; })); - Meteor.flush(); + Deps.flush(); test.equal(renderCount, 1); R.set('div class="hamburger"'); - Meteor.flush(); + Deps.flush(); // constant patched around, not re-rendered! test.equal(renderCount, 1); R.set('span class="hamburger"'); - Meteor.flush(); + Deps.flush(); // can't patch parent to a different tag test.equal(renderCount, 2); R.set('span'); - Meteor.flush(); + Deps.flush(); // can patch here, renderCount stays the same test.equal(renderCount, 2); div.kill(); - Meteor.flush(); + Deps.flush(); }); _.each(['STRING', 'MONGO'], function (idGeneration) { @@ -1902,13 +1902,13 @@ Tinytest.add("spark - leaderboard, " + idGeneration, function(test) { }); }; - Meteor.flush(); + Deps.flush(); var glinnesNameNode = findPlayerNameDiv(names[0]); test.isTrue(!! glinnesNameNode); var glinnesScoreNode = glinnesNameNode.nextSibling; test.equal(glinnesScoreNode.getAttribute("name"), "score"); clickElement(glinnesNameNode); - Meteor.flush(); + Deps.flush(); glinnesNameNode = findPlayerNameDiv(names[0]); test.isTrue(!! glinnesNameNode); test.equal(glinnesNameNode.parentNode.className, 'player selected'); @@ -1920,7 +1920,7 @@ Tinytest.add("spark - leaderboard, " + idGeneration, function(test) { '
    Glinnes Hulden
    0
    '); bump(); - Meteor.flush(); + Deps.flush(); glinnesNameNode = findPlayerNameDiv(names[0], glinnesNameNode); var glinnesScoreNode2 = glinnesNameNode.nextSibling; @@ -1934,7 +1934,7 @@ Tinytest.add("spark - leaderboard, " + idGeneration, function(test) { '
    Glinnes Hulden
    5
    '); bump(); - Meteor.flush(); + Deps.flush(); glinnesNameNode = findPlayerNameDiv(names[0], glinnesNameNode); test.equal( @@ -1942,7 +1942,7 @@ Tinytest.add("spark - leaderboard, " + idGeneration, function(test) { '
    Glinnes Hulden
    10
    '); scores.kill(); - Meteor.flush(); + Deps.flush(); test.equal(selected_player.numListeners(), 0); }); }); @@ -1970,7 +1970,7 @@ Tinytest.add("spark - list cursor stop", function(test) { return "#"+doc._id; }); test.equal(result, "#123#456"); - Meteor.flush(); + Deps.flush(); // chunk killed because not created inside Spark.render test.equal(numHandles, 0); @@ -1982,17 +1982,17 @@ Tinytest.add("spark - list cursor stop", function(test) { return ""; })).hold(); test.equal(numHandles, 1); - Meteor.flush(); + Deps.flush(); test.equal(numHandles, 1); R.set(2); - Meteor.flush(); + Deps.flush(); test.equal(numHandles, 1); R.set(-1); - Meteor.flush(); + Deps.flush(); test.equal(numHandles, 0); frag.release(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("spark - list table", function(test) { @@ -2032,7 +2032,7 @@ Tinytest.add("spark - list table", function(test) { var shouldFlushTo = function(html) { // same before flush test.equal(table.html(), lastHtml); - Meteor.flush(); + Deps.flush(); test.equal(table.html(), html); lastHtml = html; }; @@ -2197,7 +2197,7 @@ Tinytest.add("spark - list event data", function(test) { }; later(); - Meteor.flush(); + Deps.flush(); test.equal(item("Foo").innerHTML, "Foo"); test.equal(item("Bar").innerHTML, "Bar"); test.equal(item("Baz").innerHTML, "Baz"); @@ -2206,7 +2206,7 @@ Tinytest.add("spark - list event data", function(test) { var doClick = function(name) { clickElement(item(name)); test.equal(lastClicked, name); - Meteor.flush(); + Deps.flush(); }; doClick("Foo"); @@ -2228,7 +2228,7 @@ Tinytest.add("spark - list event data", function(test) { doClick("Foo"); div.kill(); - Meteor.flush(); + Deps.flush(); }); @@ -2257,12 +2257,12 @@ Tinytest.add("spark - events on preserved nodes", function(test) { test.equal(count.get(), 0); for(var i=0; i<10; i++) { click(); - Meteor.flush(); + Deps.flush(); test.equal(count.get(), i+1); } demo.kill(); - Meteor.flush(); + Deps.flush(); }); @@ -2294,32 +2294,32 @@ Tinytest.add("spark - cleanup", function(test) { })); test.equal(div.text(), "x1"); - Meteor.flush(); + Deps.flush(); test.equal(div.text(), "x1"); test.equal(R.numListeners(), 1); clear_docs(); - Meteor.flush(); + Deps.flush(); test.equal(div.text(), "x0"); test.equal(R.numListeners(), 1); // test clean-up of doc on remove add_doc(); - Meteor.flush(); + Deps.flush(); test.equal(div.text(), "x1"); test.equal(R.numListeners(), 1); // test clean-up of "else" listeners add_doc(); - Meteor.flush(); + Deps.flush(); test.equal(div.text(), "x1x1"); test.equal(R.numListeners(), 2); remove_one(); - Meteor.flush(); + Deps.flush(); test.equal(div.text(), "x1"); test.equal(R.numListeners(), 1); // test clean-up of doc with other docs div.kill(); - Meteor.flush(); + Deps.flush(); test.equal(R.numListeners(), 0); //// list stopped if not materialized @@ -2352,7 +2352,7 @@ Tinytest.add("spark - cleanup", function(test) { test.equal([observeCount, stopCount], [1, 1]); div.kill(); - Meteor.flush(); + Deps.flush(); }); @@ -2409,14 +2409,14 @@ var make_input_tester = function(render_func, events) { kill: function() { // clean up div.kill(); - Meteor.flush(); + Deps.flush(); }, inputNode: function() { return div.node().getElementsByTagName("input")[0]; }, redraw: function() { R.set(R.get() + 1); - Meteor.flush(); + Deps.flush(); } }; }; @@ -2637,7 +2637,7 @@ testAsyncMulti( _.each(hitlist, function(thing) { thing.kill(); }); - Meteor.flush(); + Deps.flush(); } ]; })()); @@ -2681,7 +2681,7 @@ Tinytest.add("spark - controls - radio", function(test) { return html; })); - Meteor.flush(); + Deps.flush(); // get the three buttons; they should be considered 'labeled' // by the patcher and not change identities! @@ -2693,12 +2693,12 @@ Tinytest.add("spark - controls - radio", function(test) { clickElement(btns[0]); test.equal(change_buf, ['AM']); change_buf.length = 0; - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(btns, 'checked'), [true, false, false]); test.equal(div.text(), "Band: AM"); R2.set("change"); - Meteor.flush(); + Deps.flush(); test.length(change_buf, 0); test.equal(_.pluck(btns, 'checked'), [true, false, false]); test.equal(div.text(), "Band: AM"); @@ -2706,21 +2706,21 @@ Tinytest.add("spark - controls - radio", function(test) { clickElement(btns[1]); test.equal(change_buf, ['FM']); change_buf.length = 0; - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(btns, 'checked'), [false, true, false]); test.equal(div.text(), "Band: FM"); clickElement(btns[2]); test.equal(change_buf, ['XM']); change_buf.length = 0; - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(btns, 'checked'), [false, false, true]); test.equal(div.text(), "Band: XM"); clickElement(btns[1]); test.equal(change_buf, ['FM']); change_buf.length = 0; - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(btns, 'checked'), [false, true, false]); test.equal(div.text(), "Band: FM"); @@ -2744,7 +2744,7 @@ Tinytest.add("spark - controls - checkbox", function(test) { return buf.join(''); })); - Meteor.flush(); + Deps.flush(); // get the three boxes; they should be considered 'labeled' by the patcher and // not change identities! @@ -2754,42 +2754,42 @@ Tinytest.add("spark - controls - checkbox", function(test) { // Re-render with first one checked. Rs.Foo.set(true); - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(boxes, 'checked'), [true, false, false]); // Re-render with first one unchecked again. Rs.Foo.set(false); - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(boxes, 'checked'), [false, false, false]); // User clicks the second one. clickElement(boxes[1]); test.equal(_.pluck(boxes, 'checked'), [false, true, false]); - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(boxes, 'checked'), [false, true, false]); // Re-render with third one checked. Second one should stay checked because // it's a user update! Rs.Baz.set(true); - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(boxes, 'checked'), [false, true, true]); // User turns second and third off. clickElement(boxes[1]); clickElement(boxes[2]); test.equal(_.pluck(boxes, 'checked'), [false, false, false]); - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(boxes, 'checked'), [false, false, false]); // Re-render with first one checked. Third should stay off because it's a user // update! Rs.Foo.set(true); - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(boxes, 'checked'), [true, false, false]); // Re-render with first one unchecked. Third should still stay off. Rs.Foo.set(false); - Meteor.flush(); + Deps.flush(); test.equal(_.pluck(boxes, 'checked'), [false, false, false]); div.kill(); @@ -2833,7 +2833,7 @@ _.each(['textarea', 'text', 'password', 'submit', 'button', // value updates reactively R.set({x:"fridge"}); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.getElementValue(input), "This is a fridge"); test.equal(input._sparkOriginalRenderedValue, ["This is a fridge"]); @@ -2841,18 +2841,18 @@ _.each(['textarea', 'text', 'password', 'submit', 'button', // ...unless focused focusElement(input); R.set({x:"frog"}); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.getElementValue(input), "This is a fridge"); test.equal(input._sparkOriginalRenderedValue, ["This is a fridge"]); // blurring and re-setting works blurElement(input); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.getElementValue(input), "This is a fridge"); test.equal(input._sparkOriginalRenderedValue, ["This is a fridge"]); } R.set({x:"frog"}); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.getElementValue(input), "This is a frog"); test.equal(input._sparkOriginalRenderedValue, ["This is a frog"]); @@ -2861,13 +2861,13 @@ _.each(['textarea', 'text', 'password', 'submit', 'button', // not change. DomUtils.setElementValue(input, "foobar"); R2.set("change"); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.getElementValue(input), "foobar"); test.equal(input._sparkOriginalRenderedValue, ["This is a frog"]); // ... but if the actual rendered value changes, that should take effect. R.set({x:"photograph"}); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.getElementValue(input), "This is a photograph"); test.equal(input._sparkOriginalRenderedValue, ["This is a photograph"]); @@ -2877,7 +2877,7 @@ _.each(['textarea', 'text', 'password', 'submit', 'button', // gets updated too. DomUtils.setElementValue(input, "This is a monkey"); R.set({x:"monkey"}); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.getElementValue(input), "This is a monkey"); test.equal(input._sparkOriginalRenderedValue, ["This is a monkey"]); @@ -2889,7 +2889,7 @@ _.each(['textarea', 'text', 'password', 'submit', 'button', DomUtils.setElementValue(input, "This is a donkey"); focusElement(input); R.set({x:"donkey"}); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.getElementValue(input), "This is a donkey"); test.equal(input._sparkOriginalRenderedValue, ["This is a donkey"]); } @@ -2938,18 +2938,18 @@ Tinytest.add("spark - oldschool landmark matching", function(test) { test.equal(buf, ["c0"]); test.equal(div.html(), "A"); - Meteor.flush(); + Deps.flush(); test.equal(buf, ["c0", "r0"]); test.equal(div.html(), "A"); R.set("B"); - Meteor.flush(); + Deps.flush(); test.equal(buf, ["c0", "r0", "r0"]); test.equal(div.html(), "B"); div.kill(); - Meteor.flush(); + Deps.flush(); test.equal(buf, ["c0", "r0", "r0", "d0"]); // with a branch @@ -2969,19 +2969,19 @@ Tinytest.add("spark - oldschool landmark matching", function(test) { })); test.equal(buf, ["c0", "c1"]); - Meteor.flush(); + Deps.flush(); // what order of chunks {0,1} is preferable?? // should be consistent but I'm not sure what makes most sense. test.equal(buf, "c0,c1,r1,r0".split(',')); buf.length = 0; R.set("B"); - Meteor.flush(); + Deps.flush(); test.equal(buf, "r1,r0".split(',')); buf.length = 0; div.kill(); - Meteor.flush(); + Deps.flush(); buf.sort(); test.equal(buf, "d0,d1".split(',')); }); @@ -3001,18 +3001,18 @@ Tinytest.add("spark - oldschool branch keys", function(test) { }, function () { return R.get(); }); })); - Meteor.flush(); + Deps.flush(); R.set("bar"); - Meteor.flush(); + Deps.flush(); R.set("baz"); - Meteor.flush(); + Deps.flush(); test.equal(objs.length, 3); test.isTrue(objs[0] === objs[1]); test.isTrue(objs[1] === objs[2]); div.kill(); - Meteor.flush(); + Deps.flush(); // track chunk matching / re-rendering in detail @@ -3077,25 +3077,25 @@ Tinytest.add("spark - oldschool branch keys", function(test) { ], 1, 'fruit'); })); - Meteor.flush(); + Deps.flush(); buf.sort(); test.equal(buf, ['c1', 'c2', 'c3', 'c4', 'on1', 'on2', 'on3', 'on4']); buf.length = 0; R.set("bar"); - Meteor.flush(); + Deps.flush(); buf.sort(); test.equal(buf, ['on1', 'on2', 'on3', 'on4']); buf.length = 0; R.set("nothing"); - Meteor.flush(); + Deps.flush(); buf.sort(); test.equal(buf, ['off1', 'off2', 'off3', 'off4']); buf.length = 0; div.kill(); - Meteor.flush(); + Deps.flush(); ///// Chunk 3 has no branch key, should be recreated @@ -3113,19 +3113,19 @@ Tinytest.add("spark - oldschool branch keys", function(test) { ], 1, 'fruit'); })); - Meteor.flush(); + Deps.flush(); buf.sort(); test.equal(buf, ['c1', 'c2', 'c3', 'c4', 'on1', 'on2', 'on3', 'on4']); buf.length = 0; R.set("bar"); - Meteor.flush(); + Deps.flush(); buf.sort(); test.equal(buf, ['c3*', 'off3', 'on1', 'on2', 'on3*', 'on4']); buf.length = 0; div.kill(); - Meteor.flush(); + Deps.flush(); buf.sort(); // killing the div should have given us offscreen calls for 1,2,3*,4 test.equal(buf, ['off1', 'off2', 'off3*', 'off4']); @@ -3156,12 +3156,12 @@ Tinytest.add("spark - isolate inside landmark", function (test) { var foo1 = d.node().firstChild; test.equal(d.node().firstChild.nextSibling.nodeValue, '1'); R.set(2); - Meteor.flush(); + Deps.flush(); var foo2 = d.node().firstChild; test.equal(d.node().firstChild.nextSibling.nodeValue, '2'); test.isTrue(foo1 === foo2); d.kill(); - Meteor.flush(); + Deps.flush(); // test that selectors in a landmark preservation map are resolved // relative to the landmark, not relative to the re-rendered @@ -3183,13 +3183,13 @@ Tinytest.add("spark - isolate inside landmark", function (test) { test.equal(foo1.nodeName, 'HR'); test.equal(foo1.nextSibling.nodeValue, '1'); R.set(2); - Meteor.flush(); + Deps.flush(); var foo2 = DomUtils.find(d.node(), '.foo'); test.equal(foo2.nodeName, 'HR'); test.equal(foo2.nextSibling.nodeValue, '2'); test.isTrue(foo1 === foo2); d.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("spark - nested onscreen processing", function (test) { @@ -3212,11 +3212,11 @@ Tinytest.add("spark - nested onscreen processing", function (test) { }); })); - Meteor.flush(); + Deps.flush(); test.equal(x.join(''), 'cr'); x = []; d.kill(); - Meteor.flush(); + Deps.flush(); test.equal(x.join(''), 'd'); }); @@ -3341,7 +3341,7 @@ Tinytest.add("spark - current landmark", function (test) { }; test.equal(callbacks, 1); - Meteor.flush(); + Deps.flush(); test.equal(callbacks, 2); test.equal(null, Spark._getEnclosingLandmark(d.node())); var enc = Spark._getEnclosingLandmark(d.node().firstChild); @@ -3349,15 +3349,15 @@ Tinytest.add("spark - current landmark", function (test) { test.equal(enc.b, 2); test.isFalse('c' in enc); enc.c = 3; - Meteor.flush(); + Deps.flush(); test.equal(callbacks, 2); R.set(2) - Meteor.flush(); + Deps.flush(); test.equal(callbacks, 3); R.set(3) - Meteor.flush(); + Deps.flush(); test.equal(callbacks, 4); test.isTrue(Spark._getEnclosingLandmark(findOuter()).outer); @@ -3368,30 +3368,30 @@ Tinytest.add("spark - current landmark", function (test) { test.equal(1, Spark._getEnclosingLandmark(findInnerB()).renderCount); R.set(4) - Meteor.flush(); + Deps.flush(); test.equal(callbacks, 5); test.equal(2, Spark._getEnclosingLandmark(findOuter()).renderCount); test.equal(2, Spark._getEnclosingLandmark(findInnerA()).renderCount); R.set(5) - Meteor.flush(); + Deps.flush(); test.equal(callbacks, 6); test.equal(3, Spark._getEnclosingLandmark(findOuter()).renderCount); test.equal(3, Spark._getEnclosingLandmark(findInnerA()).renderCount); test.equal(1, Spark._getEnclosingLandmark(findInnerB()).renderCount); R.set(6) - Meteor.flush(); + Deps.flush(); test.equal(callbacks, 7); test.equal(4, Spark._getEnclosingLandmark(findOuter()).renderCount); test.equal(4, Spark._getEnclosingLandmark(findInnerA()).renderCount); test.equal(2, Spark._getEnclosingLandmark(findInnerB()).renderCount); d.kill(); - Meteor.flush(); + Deps.flush(); test.equal(callbacks, 8); - Meteor.flush(); + Deps.flush(); test.equal(callbacks, 8); }); @@ -3461,12 +3461,12 @@ Tinytest.add("spark - find/findAll on landmark", function (test) { check(false); check(true); R.set(2); - Meteor.flush(); + Deps.flush(); check(false); check(true); d.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("spark - landmark clean-up", function (test) { @@ -3495,7 +3495,7 @@ Tinytest.add("spark - landmark clean-up", function (test) { return ''; }); test.equal(crd, [1,0,1]); - Meteor.flush(); + Deps.flush(); test.equal(crd, [1,0,1]); // two landmarks, only one materialized at a time. @@ -3510,16 +3510,16 @@ Tinytest.add("spark - landmark clean-up", function (test) { })); test.equal(crd1, [1,0,0]); // created test.equal(crd2, [0,0,0]); - Meteor.flush(); + Deps.flush(); test.equal(crd1, [1,1,0]); // rendered test.equal(crd2, [0,0,0]); R.set(2); - Meteor.flush(); + Deps.flush(); test.equal(crd1, [1,1,0]); // not destroyed (callback replaced) test.equal(crd2, [0,1,0]); // matched div.kill(); - Meteor.flush(); + Deps.flush(); test.equal(crd1, [1,1,0]); test.equal(crd2, [0,1,1]); // destroyed }); @@ -3551,19 +3551,19 @@ Tinytest.add("spark - bubbling render", function (test) { }); })); - Meteor.flush(); + Deps.flush(); test.equal(div.html(), 'foo'); test.equal(crd1, [1,1,0]); test.equal(crd2, [1,1,0]); R.set('bar'); - Meteor.flush(); + Deps.flush(); test.equal(div.html(), 'bar'); test.equal(crd1, [1,2,0]); test.equal(crd2, [1,2,0]); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("spark - landmark arg", function (test) { @@ -3596,13 +3596,13 @@ Tinytest.add("spark - landmark arg", function (test) { })); test.equal(div.text(), "Foo Bar Baz"); - Meteor.flush(); + Deps.flush(); test.equal(div.text(), "Greetings 1-bold Line"); clickElement(DomUtils.find(div.node(), 'i')); test.equal(div.text(), "Hello 3-element World"); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("spark - landmark preserve", function (test) { @@ -3623,7 +3623,7 @@ Tinytest.add("spark - landmark preserve", function (test) { test.equal(div.html(), '
    foo

    '); var hrs1 = DomUtils.findAll(div.node(), 'hr'); R.set("bar"); - Meteor.flush(); + Deps.flush(); test.equal(div.html(), '
    bar

    '); var hrs2 = DomUtils.findAll(div.node(), 'hr'); @@ -3631,7 +3631,7 @@ Tinytest.add("spark - landmark preserve", function (test) { test.isTrue(hrs1[1] === hrs2[1]); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("spark - branch annotation is optional", function (test) { @@ -3660,7 +3660,7 @@ Tinytest.add("spark - branch annotation is optional", function (test) { var div1 = div.node().firstChild; var hrs1 = DomUtils.findAll(div.node(), 'hr'); R.set("bar"); - Meteor.flush(); + Deps.flush(); test.equal(div.html(), '


    '); var div2 = div.node().firstChild; var hrs2 = DomUtils.findAll(div.node(), 'hr'); @@ -3670,7 +3670,7 @@ Tinytest.add("spark - branch annotation is optional", function (test) { test.isTrue(hrs1[1] === hrs2[1]); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("spark - unique label", function (test) { @@ -3696,14 +3696,14 @@ Tinytest.add("spark - unique label", function (test) { var div = OnscreenDiv(Meteor.render(function () { return ublm() + ublm() + ublm() + R.get(); })); - Meteor.flush(); + Deps.flush(); test.equal(bufstr(), 'cccrrr'); R.set('bar'); - Meteor.flush(); + Deps.flush(); test.equal(bufstr(), 'cccdddrrr'); div.kill(); - Meteor.flush(); + Deps.flush(); test.equal(bufstr(), 'ddd'); }); @@ -3738,21 +3738,21 @@ Tinytest.add("spark - list update", function (test) { })); lst.another(); - Meteor.flush(); + Deps.flush(); test.equal(div.html(), "foo
    "); lst.another(); R.set('bar'); - Meteor.flush(); + Deps.flush(); test.equal(div.html(), "bar

    "); R.set('baz'); lst.another(); - Meteor.flush(); + Deps.flush(); test.equal(div.html(), "baz


    "); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("spark - callback context", function (test) { @@ -3762,7 +3762,7 @@ Tinytest.add("spark - callback context", function (test) { var buf = []; var R = ReactiveVar("foo"); - var getCx = function () { return Meteor.deps.Context.current; }; + var getCx = function () { return Deps.currentComputation; }; var callbackFunc = function (ltr) { return function () { buf.push(ltr); @@ -3786,11 +3786,11 @@ Tinytest.add("spark - callback context", function (test) { test.isTrue(getCx() === cx); // test that context was restored return html; })); - Meteor.flush(); + Deps.flush(); R.set('bar'); - Meteor.flush(); + Deps.flush(); div.kill(); - Meteor.flush(); + Deps.flush(); test.equal(buf.join(''), 'ccdrrd'); test.equal(cxs.length, 6); @@ -3820,7 +3820,7 @@ Tinytest.add("spark - legacy preserve names", function (test) { var inputs1 = nodesToArray(div.node().getElementsByTagName('input')); R.set('bar'); - Meteor.flush(); + Deps.flush(); var inputs2 = nodesToArray(div.node().getElementsByTagName('input')); test.isTrue(inputs1[0] === inputs2[0]); test.isTrue(inputs1[1] === inputs2[1]); @@ -3828,12 +3828,12 @@ Tinytest.add("spark - legacy preserve names", function (test) { test.isTrue(inputs1[3] !== inputs2[3]); R2.set('banana'); - Meteor.flush(); + Deps.flush(); var inputs3 = nodesToArray(div.node().getElementsByTagName('input')); test.isTrue(inputs1[2] === inputs3[2]); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("spark - update defunct range", function (test) { @@ -3852,13 +3852,13 @@ Tinytest.add("spark - update defunct range", function (test) { test.equal(div.html(), "

    foo

    "); R.set("bar"); - Meteor.flush(); + Deps.flush(); test.equal(R.numListeners(), 1); test.equal(div.html(), "

    bar

    "); test.equal(div.node().firstChild.nodeName, "P"); div.node().firstChild.innerHTML = ''; R.set("baz"); - Meteor.flush(); // should throw no errors + Deps.flush(); // should throw no errors // will be 1 if our isolate func was run. test.equal(R.numListeners(), 0); @@ -3876,13 +3876,13 @@ Tinytest.add("spark - update defunct range", function (test) { test.equal(div.html(), "

    foo

    "); R.set("bar"); - Meteor.flush(); + Deps.flush(); test.equal(R.numListeners(), 1); test.equal(div.html(), "

    bar

    "); test.equal(div.node().firstChild.nodeName, "P"); div.node().firstChild.innerHTML = ''; R.set("baz"); - Meteor.flush(); // should throw no errors + Deps.flush(); // should throw no errors // will be 1 if our isolate func was run. test.equal(R.numListeners(), 0); diff --git a/packages/spiderable/spiderable.js b/packages/spiderable/spiderable.js index 5d617fab5e..d9e915f243 100644 --- a/packages/spiderable/spiderable.js +++ b/packages/spiderable/spiderable.js @@ -41,7 +41,7 @@ " if (typeof Meteor !== 'undefined' " + " && typeof(Meteor.status) !== 'undefined' " + " && Meteor.status().connected) {" + - " Meteor.flush();" + + " Deps.flush();" + " return Meteor._LivedataConnection._allSubscriptionsReady();" + " }" + " return false;" + diff --git a/packages/stream/stream_client.js b/packages/stream/stream_client.js index 1474e29173..60b6fb27a8 100644 --- a/packages/stream/stream_client.js +++ b/packages/stream/stream_client.js @@ -47,10 +47,10 @@ Meteor._Stream = function (url) { retry_count: 0 }; - self.status_listeners = (Meteor.deps && new Meteor.deps._ContextSet); + self.status_listeners = window.Deps && new Deps.Variable; self.status_changed = function () { if (self.status_listeners) - self.status_listeners.invalidateAll(); + self.status_listeners.changed(); }; //// Retry logic @@ -139,7 +139,7 @@ _.extend(Meteor._Stream.prototype, { status: function () { var self = this; if (self.status_listeners) - self.status_listeners.addCurrentContext(); + Deps.depend(self.status_listeners); return self.current_status; }, diff --git a/packages/templating/templating_tests.js b/packages/templating/templating_tests.js index 5c3d9717e5..469ebeb200 100644 --- a/packages/templating/templating_tests.js +++ b/packages/templating/templating_tests.js @@ -18,10 +18,10 @@ Tinytest.add("templating - assembly", function (test) { document.body.appendChild(onscreen); test.equal(canonicalizeHtml(onscreen.innerHTML), "xyhi"); Session.set("stuff", false); - Meteor.flush(); + Deps.flush(); test.equal(canonicalizeHtml(onscreen.innerHTML), "xhi"); document.body.removeChild(onscreen); - Meteor.flush(); + Deps.flush(); }); // Test that if a template throws an error, then pending_partials is @@ -71,7 +71,7 @@ Tinytest.add("templating - table assembly", function(test) { document.body.removeChild(onscreen); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("templating - event handler this", function(test) { @@ -111,7 +111,7 @@ Tinytest.add("templating - event handler this", function(test) { event_buf.length = 0; tmpl.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("templating - safestring", function(test) { @@ -345,7 +345,7 @@ Tinytest.add("templating - rendered template", function(test) { test.isTrue(hr1); R.set('bar'); - Meteor.flush(); + Deps.flush(); var br2 = div.node().getElementsByTagName('br')[0]; var hr2 = div.node().getElementsByTagName('hr')[0]; test.isTrue(br2); @@ -354,7 +354,7 @@ Tinytest.add("templating - rendered template", function(test) { test.isFalse(hr1 === hr2); div.kill(); - Meteor.flush(); + Deps.flush(); ///// @@ -379,7 +379,7 @@ Tinytest.add("templating - rendered template", function(test) { test.isTrue(hr1); R.set('bar'); - Meteor.flush(); + Deps.flush(); var br2 = div.node().getElementsByTagName('br')[0]; var hr2 = div.node().getElementsByTagName('hr')[0]; test.isTrue(br2); @@ -388,7 +388,7 @@ Tinytest.add("templating - rendered template", function(test) { test.isFalse(hr1 === hr2); div.kill(); - Meteor.flush(); + Deps.flush(); ///// @@ -409,7 +409,7 @@ Tinytest.add("templating - rendered template", function(test) { test.isTrue(hr1); stuff.update({foo:'bar'}, {$set: {foo: 'baz'}}); - Meteor.flush(); + Deps.flush(); var br2 = div.node().getElementsByTagName('br')[0]; var hr2 = div.node().getElementsByTagName('hr')[0]; test.isTrue(br2); @@ -418,7 +418,7 @@ Tinytest.add("templating - rendered template", function(test) { test.isFalse(hr1 === hr2); div.kill(); - Meteor.flush(); + Deps.flush(); ///// @@ -436,7 +436,7 @@ Tinytest.add("templating - rendered template", function(test) { test.isTrue(hr1); stuff.update({foo:'bar'}, {$set: {foo: 'baz'}}); - Meteor.flush(); + Deps.flush(); var br2 = div.node().getElementsByTagName('br')[0]; var hr2 = div.node().getElementsByTagName('hr')[0]; test.isTrue(br2); @@ -445,7 +445,7 @@ Tinytest.add("templating - rendered template", function(test) { test.isFalse(hr1 === hr2); div.kill(); - Meteor.flush(); + Deps.flush(); }); @@ -477,12 +477,12 @@ Tinytest.add("templating - branch labels", function(test) { }; var div = OnscreenDiv(Meteor.render(Template.test_branches_a)); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.find(div.node(), 'span').innerHTML, 'foo'); test.equal(elems.length, 3); R.set('bar'); - Meteor.flush(); + Deps.flush(); var elems2 = DomUtils.findAll(div.node(), 'hr'); elems2.sort(function(a, b) { return a.myIndex - b.myIndex; }); test.equal(elems[0], elems2[0]); @@ -491,7 +491,7 @@ Tinytest.add("templating - branch labels", function(test) { test.equal(DomUtils.find(div.node(), 'span').innerHTML, 'bar'); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("templating - matching in list", function (test) { @@ -519,7 +519,7 @@ Tinytest.add("templating - matching in list", function (test) { var R = ReactiveVar('foo'); var div = OnscreenDiv(Spark.render(Template.test_listmatching_a0)); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.find(div.node(), 'span').innerHTML, 'foo'); test.equal(div.html().match(/

    (.*?)<\/p>/)[1].match(/\S+/g), ['a','b','c']); @@ -527,13 +527,13 @@ Tinytest.add("templating - matching in list", function (test) { buf.length = 0; R.set('bar'); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.find(div.node(), 'span').innerHTML, 'bar'); test.equal(div.html().match(/

    (.*?)<\/p>/)[1].match(/\S+/g), ['a','b','c']); test.equal(buf.join(''), '*a*b*c'); div.kill(); - Meteor.flush(); + Deps.flush(); }); @@ -560,19 +560,19 @@ Tinytest.add("templating - isolate helper", function (test) { test.equal(getTallies().join(','), str); }; - Meteor.flush(); + Deps.flush(); expect("1,1,1,1"); - bump(1); Meteor.flush(); expect("2,2,2,2"); - bump(2); Meteor.flush(); expect("2,3,3,3"); - bump(3); Meteor.flush(); expect("2,3,4,4"); - bump(4); Meteor.flush(); expect("2,3,4,5"); - Meteor.flush(); expect("2,3,4,5"); - bump(3); Meteor.flush(); expect("2,3,5,6"); - bump(2); Meteor.flush(); expect("2,4,6,7"); - bump(1); Meteor.flush(); expect("3,5,7,8"); + bump(1); Deps.flush(); expect("2,2,2,2"); + bump(2); Deps.flush(); expect("2,3,3,3"); + bump(3); Deps.flush(); expect("2,3,4,4"); + bump(4); Deps.flush(); expect("2,3,4,5"); + Deps.flush(); expect("2,3,4,5"); + bump(3); Deps.flush(); expect("2,3,5,6"); + bump(2); Deps.flush(); expect("2,4,6,7"); + bump(1); Deps.flush(); expect("3,5,7,8"); div.kill(); - Meteor.flush(); + Deps.flush(); }); @@ -618,13 +618,13 @@ Tinytest.add("templating - template arg", function (test) { })); test.equal(div.text(), "Foo Bar Baz"); - Meteor.flush(); + Deps.flush(); test.equal(div.text(), "Greetings 1-bold Line"); clickElement(DomUtils.find(div.node(), 'i')); test.equal(div.text(), "Hello 3-element World (the secret is strawberry pie)"); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("templating - preserve", function (test) { @@ -641,7 +641,7 @@ Tinytest.add("templating - preserve", function (test) { tmpl['var'] = function () { return R.get(); }; var div = OnscreenDiv(Meteor.render(tmpl)); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.find(div.node(), 'u').firstChild.nodeValue.match( /\S+/)[0], 'foo'); var spans1 = {}; @@ -650,7 +650,7 @@ Tinytest.add("templating - preserve", function (test) { }); R.set('bar'); - Meteor.flush(); + Deps.flush(); test.equal(DomUtils.find(div.node(), 'u').firstChild.nodeValue.match( /\S+/)[0], 'bar'); var spans2 = {}; @@ -668,7 +668,7 @@ Tinytest.add("templating - preserve", function (test) { test.isFalse(spans1.z === spans2.z); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("templating - helpers", function (test) { @@ -682,7 +682,7 @@ Tinytest.add("templating - helpers", function (test) { var div = OnscreenDiv(Meteor.render(tmpl)); test.equal(div.text().match(/\S+/)[0], 'abc'); div.kill(); - Meteor.flush(); + Deps.flush(); tmpl = Template.test_template_helpers_b; @@ -707,14 +707,14 @@ Tinytest.add("templating - helpers", function (test) { test.expect_fail(); test.equal(txt, 'ABC4D'); div.kill(); - Meteor.flush(); + Deps.flush(); // test that helpers don't "leak" tmpl = Template.test_template_helpers_c; div = OnscreenDiv(Meteor.render(tmpl)); test.equal(div.text(), 'x'); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("templating - events", function (test) { @@ -731,7 +731,7 @@ Tinytest.add("templating - events", function (test) { clickElement(DomUtils.find(div.node(), 'b')); test.equal(buf, ['b']); div.kill(); - Meteor.flush(); + Deps.flush(); /// @@ -750,7 +750,7 @@ Tinytest.add("templating - events", function (test) { clickElement(DomUtils.find(div.node(), 'i')); test.equal(buf, ['u', 'i']); div.kill(); - Meteor.flush(); + Deps.flush(); }); @@ -773,34 +773,34 @@ Tinytest.add("templating - #each rendered callback", function (test) { DomUtils.rangeToHtml(this.firstNode, this.lastNode)).replace(/\s/g, '')); }; var div = OnscreenDiv(Meteor.render(tmpl)); - Meteor.flush(); + Deps.flush(); test.equal(buf, ['

    a
    b
    c
    ']); buf.length = 0; // added entries.insert({x:'d'}); test.equal(buf, []); - Meteor.flush(); + Deps.flush(); test.equal(buf, ['
    a
    b
    c
    d
    ']); buf.length = 0; // removed entries.remove({x:'a'}); test.equal(buf, []); - Meteor.flush(); + Deps.flush(); test.equal(buf, ['
    b
    c
    d
    ']); buf.length = 0; // moved/changed entries.update({x:'b'}, {$set: {x: 'z'}}); test.equal(buf, []); - Meteor.flush(); + Deps.flush(); test.equal(buf, ['
    c
    d
    z
    ', '
    c
    d
    z
    ']); buf.length = 0; div.kill(); - Meteor.flush(); + Deps.flush(); // test pure "moved" @@ -827,7 +827,7 @@ Tinytest.add("templating - #each rendered callback", function (test) { buf = []; var div = OnscreenDiv(Meteor.render(tmpl)); test.equal(buf, []); - Meteor.flush(); + Deps.flush(); test.equal(buf, ['
    a
    b
    c
    ']); buf.length = 0; @@ -835,14 +835,14 @@ Tinytest.add("templating - #each rendered callback", function (test) { callbacks.movedBefore('a', null); }); test.equal(buf, []); - Meteor.flush(); + Deps.flush(); test.equal(div.html().replace(/\s/g, ''), '
    b
    c
    a
    '); test.equal(buf, ['
    b
    c
    a
    ']); buf.length = 0; div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("templating - landmarks in helpers", function (test) { @@ -864,19 +864,19 @@ Tinytest.add("templating - landmarks in helpers", function (test) { var div = OnscreenDiv(Meteor.render(tmpl)); test.equal(div.text().match(/\S+/)[0], 'xxxxfoo'); - Meteor.flush(); + Deps.flush(); buf.sort(); test.equal(buf.join(''), 'ccccrrrr'); buf.length = 0; R.set('bar'); - Meteor.flush(); + Deps.flush(); test.equal(div.text().match(/\S+/)[0], 'xxxxbar'); test.equal(buf.join(''), 'rrrr'); buf.length = 0; div.kill(); - Meteor.flush(); + Deps.flush(); test.equal(buf.join(''), 'dddd'); }); @@ -899,19 +899,19 @@ Tinytest.add("templating - bare each has no matching", function (test) { }; var div = OnscreenDiv(Meteor.render(tmpl)); - Meteor.flush(); + Deps.flush(); buf.sort(); test.equal(buf.join(''), 'cccrrr'); buf.length = 0; R.set('bar'); - Meteor.flush(); + Deps.flush(); buf.sort(); test.equal(buf.join(''), 'cccdddrrr'); buf.length = 0; div.kill(); - Meteor.flush(); + Deps.flush(); test.equal(buf.join(''), 'ddd'); }); @@ -934,21 +934,21 @@ Tinytest.add("templating - templates are labeled", function (test) { }); var div = OnscreenDiv(Meteor.render(tmpls[0])); - Meteor.flush(); + Deps.flush(); test.equal(div.html(), "


    foo"); buf.sort(); test.equal(buf.join(''), 'cccrrr'); buf.length = 0; R.set('bar'); - Meteor.flush(); + Deps.flush(); test.equal(div.html(), "


    bar"); buf.sort(); test.equal(buf.join(''), 'rrr'); buf.length = 0; div.kill(); - Meteor.flush(); + Deps.flush(); test.equal(buf.join(''), 'ddd'); }); @@ -971,10 +971,10 @@ Tinytest.add("templating - unlabeled cursor", function (test) { // This will fail with "can't create second landmark in branch" // unless _id-less objects returned from a cursor are given // unique branch labels in an {{#each}}. - Meteor.flush(); + Deps.flush(); div.kill(); - Meteor.flush(); + Deps.flush(); }); Tinytest.add("templating - constant text patching", function (test) { @@ -990,16 +990,16 @@ Tinytest.add("templating - constant text patching", function (test) { }; var div = OnscreenDiv(Meteor.render(tmpl)); - Meteor.flush(); + Deps.flush(); R.set("bar"); // This flush will fail if we can't patch the constant region, // which starts with a text node, after preserving the preceding // paragraph. - Meteor.flush(); + Deps.flush(); div.kill(); - Meteor.flush(); + Deps.flush(); }); @@ -1055,16 +1055,16 @@ Tinytest.add("templating - tricky branch labels", function (test) { }); var div = OnscreenDiv(Meteor.render(Template.test_template_trickylabels_a0)); - Meteor.flush(); + Deps.flush(); loading.set(false); - Meteor.flush(); + Deps.flush(); x.length = 0; v.set(2); - Meteor.flush(); + Deps.flush(); test.equal(x.join(''), 'r'); // no 'c' or 'd' test.equal(div.html().replace(/\s+/g, ''), '
    foo
    2
    bar
    '); div.kill(); - Meteor.flush(); + Deps.flush(); }); diff --git a/packages/test-helpers/onscreendiv.js b/packages/test-helpers/onscreendiv.js index b594627e2b..5b0a00afd0 100644 --- a/packages/test-helpers/onscreendiv.js +++ b/packages/test-helpers/onscreendiv.js @@ -43,14 +43,14 @@ OnscreenDiv.prototype.node = function() { }; // remove the DIV from the document and trigger -// "fast GC" -- i.e., after the next Meteor.flush() +// "fast GC" -- i.e., after the next Deps.flush() // the DIV will be fully cleaned up by LiveUI. OnscreenDiv.prototype.kill = function() { var self = this; if (self.div.parentNode) self.div.parentNode.removeChild(self.div); - Meteor._atFlush(function () { + Deps.afterFlush(function () { Spark.finalize(self.div); }); }; diff --git a/packages/test-helpers/reactivevar.js b/packages/test-helpers/reactivevar.js index 0c789663ef..a906c40422 100644 --- a/packages/test-helpers/reactivevar.js +++ b/packages/test-helpers/reactivevar.js @@ -19,11 +19,11 @@ var ReactiveVar = function(initialValue) { this._value = (typeof initialValue === "undefined" ? null : initialValue); - this._deps = new Meteor.deps._ContextSet; + this._depsVar = new Deps.Variable; }; ReactiveVar.prototype.get = function() { - this._deps.addCurrentContext(); + Deps.depend(this._depsVar); return this._value; }; @@ -35,9 +35,10 @@ ReactiveVar.prototype.set = function(newValue) { this._value = newValue; - this._deps.invalidateAll(); + this._depsVar.changed(); }; ReactiveVar.prototype.numListeners = function() { - return _.keys(this._deps._contextsById).length; + // accesses private field (tests want to know) + return _.keys(this._depsVar._dependentsById).length; }; diff --git a/packages/test-helpers/wrappedfrag.js b/packages/test-helpers/wrappedfrag.js index f019bf2fea..1023890cea 100644 --- a/packages/test-helpers/wrappedfrag.js +++ b/packages/test-helpers/wrappedfrag.js @@ -31,7 +31,7 @@ WrappedFrag.prototype.release = function() { // decrement frag's GC protection reference count // Clean up on flush, if hits 0. Wait to decrement // so no one else cleans it up first. - Meteor._atFlush(function () { + Deps.afterFlush(function () { if (! --frag["_protect"]) { Spark.finalize(frag); } diff --git a/packages/test-in-browser/driver.js b/packages/test-in-browser/driver.js index 2a1e7f43c1..8fc6d796ca 100644 --- a/packages/test-in-browser/driver.js +++ b/packages/test-in-browser/driver.js @@ -2,8 +2,8 @@ var running = true; var resultTree = []; var failedTests = []; -var resultDeps = new Meteor.deps._ContextSet; -var countDeps = new Meteor.deps._ContextSet; +var resultsVar = new Deps.Variable; +var countVar = new Deps.Variable; var totalCount = 0; var passedCount = 0; var failedCount = 0; @@ -13,37 +13,37 @@ Session.setDefault("groupPath", ["tinytest"]); Session.set("rerunScheduled", false); Meteor.startup(function () { - Meteor.flush(); + Deps.flush(); Meteor._runTestsEverywhere(reportResults, function () { running = false; Meteor.onTestsComplete && Meteor.onTestsComplete(); - _resultsChanged(); - Meteor.flush(); + resultsVar.changed(); + Deps.flush(); }, Session.get("groupPath")); }); Template.progressBar.running = function () { - countDeps.addCurrentContext(); + Deps.depend(countVar); return passedCount + failedCount < totalCount; }; Template.progressBar.percentPass = function () { - countDeps.addCurrentContext(); + Deps.depend(countVar); if (totalCount === 0) return 0; return 100*passedCount/totalCount; }; Template.progressBar.percentFail = function () { - countDeps.addCurrentContext(); + Deps.depend(countVar); if (totalCount === 0) return 0; return 100*failedCount/totalCount; }; Template.progressBar.anyFail = function () { - countDeps.addCurrentContext(); + Deps.depend(countVar); return failedCount > 0; }; @@ -85,12 +85,12 @@ Template.test_group.events({ }); Template.test_table.running = function() { - resultDeps.addCurrentContext(); + Deps.depend(resultsVar); return running; }; Template.test_table.passed = function() { - resultDeps.addCurrentContext(); + Deps.depend(resultsVar); // walk whole tree to look for failed tests var walk = function (groups) { @@ -119,7 +119,7 @@ Template.test_table.passed = function() { Template.test_table.total_test_time = function() { - resultDeps.addCurrentContext(); + Deps.depend(resultsVar); // walk whole tree to get all tests var walk = function (groups) { @@ -142,11 +142,11 @@ Template.test_table.total_test_time = function() { Template.test_table.data = function() { - resultDeps.addCurrentContext(); + Deps.depend(resultsVar); return resultTree; }; Template.test_table.failedTests = function() { - resultDeps.addCurrentContext(); + Deps.depend(resultsVar); return failedTests; }; @@ -182,7 +182,7 @@ Template.test.test_class = function() { Template.test.events({ 'click .testname': function() { this.expanded = ! this.expanded; - _resultsChanged(); + resultsVar.changed(); } }); @@ -275,11 +275,6 @@ Template.event.is_debuggable = function() { return !!this.cookie; }; - -var _resultsChanged = function() { - resultDeps.invalidateAll(); -}; - var _testTime = function(t) { if (t.events && t.events.length > 0) { var lastEvent = _.last(t.events); @@ -351,7 +346,7 @@ var _findTestForResults = function (results) { test = {name: testName, parent: group, server: server, fullName: fullName}; group.tests.push(test); totalCount++; - countDeps.invalidateAll(); + countVar.changed(); } return test; @@ -380,7 +375,7 @@ var reportResults = function(results) { var status = _testStatus(test); if (status === "failed") { failedCount++; - countDeps.invalidateAll(); + countVar.changed(); // Expand a failed test (but only set this if the user hasn't clicked on the // test name yet). if (test.expanded === undefined) @@ -389,7 +384,7 @@ var reportResults = function(results) { failedTests.push(test.fullName); } else if (status === "succeeded") { passedCount++; - countDeps.invalidateAll(); + countVar.changed(); } _.defer(_throttled_update); @@ -401,16 +396,16 @@ var forgetEvents = function (results) { var status = _testStatus(test); if (status === "failed") { failedCount--; - countDeps.invalidateAll(); + countVar.changed(); } else if (status === "succeeded") { passedCount--; - countDeps.invalidateAll(); + countVar.changed(); } delete test.events; - _resultsChanged(); + resultsVar.changed(); }; var _throttled_update = _.throttle(function() { - _resultsChanged(); - Meteor.flush(); + resultsVar.changed(); + Deps.flush(); }, 500);