Skip to content

Commit

Permalink
Add comments in deps linking to the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
avital committed Oct 23, 2013
1 parent 679100f commit 21afac1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/deps/deps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
//////////////////////////////////////////////////
// Package docs at http://docs.meteor.com/#deps //
//////////////////////////////////////////////////

Deps = {};

// http://docs.meteor.com/#deps_active
Deps.active = false;

// http://docs.meteor.com/#deps_currentcomputation
Deps.currentComputation = null;

var setCurrentComputation = function (c) {
Expand Down Expand Up @@ -40,15 +48,24 @@ var requireFlush = function () {
// (throws an error if you try to call it)
var constructingComputation = false;

//
// http://docs.meteor.com/#deps_computation
//
Deps.Computation = function (f, parent) {
if (! constructingComputation)
throw new Error(
"Deps.Computation constructor is private; use Deps.autorun");
constructingComputation = false;

var self = this;

// http://docs.meteor.com/#computation_stopped
self.stopped = false;

// http://docs.meteor.com/#computation_invalidated
self.invalidated = false;

// http://docs.meteor.com/#computation_firstrun
self.firstRun = true;

self._id = nextId++;
Expand All @@ -72,6 +89,7 @@ Deps.Computation = function (f, parent) {

_.extend(Deps.Computation.prototype, {

// http://docs.meteor.com/#computation_oninvalidate
onInvalidate: function (f) {
var self = this;

Expand All @@ -90,6 +108,7 @@ _.extend(Deps.Computation.prototype, {
self._onInvalidateCallbacks.push(g);
},

// http://docs.meteor.com/#computation_invalidate
invalidate: function () {
var self = this;
if (! self.invalidated) {
Expand All @@ -110,6 +129,7 @@ _.extend(Deps.Computation.prototype, {
}
},

// http://docs.meteor.com/#computation_stop
stop: function () {
if (! this.stopped) {
this.stopped = true;
Expand Down Expand Up @@ -154,11 +174,16 @@ _.extend(Deps.Computation.prototype, {
}
});

//
// http://docs.meteor.com/#deps_dependency
//
Deps.Dependency = function () {
this._dependentsById = {};
};

_.extend(Deps.Dependency.prototype, {
// http://docs.meteor.com/#dependency_depend
//
// Adds `computation` to this set if it is not already
// present. Returns true if `computation` is a new member of the set.
// If no argument, defaults to currentComputation, or does nothing
Expand All @@ -181,11 +206,15 @@ _.extend(Deps.Dependency.prototype, {
}
return false;
},

// http://docs.meteor.com/#dependency_changed
changed: function () {
var self = this;
for (var id in self._dependentsById)
self._dependentsById[id].invalidate();
},

// http://docs.meteor.com/#dependency_hasdependents
hasDependents: function () {
var self = this;
for(var id in self._dependentsById)
Expand All @@ -195,6 +224,7 @@ _.extend(Deps.Dependency.prototype, {
});

_.extend(Deps, {
// http://docs.meteor.com/#deps_flush
flush: function () {
// Nested flush could plausibly happen if, say, a flush causes
// DOM mutation, which causes a "blur" event, which runs an
Expand Down Expand Up @@ -240,6 +270,8 @@ _.extend(Deps, {
willFlush = false;
},

// http://docs.meteor.com/#deps_autorun
//
// Run f(). Record its dependencies. Rerun it whenever the
// dependencies change.
//
Expand All @@ -262,6 +294,8 @@ _.extend(Deps, {
return c;
},

// http://docs.meteor.com/#deps_nonreactive
//
// Run `f` with no current computation, returning the return value
// of `f`. Used to turn off reactivity for the duration of `f`,
// so that reactive data sources accessed by `f` will not result in any
Expand Down Expand Up @@ -293,13 +327,15 @@ _.extend(Deps, {
return nonreactiveVersion;
},

// http://docs.meteor.com/#deps_oninvalidate
onInvalidate: function (f) {
if (! Deps.active)
throw new Error("Deps.onInvalidate requires a currentComputation");

Deps.currentComputation.onInvalidate(f);
},

// http://docs.meteor.com/#deps_afterflush
afterFlush: function (f) {
afterFlushCallbacks.push(f);
requireFlush();
Expand Down

0 comments on commit 21afac1

Please sign in to comment.