You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
24 KiB
1 lines
24 KiB
{"version":3,"sources":["tracker/tracker.js","tracker/deprecated.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qD;AACA,qD;AACA,qD;;AAEA,G;AACA,qB;AACA,sD;AACA,G;AACA,a;;AAEA,yC;;AAEA,G;AACA,iL;AACA,gB;AACA,kB;AACA,G;AACA,uB;;AAEA,qD;;AAEA,G;AACA,4S;AACA,gB;AACA,8B;AACA,G;AACA,kC;;AAEA,mE;AACA,2E;AACA,6E;AACA,oE;AACA,qC;AACA,2B;;AAEA,0C;AACA,iC;AACA,wB;AACA,E;;AAEA,8B;AACA,+D;AACA,oE;AACA,0D;AACA,I;AACA,oE;AACA,yD;AACA,8D;AACA,qE;AACA,4B;AACA,E;;AAEA,uD;AACA,4E;AACA,4E;AACA,gF;AACA,uD;AACA,sC;AACA,2C;AACA,+C;AACA,K;AACA,G;AACA,E;;AAEA,sC;AACA,wB;AACA,Y;AACA,U;AACA,sE;AACA,yC;AACA,2C;AACA,sE;AACA,2C;AACA,gD;AACA,gC;AACA,O;AACA,K;AACA,4B;AACA,4C;;AAEA,gD;AACA,iC;AACA,K;AACA,G;AACA,E;;AAEA,oE;AACA,oE;AACA,0D;AACA,kE;AACA,uB;AACA,wC;AACA,2D;AACA,a;AACA,U;AACA,wB;AACA,2B;AACA,2C;AACA,4B;AACA,S;AACA,M;AACA,G;AACA,E;;AAEA,e;AACA,4D;AACA,6B;AACA,4E;AACA,sB;AACA,wC;AACA,oB;AACA,kE;AACA,kE;AACA,qE;AACA,iD;AACA,sB;AACA,oE;AACA,uE;AACA,qE;AACA,iE;AACA,U;AACA,4B;;AAEA,6B;;AAEA,gC;AACA,oB;AACA,oE;AACA,sC;AACA,8C;AACA,Q;AACA,uC;AACA,qB;AACA,G;AACA,E;;AAEA,yD;AACA,0C;AACA,oC;;AAEA,E;AACA,8C;;AAEA,G;AACA,yE;AACA,iB;AACA,0E;AACA,8E;AACA,gF;AACA,e;AACA,4B;AACA,G;AACA,qD;AACA,gC;AACA,oB;AACA,yE;AACA,kC;;AAEA,kB;;AAEA,gD;;AAEA,K;AACA,wD;AACA,kB;AACA,kC;AACA,c;AACA,mB;AACA,K;AACA,uB;;AAEA,oD;;AAEA,K;AACA,2G;AACA,kB;AACA,kC;AACA,c;AACA,uB;AACA,oB;AACA,K;AACA,2B;;AAEA,iD;;AAEA,K;AACA,wJ;AACA,kB;AACA,kC;AACA,c;AACA,oB;AACA,oB;AACA,K;AACA,uB;;AAEA,sB;AACA,mC;AACA,yD;AACA,2D;AACA,wB;AACA,iB;AACA,0B;AACA,4B;;AAEA,wD;AACA,yC;;AAEA,qB;AACA,O;AACA,oB;AACA,oB;AACA,a;AACA,0B;AACA,gB;AACA,kB;AACA,G;AACA,E;;AAEA,mD;;AAEA,G;AACA,yS;AACA,gB;AACA,iI;AACA,G;AACA,2D;AACA,kB;;AAEA,8B;AACA,wD;;AAEA,yB;AACA,qC;AACA,mC;AACA,O;AACA,U;AACA,wC;AACA,G;AACA,E;;AAEA,iD;;AAEA,G;AACA,kE;AACA,gB;AACA,G;AACA,wD;AACA,kB;AACA,2B;AACA,wD;AACA,uD;AACA,gD;AACA,qB;AACA,qC;AACA,K;;AAEA,4B;;AAEA,6C;AACA,iC;AACA,gE;AACA,uC;AACA,qC;AACA,S;AACA,K;AACA,qC;AACA,G;AACA,E;;AAEA,2C;;AAEA,G;AACA,qD;AACA,gB;AACA,G;AACA,kD;AACA,uB;AACA,wB;AACA,sB;AACA,sC;AACA,2C;AACA,G;AACA,E;;AAEA,sD;AACA,kB;AACA,2B;;AAEA,4C;AACA,8B;AACA,oC;AACA,mB;AACA,O;AACA,0C;AACA,a;AACA,oC;AACA,kC;AACA,G;AACA,E;;AAEA,6D;AACA,kB;AACA,4C;AACA,E;;AAEA,wD;AACA,kB;;AAEA,2B;AACA,O;AACA,iC;AACA,W;AACA,wB;AACA,mB;AACA,4B;AACA,2B;AACA,gB;AACA,sC;AACA,S;AACA,O;AACA,K;AACA,a;AACA,8B;AACA,G;AACA,E;;AAEA,E;AACA,6C;;AAEA,G;AACA,0E;AACA,wE;AACA,yE;AACA,6E;AACA,2D;AACA,S;AACA,2B;AACA,G;AACA,kC;AACA,4B;AACA,E;;AAEA,4C;AACA,E;AACA,sD;AACA,sE;AACA,kE;AACA,qC;;AAEA,G;AACA,mL;;AAEA,iH;;AAEA,+F;AACA,gB;AACA,gJ;AACA,qB;AACA,G;AACA,8D;AACA,sB;AACA,yB;AACA,mB;;AAEA,6C;AACA,G;AACA,kB;AACA,2B;AACA,uC;AACA,2C;AACA,0C;AACA,sC;AACA,O;AACA,gB;AACA,G;AACA,e;AACA,E;;AAEA,6C;;AAEA,G;AACA,4F;AACA,gB;AACA,G;AACA,oD;AACA,kB;AACA,sC;AACA,0C;AACA,E;;AAEA,mD;;AAEA,G;AACA,yI;AACA,gB;AACA,qB;AACA,G;AACA,0D;AACA,kB;AACA,qC;AACA,gB;AACA,e;AACA,E;;AAEA,wC;;AAEA,G;AACA,4G;AACA,gB;AACA,G;AACA,oC;AACA,gD;AACA,8E;AACA,E;;AAEA,gF;AACA,+E;AACA,oD;AACA,wC;AACA,oE;AACA,gB;AACA,I;AACA,gE;AACA,6D;AACA,+D;AACA,4D;AACA,+D;AACA,yC;AACA,I;AACA,sD;AACA,c;AACA,+D;;AAEA,gB;AACA,0D;;AAEA,0B;;AAEA,iB;AACA,mB;AACA,+C;;AAEA,0B;AACA,0B;AACA,O;AACA,wC;AACA,wC;;AAEA,2C;AACA,0C;AACA,+C;AACA,0B;AACA,qC;AACA,4C;AACA,S;;AAEA,wE;AACA,6B;AACA,iB;AACA,S;AACA,O;;AAEA,uC;AACA,kD;AACA,uC;AACA,+C;AACA,a;AACA,iB;AACA,qB;AACA,uC;AACA,S;AACA,O;AACA,K;AACA,uB;AACA,a;AACA,wB;AACA,0D;AACA,uE;AACA,wB;AACA,yB;AACA,yD;AACA,8B;AACA,S;AACA,K;AACA,sB;AACA,oB;AACA,mE;AACA,4E;AACA,gF;AACA,4C;AACA,wC;AACA,uE;AACA,O;AACA,mC;AACA,K;AACA,G;AACA,E;;AAEA,0C;AACA,E;AACA,0D;AACA,uB;AACA,E;AACA,wD;AACA,E;AACA,mD;AACA,mE;;AAEA,G;AACA,wC;AACA,+B;AACA,G;AACA,G;AACA,2E;AACA,+E;AACA,a;AACA,gB;AACA,gF;AACA,8D;AACA,4B;AACA,gF;AACA,yE;AACA,6D;AACA,iC;AACA,G;AACA,yC;AACA,8B;AACA,oE;;AAEA,0B;;AAEA,iC;AACA,kC;AACA,oD;;AAEA,qB;AACA,sC;AACA,e;AACA,O;;AAEA,W;AACA,E;;AAEA,8C;AACA,E;AACA,kE;AACA,gE;AACA,uE;AACA,kC;;AAEA,G;AACA,yD;AACA,gB;AACA,yD;AACA,G;AACA,oC;AACA,4C;AACA,8B;AACA,O;AACA,e;AACA,a;AACA,oC;AACA,G;AACA,E;;AAEA,+C;;AAEA,G;AACA,gN;AACA,gB;AACA,sJ;AACA,G;AACA,qC;AACA,uB;AACA,0E;;AAEA,6C;AACA,E;;AAEA,6C;;AAEA,G;AACA,+Q;AACA,gB;AACA,+D;AACA,G;AACA,mC;AACA,8B;AACA,iB;AACA,E;;;;;;;;;;;;;;;;;;;AC7kBA,wB;;AAEA,uE;AACA,gB;AACA,wB;AACA,6B;AACA,iC;;AAEA,+E;AACA,sC;AACA,wB;AACA,uC;;AAEA,sD;AACA,wB;AACA,+B;AACA,oB;AACA,E;;AAEA,e","file":"/packages/tracker.js","sourcesContent":["/////////////////////////////////////////////////////\n// Package docs at http://docs.meteor.com/#tracker //\n/////////////////////////////////////////////////////\n\n/**\n * @namespace Tracker\n * @summary The namespace for Tracker-related methods.\n */\nTracker = {};\n\n// http://docs.meteor.com/#tracker_active\n\n/**\n * @summary True if there is a current computation, meaning that dependencies on reactive data sources will be tracked and potentially cause the current computation to be rerun.\n * @locus Client\n * @type {Boolean}\n */\nTracker.active = false;\n\n// http://docs.meteor.com/#tracker_currentcomputation\n\n/**\n * @summary The current computation, or `null` if there isn't one. The current computation is the [`Tracker.Computation`](#tracker_computation) object created by the innermost active call to `Tracker.autorun`, and it's the computation that gains dependencies when reactive data sources are accessed.\n * @locus Client\n * @type {Tracker.Computation}\n */\nTracker.currentComputation = null;\n\n// References to all computations created within the Tracker by id.\n// Keeping these references on an underscore property gives more control to\n// tooling and packages extending Tracker without increasing the API surface.\n// These can used to monkey-patch computations, their functions, use\n// computation ids for tracking, etc.\nTracker._computations = {};\n\nvar setCurrentComputation = function (c) {\n Tracker.currentComputation = c;\n Tracker.active = !! c;\n};\n\nvar _debugFunc = function () {\n // We want this code to work without Meteor, and also without\n // \"console\" (which is technically non-standard and may be missing\n // on some browser we come across, like it was on IE 7).\n //\n // Lazy evaluation because `Meteor` does not exist right away.(??)\n return (typeof Meteor !== \"undefined\" ? Meteor._debug :\n ((typeof console !== \"undefined\") && console.error ?\n function () { console.error.apply(console, arguments); } :\n function () {}));\n};\n\nvar _maybeSupressMoreLogs = function (messagesLength) {\n // Sometimes when running tests, we intentionally supress logs on expected\n // printed errors. Since the current implementation of _throwOrLog can log\n // multiple separate log messages, supress all of them if at least one supress\n // is expected as we still want them to count as one.\n if (typeof Meteor !== \"undefined\") {\n if (Meteor._supressed_log_expected()) {\n Meteor._suppress_log(messagesLength - 1);\n }\n }\n};\n\nvar _throwOrLog = function (from, e) {\n if (throwFirstError) {\n throw e;\n } else {\n var printArgs = [\"Exception from Tracker \" + from + \" function:\"];\n if (e.stack && e.message && e.name) {\n var idx = e.stack.indexOf(e.message);\n if (idx < 0 || idx > e.name.length + 2) { // check for \"Error: \"\n // message is not part of the stack\n var message = e.name + \": \" + e.message;\n printArgs.push(message);\n }\n }\n printArgs.push(e.stack);\n _maybeSupressMoreLogs(printArgs.length);\n\n for (var i = 0; i < printArgs.length; i++) {\n _debugFunc()(printArgs[i]);\n }\n }\n};\n\n// Takes a function `f`, and wraps it in a `Meteor._noYieldsAllowed`\n// block if we are running on the server. On the client, returns the\n// original function (since `Meteor._noYieldsAllowed` is a\n// no-op). This has the benefit of not adding an unnecessary stack\n// frame on the client.\nvar withNoYieldsAllowed = function (f) {\n if ((typeof Meteor === 'undefined') || Meteor.isClient) {\n return f;\n } else {\n return function () {\n var args = arguments;\n Meteor._noYieldsAllowed(function () {\n f.apply(null, args);\n });\n };\n }\n};\n\nvar nextId = 1;\n// computations whose callbacks we should call at flush time\nvar pendingComputations = [];\n// `true` if a Tracker.flush is scheduled, or if we are in Tracker.flush now\nvar willFlush = false;\n// `true` if we are in Tracker.flush now\nvar inFlush = false;\n// `true` if we are computing a computation now, either first time\n// or recompute. This matches Tracker.active unless we are inside\n// Tracker.nonreactive, which nullfies currentComputation even though\n// an enclosing computation may still be running.\nvar inCompute = false;\n// `true` if the `_throwFirstError` option was passed in to the call\n// to Tracker.flush that we are in. When set, throw rather than log the\n// first error encountered while flushing. Before throwing the error,\n// finish flushing (from a finally block), logging any subsequent\n// errors.\nvar throwFirstError = false;\n\nvar afterFlushCallbacks = [];\n\nvar requireFlush = function () {\n if (! willFlush) {\n // We want this code to work without Meteor, see debugFunc above\n if (typeof Meteor !== \"undefined\")\n Meteor._setImmediate(Tracker._runFlush);\n else\n setTimeout(Tracker._runFlush, 0);\n willFlush = true;\n }\n};\n\n// Tracker.Computation constructor is visible but private\n// (throws an error if you try to call it)\nvar constructingComputation = false;\n\n//\n// http://docs.meteor.com/#tracker_computation\n\n/**\n * @summary A Computation object represents code that is repeatedly rerun\n * in response to\n * reactive data changes. Computations don't have return values; they just\n * perform actions, such as rerendering a template on the screen. Computations\n * are created using Tracker.autorun. Use stop to prevent further rerunning of a\n * computation.\n * @instancename computation\n */\nTracker.Computation = function (f, parent, onError) {\n if (! constructingComputation)\n throw new Error(\n \"Tracker.Computation constructor is private; use Tracker.autorun\");\n constructingComputation = false;\n\n var self = this;\n\n // http://docs.meteor.com/#computation_stopped\n\n /**\n * @summary True if this computation has been stopped.\n * @locus Client\n * @memberOf Tracker.Computation\n * @instance\n * @name stopped\n */\n self.stopped = false;\n\n // http://docs.meteor.com/#computation_invalidated\n\n /**\n * @summary True if this computation has been invalidated (and not yet rerun), or if it has been stopped.\n * @locus Client\n * @memberOf Tracker.Computation\n * @instance\n * @name invalidated\n * @type {Boolean}\n */\n self.invalidated = false;\n\n // http://docs.meteor.com/#computation_firstrun\n\n /**\n * @summary True during the initial run of the computation at the time `Tracker.autorun` is called, and false on subsequent reruns and at other times.\n * @locus Client\n * @memberOf Tracker.Computation\n * @instance\n * @name firstRun\n * @type {Boolean}\n */\n self.firstRun = true;\n\n self._id = nextId++;\n self._onInvalidateCallbacks = [];\n // the plan is at some point to use the parent relation\n // to constrain the order that computations are processed\n self._parent = parent;\n self._func = f;\n self._onError = onError;\n self._recomputing = false;\n\n // Register the computation within the global Tracker.\n Tracker._computations[self._id] = self;\n\n var errored = true;\n try {\n self._compute();\n errored = false;\n } finally {\n self.firstRun = false;\n if (errored)\n self.stop();\n }\n};\n\n// http://docs.meteor.com/#computation_oninvalidate\n\n/**\n * @summary Registers `callback` to run when this computation is next invalidated, or runs it immediately if the computation is already invalidated. The callback is run exactly once and not upon future invalidations unless `onInvalidate` is called again after the computation becomes valid again.\n * @locus Client\n * @param {Function} callback Function to be called on invalidation. Receives one argument, the computation that was invalidated.\n */\nTracker.Computation.prototype.onInvalidate = function (f) {\n var self = this;\n\n if (typeof f !== 'function')\n throw new Error(\"onInvalidate requires a function\");\n\n if (self.invalidated) {\n Tracker.nonreactive(function () {\n withNoYieldsAllowed(f)(self);\n });\n } else {\n self._onInvalidateCallbacks.push(f);\n }\n};\n\n// http://docs.meteor.com/#computation_invalidate\n\n/**\n * @summary Invalidates this computation so that it will be rerun.\n * @locus Client\n */\nTracker.Computation.prototype.invalidate = function () {\n var self = this;\n if (! self.invalidated) {\n // if we're currently in _recompute(), don't enqueue\n // ourselves, since we'll rerun immediately anyway.\n if (! self._recomputing && ! self.stopped) {\n requireFlush();\n pendingComputations.push(this);\n }\n\n self.invalidated = true;\n\n // callbacks can't add callbacks, because\n // self.invalidated === true.\n for(var i = 0, f; f = self._onInvalidateCallbacks[i]; i++) {\n Tracker.nonreactive(function () {\n withNoYieldsAllowed(f)(self);\n });\n }\n self._onInvalidateCallbacks = [];\n }\n};\n\n// http://docs.meteor.com/#computation_stop\n\n/**\n * @summary Prevents this computation from rerunning.\n * @locus Client\n */\nTracker.Computation.prototype.stop = function () {\n if (! this.stopped) {\n this.stopped = true;\n this.invalidate();\n // Unregister from global Tracker.\n delete Tracker._computations[this._id];\n }\n};\n\nTracker.Computation.prototype._compute = function () {\n var self = this;\n self.invalidated = false;\n\n var previous = Tracker.currentComputation;\n setCurrentComputation(self);\n var previousInCompute = inCompute;\n inCompute = true;\n try {\n withNoYieldsAllowed(self._func)(self);\n } finally {\n setCurrentComputation(previous);\n inCompute = previousInCompute;\n }\n};\n\nTracker.Computation.prototype._needsRecompute = function () {\n var self = this;\n return self.invalidated && ! self.stopped;\n};\n\nTracker.Computation.prototype._recompute = function () {\n var self = this;\n\n self._recomputing = true;\n try {\n if (self._needsRecompute()) {\n try {\n self._compute();\n } catch (e) {\n if (self._onError) {\n self._onError(e);\n } else {\n _throwOrLog(\"recompute\", e);\n }\n }\n }\n } finally {\n self._recomputing = false;\n }\n};\n\n//\n// http://docs.meteor.com/#tracker_dependency\n\n/**\n * @summary A Dependency represents an atomic unit of reactive data that a\n * computation might depend on. Reactive data sources such as Session or\n * Minimongo internally create different Dependency objects for different\n * pieces of data, each of which may be depended on by multiple computations.\n * When the data changes, the computations are invalidated.\n * @class\n * @instanceName dependency\n */\nTracker.Dependency = function () {\n this._dependentsById = {};\n};\n\n// http://docs.meteor.com/#dependency_depend\n//\n// Adds `computation` to this set if it is not already\n// present. Returns true if `computation` is a new member of the set.\n// If no argument, defaults to currentComputation, or does nothing\n// if there is no currentComputation.\n\n/**\n * @summary Declares that the current computation (or `fromComputation` if given) depends on `dependency`. The computation will be invalidated the next time `dependency` changes.\n\nIf there is no current computation and `depend()` is called with no arguments, it does nothing and returns false.\n\nReturns true if the computation is a new dependent of `dependency` rather than an existing one.\n * @locus Client\n * @param {Tracker.Computation} [fromComputation] An optional computation declared to depend on `dependency` instead of the current computation.\n * @returns {Boolean}\n */\nTracker.Dependency.prototype.depend = function (computation) {\n if (! computation) {\n if (! Tracker.active)\n return false;\n\n computation = Tracker.currentComputation;\n }\n var self = this;\n var id = computation._id;\n if (! (id in self._dependentsById)) {\n self._dependentsById[id] = computation;\n computation.onInvalidate(function () {\n delete self._dependentsById[id];\n });\n return true;\n }\n return false;\n};\n\n// http://docs.meteor.com/#dependency_changed\n\n/**\n * @summary Invalidate all dependent computations immediately and remove them as dependents.\n * @locus Client\n */\nTracker.Dependency.prototype.changed = function () {\n var self = this;\n for (var id in self._dependentsById)\n self._dependentsById[id].invalidate();\n};\n\n// http://docs.meteor.com/#dependency_hasdependents\n\n/**\n * @summary True if this Dependency has one or more dependent Computations, which would be invalidated if this Dependency were to change.\n * @locus Client\n * @returns {Boolean}\n */\nTracker.Dependency.prototype.hasDependents = function () {\n var self = this;\n for(var id in self._dependentsById)\n return true;\n return false;\n};\n\n// http://docs.meteor.com/#tracker_flush\n\n/**\n * @summary Process all reactive updates immediately and ensure that all invalidated computations are rerun.\n * @locus Client\n */\nTracker.flush = function (options) {\n Tracker._runFlush({ finishSynchronously: true,\n throwFirstError: options && options._throwFirstError });\n};\n\n// Run all pending computations and afterFlush callbacks. If we were not called\n// directly via Tracker.flush, this may return before they're all done to allow\n// the event loop to run a little before continuing.\nTracker._runFlush = function (options) {\n // XXX What part of the comment below is still true? (We no longer\n // have Spark)\n //\n // Nested flush could plausibly happen if, say, a flush causes\n // DOM mutation, which causes a \"blur\" event, which runs an\n // app event handler that calls Tracker.flush. At the moment\n // Spark blocks event handlers during DOM mutation anyway,\n // because the LiveRange tree isn't valid. And we don't have\n // any useful notion of a nested flush.\n //\n // https://app.asana.com/0/159908330244/385138233856\n if (inFlush)\n throw new Error(\"Can't call Tracker.flush while flushing\");\n\n if (inCompute)\n throw new Error(\"Can't flush inside Tracker.autorun\");\n\n options = options || {};\n\n inFlush = true;\n willFlush = true;\n throwFirstError = !! options.throwFirstError;\n\n var recomputedCount = 0;\n var finishedTry = false;\n try {\n while (pendingComputations.length ||\n afterFlushCallbacks.length) {\n\n // recompute all pending computations\n while (pendingComputations.length) {\n var comp = pendingComputations.shift();\n comp._recompute();\n if (comp._needsRecompute()) {\n pendingComputations.unshift(comp);\n }\n\n if (! options.finishSynchronously && ++recomputedCount > 1000) {\n finishedTry = true;\n return;\n }\n }\n\n if (afterFlushCallbacks.length) {\n // call one afterFlush callback, which may\n // invalidate more computations\n var func = afterFlushCallbacks.shift();\n try {\n func();\n } catch (e) {\n _throwOrLog(\"afterFlush\", e);\n }\n }\n }\n finishedTry = true;\n } finally {\n if (! finishedTry) {\n // we're erroring due to throwFirstError being true.\n inFlush = false; // needed before calling `Tracker.flush()` again\n // finish flushing\n Tracker._runFlush({\n finishSynchronously: options.finishSynchronously,\n throwFirstError: false\n });\n }\n willFlush = false;\n inFlush = false;\n if (pendingComputations.length || afterFlushCallbacks.length) {\n // We're yielding because we ran a bunch of computations and we aren't\n // required to finish synchronously, so we'd like to give the event loop a\n // chance. We should flush again soon.\n if (options.finishSynchronously) {\n throw new Error(\"still have more to do?\"); // shouldn't happen\n }\n setTimeout(requireFlush, 10);\n }\n }\n};\n\n// http://docs.meteor.com/#tracker_autorun\n//\n// Run f(). Record its dependencies. Rerun it whenever the\n// dependencies change.\n//\n// Returns a new Computation, which is also passed to f.\n//\n// Links the computation to the current computation\n// so that it is stopped if the current computation is invalidated.\n\n/**\n * @callback Tracker.ComputationFunction\n * @param {Tracker.Computation}\n */\n/**\n * @summary Run a function now and rerun it later whenever its dependencies\n * change. Returns a Computation object that can be used to stop or observe the\n * rerunning.\n * @locus Client\n * @param {Tracker.ComputationFunction} runFunc The function to run. It receives\n * one argument: the Computation object that will be returned.\n * @param {Object} [options]\n * @param {Function} options.onError Optional. The function to run when an error\n * happens in the Computation. The only argument it recieves is the Error\n * thrown. Defaults to the error being logged to the console.\n * @returns {Tracker.Computation}\n */\nTracker.autorun = function (f, options) {\n if (typeof f !== 'function')\n throw new Error('Tracker.autorun requires a function argument');\n\n options = options || {};\n\n constructingComputation = true;\n var c = new Tracker.Computation(\n f, Tracker.currentComputation, options.onError);\n\n if (Tracker.active)\n Tracker.onInvalidate(function () {\n c.stop();\n });\n\n return c;\n};\n\n// http://docs.meteor.com/#tracker_nonreactive\n//\n// Run `f` with no current computation, returning the return value\n// of `f`. Used to turn off reactivity for the duration of `f`,\n// so that reactive data sources accessed by `f` will not result in any\n// computations being invalidated.\n\n/**\n * @summary Run a function without tracking dependencies.\n * @locus Client\n * @param {Function} func A function to call immediately.\n */\nTracker.nonreactive = function (f) {\n var previous = Tracker.currentComputation;\n setCurrentComputation(null);\n try {\n return f();\n } finally {\n setCurrentComputation(previous);\n }\n};\n\n// http://docs.meteor.com/#tracker_oninvalidate\n\n/**\n * @summary Registers a new [`onInvalidate`](#computation_oninvalidate) callback on the current computation (which must exist), to be called immediately when the current computation is invalidated or stopped.\n * @locus Client\n * @param {Function} callback A callback function that will be invoked as `func(c)`, where `c` is the computation on which the callback is registered.\n */\nTracker.onInvalidate = function (f) {\n if (! Tracker.active)\n throw new Error(\"Tracker.onInvalidate requires a currentComputation\");\n\n Tracker.currentComputation.onInvalidate(f);\n};\n\n// http://docs.meteor.com/#tracker_afterflush\n\n/**\n * @summary Schedules a function to be called during the next flush, or later in the current flush if one is in progress, after all invalidated computations have been rerun. The function will be run once and not on subsequent flushes unless `afterFlush` is called again.\n * @locus Client\n * @param {Function} callback A function to call at flush time.\n */\nTracker.afterFlush = function (f) {\n afterFlushCallbacks.push(f);\n requireFlush();\n};\n","// Deprecated functions.\n\n// These functions used to be on the Meteor object (and worked slightly\n// differently).\n// XXX COMPAT WITH 0.5.7\nMeteor.flush = Tracker.flush;\nMeteor.autorun = Tracker.autorun;\n\n// We used to require a special \"autosubscribe\" call to reactively subscribe to\n// things. Now, it works with autorun.\n// XXX COMPAT WITH 0.5.4\nMeteor.autosubscribe = Tracker.autorun;\n\n// This Tracker API briefly existed in 0.5.8 and 0.5.9\n// XXX COMPAT WITH 0.5.9\nTracker.depend = function (d) {\n return d.depend();\n};\n\nDeps = Tracker;\n"]} |