Var -> Deps

This commit is contained in:
David Greenspan
2013-02-28 16:11:38 -08:00
parent 457de14998
commit 447f5a6686
5 changed files with 54 additions and 54 deletions

View File

@@ -6,18 +6,18 @@
};
var loggingIn = false;
var loggingInVar = new Deps.Variable;
var loggingInDeps = 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;
loggingInVar.changed();
loggingInDeps.changed();
}
};
Meteor.loggingIn = function () {
loggingInVar.changed();
loggingInDeps.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 loginServicesConfiguredVar = new Deps.Variable;
var loginServicesConfiguredDeps = new Deps.Variable;
Meteor.subscribe("meteor.loginServiceConfiguration", function () {
loginServicesConfigured = true;
loginServicesConfiguredVar.changed();
loginServicesConfiguredDeps.changed();
});
// A reactive function returning whether the
@@ -196,7 +196,7 @@
return true;
// not yet complete, save the context for invalidation once we are.
Deps.depend(loginServicesConfiguredVar);
Deps.depend(loginServicesConfiguredDeps);
return false;
};
})();

View File

@@ -158,7 +158,7 @@ Meteor._LivedataConnection = function (url, options) {
// Reactive userId.
self._userId = null;
self._userIdVar = (typeof Deps !== "undefined") && new Deps.Variable;
self._userIdDeps = (typeof Deps !== "undefined") && new Deps.Variable;
// Block auto-reload while we're waiting for method responses.
if (!options.reloadWithOutstanding) {
@@ -474,7 +474,7 @@ _.extend(Meteor._LivedataConnection.prototype, {
params: params,
inactivate: false,
ready: false,
readyVar: (typeof Deps !== "undefined") && new Deps.Variable,
readyDeps: (typeof Deps !== "undefined") && new Deps.Variable,
readyCallback: callbacks.onReady,
errorCallback: callbacks.onError
};
@@ -494,7 +494,7 @@ _.extend(Meteor._LivedataConnection.prototype, {
if (!_.has(self._subscriptions, id))
return false;
var record = self._subscriptions[id];
record.readyVar && Deps.depend(record.readyVar);
record.readyDeps && Deps.depend(record.readyDeps);
return record.ready;
}
};
@@ -777,8 +777,8 @@ _.extend(Meteor._LivedataConnection.prototype, {
///
userId: function () {
var self = this;
if (self._userIdVar)
Deps.depend(self._userIdVar);
if (self._userIdDeps)
Deps.depend(self._userIdDeps);
return self._userId;
},
@@ -788,8 +788,8 @@ _.extend(Meteor._LivedataConnection.prototype, {
if (self._userId === userId)
return;
self._userId = userId;
if (self._userIdVar)
self._userIdVar.changed();
if (self._userIdDeps)
self._userIdDeps.changed();
},
// Returns true if we are in a state after reconnect of waiting for subs to be
@@ -1108,7 +1108,7 @@ _.extend(Meteor._LivedataConnection.prototype, {
return;
subRecord.readyCallback && subRecord.readyCallback();
subRecord.ready = true;
subRecord.readyVar && subRecord.readyVar.changed();
subRecord.readyDeps && subRecord.readyDeps.changed();
});
});
},

View File

@@ -15,8 +15,8 @@
Session = _.extend({}, {
keys: {}, // key -> value
keyVars: {}, // key -> Variable
keyValueVars: {}, // key -> value -> Variable
keyDeps: {}, // key -> Variable
keyValueDeps: {}, // key -> value -> Variable
set: function (key, value) {
var self = this;
@@ -33,10 +33,10 @@
v && v.changed();
};
changed(self.keyVars[key]);
if (self.keyValueVars[key]) {
changed(self.keyValueVars[key][oldSerializedValue]);
changed(self.keyValueVars[key][value]);
changed(self.keyDeps[key]);
if (self.keyValueDeps[key]) {
changed(self.keyValueDeps[key][oldSerializedValue]);
changed(self.keyValueDeps[key][value]);
}
},
@@ -53,7 +53,7 @@
get: function (key) {
var self = this;
self._ensureKey(key);
Deps.depend(self.keyVars[key]);
Deps.depend(self.keyDeps[key]);
return parse(self.keys[key]);
},
@@ -64,7 +64,7 @@
// .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 keyValueVars[key] to store the dependency.) You can still use
// element of keyValueDeps[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
@@ -82,16 +82,16 @@
if (Deps.active) {
self._ensureKey(key);
if (! _.has(self.keyValueVars[key], serializedValue))
self.keyValueVars[key][serializedValue] = new Deps.Variable;
if (! _.has(self.keyValueDeps[key], serializedValue))
self.keyValueDeps[key][serializedValue] = new Deps.Variable;
var isNew = Deps.depend(self.keyValueVars[key][serializedValue]);
var isNew = Deps.depend(self.keyValueDeps[key][serializedValue]);
if (isNew) {
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.keyValueVars[key][serializedValue].hasDependents())
delete self.keyValueVars[key][serializedValue];
if (! self.keyValueDeps[key][serializedValue].hasDependents())
delete self.keyValueDeps[key][serializedValue];
});
}
}
@@ -103,9 +103,9 @@
_ensureKey: function (key) {
var self = this;
if (!(key in self.keyVars)) {
self.keyVars[key] = new Deps.Variable;
self.keyValueVars[key] = {};
if (!(key in self.keyDeps)) {
self.keyDeps[key] = new Deps.Variable;
self.keyValueDeps[key] = {};
}
}
});

View File

@@ -19,11 +19,11 @@ var ReactiveVar = function(initialValue) {
this._value = (typeof initialValue === "undefined" ? null :
initialValue);
this._depsVar = new Deps.Variable;
this._deps = new Deps.Variable;
};
ReactiveVar.prototype.get = function() {
Deps.depend(this._depsVar);
Deps.depend(this._deps);
return this._value;
};
@@ -35,10 +35,10 @@ ReactiveVar.prototype.set = function(newValue) {
this._value = newValue;
this._depsVar.changed();
this._deps.changed();
};
ReactiveVar.prototype.numListeners = function() {
// accesses private field (tests want to know)
return _.keys(this._depsVar._dependentsById).length;
return _.keys(this._deps._dependentsById).length;
};

View File

@@ -2,8 +2,8 @@ var running = true;
var resultTree = [];
var failedTests = [];
var resultsVar = new Deps.Variable;
var countVar = new Deps.Variable;
var resultsDeps = new Deps.Variable;
var countDeps = new Deps.Variable;
var totalCount = 0;
var passedCount = 0;
var failedCount = 0;
@@ -17,33 +17,33 @@ Meteor.startup(function () {
Meteor._runTestsEverywhere(reportResults, function () {
running = false;
Meteor.onTestsComplete && Meteor.onTestsComplete();
resultsVar.changed();
resultsDeps.changed();
Deps.flush();
}, Session.get("groupPath"));
});
Template.progressBar.running = function () {
Deps.depend(countVar);
Deps.depend(countDeps);
return passedCount + failedCount < totalCount;
};
Template.progressBar.percentPass = function () {
Deps.depend(countVar);
Deps.depend(countDeps);
if (totalCount === 0)
return 0;
return 100*passedCount/totalCount;
};
Template.progressBar.percentFail = function () {
Deps.depend(countVar);
Deps.depend(countDeps);
if (totalCount === 0)
return 0;
return 100*failedCount/totalCount;
};
Template.progressBar.anyFail = function () {
Deps.depend(countVar);
Deps.depend(countDeps);
return failedCount > 0;
};
@@ -85,12 +85,12 @@ Template.test_group.events({
});
Template.test_table.running = function() {
Deps.depend(resultsVar);
Deps.depend(resultsDeps);
return running;
};
Template.test_table.passed = function() {
Deps.depend(resultsVar);
Deps.depend(resultsDeps);
// 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() {
Deps.depend(resultsVar);
Deps.depend(resultsDeps);
// 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() {
Deps.depend(resultsVar);
Deps.depend(resultsDeps);
return resultTree;
};
Template.test_table.failedTests = function() {
Deps.depend(resultsVar);
Deps.depend(resultsDeps);
return failedTests;
};
@@ -182,7 +182,7 @@ Template.test.test_class = function() {
Template.test.events({
'click .testname': function() {
this.expanded = ! this.expanded;
resultsVar.changed();
resultsDeps.changed();
}
});
@@ -346,7 +346,7 @@ var _findTestForResults = function (results) {
test = {name: testName, parent: group, server: server, fullName: fullName};
group.tests.push(test);
totalCount++;
countVar.changed();
countDeps.changed();
}
return test;
@@ -375,7 +375,7 @@ var reportResults = function(results) {
var status = _testStatus(test);
if (status === "failed") {
failedCount++;
countVar.changed();
countDeps.changed();
// Expand a failed test (but only set this if the user hasn't clicked on the
// test name yet).
if (test.expanded === undefined)
@@ -384,7 +384,7 @@ var reportResults = function(results) {
failedTests.push(test.fullName);
} else if (status === "succeeded") {
passedCount++;
countVar.changed();
countDeps.changed();
}
_.defer(_throttled_update);
@@ -396,16 +396,16 @@ var forgetEvents = function (results) {
var status = _testStatus(test);
if (status === "failed") {
failedCount--;
countVar.changed();
countDeps.changed();
} else if (status === "succeeded") {
passedCount--;
countVar.changed();
countDeps.changed();
}
delete test.events;
resultsVar.changed();
resultsDeps.changed();
};
var _throttled_update = _.throttle(function() {
resultsVar.changed();
resultsDeps.changed();
Deps.flush();
}, 500);