From 21afac1e2dbf3e65e0c58d28ca9ef7e4ca6d0af6 Mon Sep 17 00:00:00 2001 From: Avital Oliver Date: Tue, 22 Oct 2013 23:12:16 -0700 Subject: [PATCH] Add comments in deps linking to the docs --- packages/deps/deps.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/deps/deps.js b/packages/deps/deps.js index 21f4afc32bf..3df6381b38c 100644 --- a/packages/deps/deps.js +++ b/packages/deps/deps.js @@ -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) { @@ -40,6 +48,9 @@ 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( @@ -47,8 +58,14 @@ Deps.Computation = function (f, parent) { 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++; @@ -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; @@ -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) { @@ -110,6 +129,7 @@ _.extend(Deps.Computation.prototype, { } }, + // http://docs.meteor.com/#computation_stop stop: function () { if (! this.stopped) { this.stopped = true; @@ -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 @@ -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) @@ -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 @@ -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. // @@ -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 @@ -293,6 +327,7 @@ _.extend(Deps, { return nonreactiveVersion; }, + // http://docs.meteor.com/#deps_oninvalidate onInvalidate: function (f) { if (! Deps.active) throw new Error("Deps.onInvalidate requires a currentComputation"); @@ -300,6 +335,7 @@ _.extend(Deps, { Deps.currentComputation.onInvalidate(f); }, + // http://docs.meteor.com/#deps_afterflush afterFlush: function (f) { afterFlushCallbacks.push(f); requireFlush();