PageSourceSearch

https://builder.falcon-nw.com/packages/tracker.js?hash=5287ff9f06c31b63a8712d359dc63aba784521ee

js falcon-nw.com collected 2026-09-24 21:41:31 UTC 25,055 bytes, 714 lines download raw bytes

1//////////////////////////////////////////////////////////////////////////
2//                                                                      //
3// This is a generated file. You can view the original                  //
4// source in your browser if your browser supports source maps.         //
5// Source maps are supported by all recent versions of Chrome, Safari,  //
6// and Firefox, and by Internet Explorer 11.                            //
7//                                                                      //
8//////////////////////////////////////////////////////////////////////////
9
10
11Package["core-runtime"].queue("tracker",function () {/* Imports */
12var Meteor = Package.meteor.Meteor;
13var global = Package.meteor.global;
14var meteorEnv = Package.meteor.meteorEnv;
15var meteorInstall = Package.modules.meteorInstall;
16var meteorBabelHelpers = Package.modules.meteorBabelHelpers;
17var Promise = Package.promise.Promise;
18var Symbol = Package['ecmascript-runtime-client'].Symbol;
19var Map = Package['ecmascript-runtime-client'].Map;
20var Set = Package['ecmascript-runtime-client'].Set;
21
22/* Package-scope variables */
23var Tracker, Deps;
24
25var require = meteorInstall({"node_modules":{"meteor":{"tracker":{
25"tracker.js":function module(){
26
27////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
28//                                                                                                                    //
29// packages/tracker/tracker.js                                                                                        //
30//                                                                                                                    //
31////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32                                                                                                                      //
33/////////////////////////////////////////////////////
34// Package docs at http://docs.meteor.com/#tracker //
35/////////////////////////////////////////////////////
36
37/**
38 * @namespace Tracker
39 * @summary The namespace for Tracker-related methods.
40 */
41Tracker = {};
42
43/**
44 * @namespace Deps
45 * @deprecated
46 */
47Deps = Tracker;
48
49// http://docs.meteor.com/#tracker_active
50
51/**
52 * @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.
53 * @locus Client
54 * @type {Boolean}
55 */
56Tracker.active = false;
57
58// http://docs.meteor.com/#tracker_currentcomputation
59
60/**
61 * @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.
62 * @locus Client
63 * @type {Tracker.Computation}
64 */
65Tracker.currentComputation = null;
66function _debugFunc() {
67  // We want this code to work without Meteor, and also without
68  // "console" (which is technically non-standard and may be missing
69  // on some browser we come across, like it was on IE 7).
70  //
71  // Lazy evaluation because `Meteor` does not exist right away.(??)
72  return typeof Meteor !== "undefined" ? Meteor._debug : typeof console !== "undefined" && console.error ? function () {
73    console.error.apply(console, arguments);
74  } : function () {};
75}
76function _maybeSuppressMoreLogs(messagesLength) {
77  // Sometimes when running tests, we intentionally suppress logs on expected
78  // printed errors. Since the current implementation of _throwOrLog can log
79  // multiple separate log messages, suppress all of them if at least one suppress
80  // is expected as we still want them to count as one.
81  if (typeof Meteor !== "undefined") {
82    if (Meteor._suppressed_log_expected()) {
83      Meteor._suppress_log(messagesLength - 1);
84    }
85  }
86}
87function _throwOrLog(from, e) {
88  if (throwFirstError) {
89    throw e;
90  } else {
91    var printArgs = ["Exception from Tracker " + from + " function:"];
92    if (e.stack && e.message && e.name) {
93      var idx = e.stack.indexOf(e.message);
94      if (idx < 0 || idx > e.name.length + 2) {
95        // check for "Error: "
96        // message is not part of the stack
97        var message = e.name + ": " + e.message;
98        printArgs.push(message);
99      }
100    }
101    printArgs.push(e.stack);
102    _maybeSuppressMoreLogs(printArgs.length);
103    for (var i = 0; i < printArgs.length; i++) {
104      _debugFunc()(printArgs[i]);
105    }
106  }
107}
108
109// Takes a function `f`, and wraps it in a `Meteor._noYieldsAllowed`
110// block if we are running on the server. On the client, returns the
111// original function (since `Meteor._noYieldsAllowed` is a
112// no-op). This has the benefit of not adding an unnecessary stack
113// frame on the client.
114function withNoYieldsAllowed(f) {
115  if (typeof Meteor === 'undefined' || Meteor.isClient) {
116    return f;
117  } else {
118    return function () {
119      var args = arguments;
120      Meteor._noYieldsAllowed(function () {
121        f.apply(null, args);
122      });
123    };
124  }
125}
126var nextId = 1;
127// computations whose callbacks we should call at flush time
128var pendingComputations = [];
129// `true` if a Tracker.flush is scheduled, or if we are in Tracker.flush now
130var willFlush = false;
131// `true` if we are in Tracker.flush now
132var inFlush = false;
133// `true` if we are computing a computation now, either first time
134// or recompute.  This matches Tracker.active unless we are inside
135// Tracker.nonreactive, which nullfies currentComputation even though
136// an enclosing computation may still be running.
137var inCompute = false;
138// `true` if the `_throwFirstError` option was passed in to the call
139// to Tracker.flush that we are in. When set, throw rather than log the
140// first error encountered while flushing. Before throwing the error,
141// finish flushing (from a finally block), logging any subsequent
142// errors.
143var throwFirstError = false;
144var afterFlushCallbacks = [];
145function requireFlush() {
146  if (!willFlush) {
147    // We want this code to work without Meteor, see debugFunc above
148    if (typeof Meteor !== "undefined") Meteor._setImmediate(Tracker._runFlush);else setTimeout(Tracker._runFlush, 0);
149    willFlush = true;
150  }
151}
152
153// Tracker.Computation constructor is visible but private
154// (throws an error if you try to call it)
155var constructingComputation = false;
156
157//
158// http://docs.meteor.com/#tracker_computation
159
160/**
161 * @summary A Computation object represents code that is repeatedly rerun
162 * in response to
163 * reactive data changes. Computations don't have return values; they just
164 * perform actions, such as rerendering a template on the screen. Computations
165 * are created using Tracker.autorun. Use stop to prevent further rerunning of a
166 * computation.
167 * @instancename computation
168 */
169Tracker.Computation = /*#__PURE__*/function () {
170  function Computation(f, parent, onError) {
171    if (!constructingComputation) throw new Error("Tracker.Computation constructor is private; use Tracker.autorun");
172    constructingComputation = false;
173
174    // http://docs.meteor.com/#computation_stopped
175
176    /**
177     * @summary True if this computation has been stopped.
178     * @locus Client
179     * @memberOf Tracker.Computation
180     * @instance
181     * @name  stopped
182     */
183    this.stopped = false;
184
185    // http://docs.meteor.com/#computation_invalidated
186
187    /**
188     * @summary True if this computation has been invalidated (and not yet rerun), or if it has been stopped.
189     * @locus Client
190     * @memberOf Tracker.Computation
191     * @instance
192     * @name  invalidated
193     * @type {Boolean}
194     */
195    this.invalidated = false;
196
197    // http://docs.meteor.com/#computation_firstrun
198
199    /**
200     * @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.
201     * @locus Client
202     * @memberOf Tracker.Computation
203     * @instance
204     * @name  firstRun
205     * @type {Boolean}
206     */
207    this.firstRun = true;
208    this._id = nextId++;
209    this._onInvalidateCallbacks = [];
210    this._onStopCallbacks = [];
211    // the plan is at some point to use the parent relation
212    // to constrain the order that computations are processed
213    this._parent = parent;
214    this._func = f;
215    this._onError = onError;
216    this._recomputing = false;
217
218    /**
219     * @summary Forces autorun blocks to be executed in synchronous-looking order by storing the value autorun promise thus making it awaitable.
220     * @locus Client
221     * @memberOf Tracker.Computation
222     * @instance
223     * @name  firstRunPromise
224     * @returns {Promise<unknown>}
225     */
226    this.firstRunPromise = undefined;
227    var errored = true;
228    try {
229      this._compute();
230      errored = false;
231    } finally {
232      this.firstRun = false;
233      if (errored) this.stop();
234    }
235  }
236
237  /**
238  * Resolves the firstRunPromise with the result of the autorun function.
239  * @param {*} onResolved
240  * @param {*} onRejected
241  * @returns{Promise<unknown}
242  */
243  var _proto = Computation.prototype;
244  _proto.then = function () {
245    function then(onResolved, onRejected) {
246      return this.firstRunPromise.then(onResolved, onRejected);
247    }
248    return then;
249  }();
250  _proto.catch = function () {
251    function _catch(onRejected) {
252      return this.firstRunPromise.catch(onRejected);
253    }
254    return _catch;
255  }();
256  // http://docs.meteor.com/#computation_oninvalidate
257  /**
258   * @summary Registers `callback` to run when this computation is next invalidated, or runs it immediately if the computation is already invali
258dated.  The callback is run exactly once and not upon future invalidations unless `onInvalidate` is called again after the computation becomes valid again.
259   * @locus Client
260   * @param {Function} callback Function to be called on invalidation. Receives one argument, the computation that was invalidated.
261   */
262  _proto.onInvalidate = function () {
263    function onInvalidate(f) {
264      var _this = this;
265      if (typeof f !== 'function') throw new Error("onInvalidate requires a function");
266      if (this.invalidated) {
267        Tracker.nonreactive(function () {
268          withNoYieldsAllowed(f)(_this);
269        });
270      } else {
271        this._onInvalidateCallbacks.push(f);
272      }
273    }
274    return onInvalidate;
275  }()
276  /**
277   * @summary Registers `callback` to run when this computation is stopped, or runs it immediately if the computation is already stopped.  The callback is run after any `onInvalidate` callbacks.
278   * @locus Client
279   * @param {Function} callback Function to be called on stop. Receives one argument, the computation that was stopped.
280   */
281  ;
282  _proto.onStop = function () {
283    function onStop(f) {
284      var _this2 = this;
285      if (typeof f !== 'function') throw new Error("onStop requires a function");
286      if (this.stopped) {
287        Tracker.nonreactive(function () {
288          withNoYieldsAllowed(f)(_this2);
289        });
290      } else {
291        this._onStopCallbacks.push(f);
292      }
293    }
294    return onStop;
295  }() // http://docs.meteor.com/#computation_invalidate
296  /**
297   * @summary Invalidates this computation so that it will be rerun.
298   * @locus Client
299   */
300  ;
301  _proto.invalidate = function () {
302    function invalidate() {
303      var _this3 = this;
304      if (!this.invalidated) {
305        // if we're currently in _recompute(), don't enqueue
306        // ourselves, since we'll rerun immediately anyway.
307        if (!this._recomputing && !this.stopped) {
308          requireFlush();
309          pendingComputations.push(this);
310        }
311        this.invalidated = true;
312
313        // callbacks can't add callbacks, because
314        // this.invalidated === true.
315        for (var i = 0, f; f = this._onInvalidateCallbacks[i]; i++) {
316          Tracker.nonreactive(function () {
317            withNoYieldsAllowed(f)(_this3);
318          });
319        }
320        this._onInvalidateCallbacks = [];
321      }
322    }
323    return invalidate;
324  }() // http://docs.meteor.com/#computation_stop
325  /**
326   * @summary Prevents this computation from rerunning.
327   * @locus Client
328   */
329  ;
330  _proto.stop = function () {
331    function stop() {
332      var _this4 = this;
333      if (!this.stopped) {
334        this.stopped = true;
335        this.invalidate();
336        for (var i = 0, f; f = this._onStopCallbacks[i]; i++) {
337          Tracker.nonreactive(function () {
338            withNoYieldsAllowed(f)(_this4);
339          });
340        }
341        this._onStopCallbacks = [];
342      }
343    }
344    return stop;
345  }();
346  _proto._compute = function () {
347    function _compute() {
348      var _this5 = this;
349      this.invalidated = false;
350      var previousInCompute = inCompute;
351      inCompute = true;
352      try {
353        // In case of async functions, the result of this function will contain the promise of the autorun function
354        // & make autoruns await-able.
355        var firstRunPromise = Tracker.withComputation(this, function () {
356          return withNoYieldsAllowed(_this5._func)(_this5);
357        });
358        // We'll store the firstRunPromise on the computation so it can be awaited by the callers, but only
359        // during the first run. We don't want things to get mixed up.
360        if (this.firstRun) {
361          this.firstRunPromise = Promise.resolve(firstRunPromise);
362        }
363      } finally {
364        inCompute = previousInCompute;
365      }
366    }
367    return _compute;
368  }();
369  _proto._needsRecompute = function () {
370    function _needsRecompute() {
371      return this.invalidated && !this.stopped;
372    }
373    return _needsRecompute;
374  }();
375  _proto._recompute = function () {
376    function _recompute() {
377      this._recomputing = true;
378      try {
379        if (this._needsRecompute()) {
380          try {
381            this._compute();
382          } catch (e) {
383            if (this._onError) {
384              this._onError(e);
385            } else {
386              _throwOrLog("recompute", e);
387            }
388          }
389        }
390      } finally {
391        this._recomputing = false;
392      }
393    }
394    return _recompute;
395  }()
396  /**
397   * @summary Process the reactive updates for this computation immediately
398   * and ensure that the computation is rerun. The computation is rerun only
399   * if it is invalidated.
400   * @locus Client
401   */
402  ;
403  _proto.flush = function () {
404    function flush() {
405      if (this._recomputing) return;
406      this._recompute();
407    }
408    return flush;
409  }()
410  /**
411   * @summary Causes the function inside this computation to run and
412   * synchronously process all reactive updtes.
413   * @locus Client
414   */
415  ;
416  _proto.run = function () {
417    function run() {
418      this.invalidate();
419      this.flush();
420    }
421    return run;
422  }();
423  return Computation;
424}();
425
426//
427// http://docs.meteor.com/#tracker_dependency
428
429/**
430 * @summary A Dependency represents an atomic unit of reactive data that a
431 * computation might depend on. Reactive data sources such as Session or
432 * Minimongo internally create different Dependency objects for different
433 * pieces of data, each of which may be depended on by multiple computations.
434 * When the data changes, the computations are invalidated.
435 * @class
436 * @instanceName dependency
437 */
438Tracker.Dependency = /*#__PURE__*/function () {
439  function Dependency() {
440    this._dependentsById = Object.create(null);
441  }
442
443  // http://docs.meteor.com/#dependency_depend
444  //
445  // Adds `computation` to this set if it is not already
446  // present.  Returns true if `computation` is a new member of the set.
447  // If no argument, defaults to currentComputation, or does nothing
448  // if there is no currentComputation.
449
450  /**
451   * @summary Declares that the current computation (or `fromComputation` if given) depen
451ds on `dependency`.  The computation will be invalidated the next time `dependency` changes.
452    If there is no current computation and `depend()` is called with no arguments, it does nothing and returns false.
453    Returns true if the computation is a new dependent of `dependency` rather than an existing one.
454   * @locus Client
455   * @param {Tracker.Computation} [fromComputation] An optional computation declared to depend on `dependency` instead of the current computation.
456   * @returns {Boolean}
457   */
458  var _proto2 = Dependency.prototype;
459  _proto2.depend = function () {
460    function depend(computation) {
461      var _this6 = this;
462      if (!computation) {
463        if (!Tracker.active) return false;
464        computation = Tracker.currentComputation;
465      }
466      var id = computation._id;
467      if (!(id in this._dependentsById)) {
468        this._dependentsById[id] = computation;
469        computation.onInvalidate(function () {
470          delete _this6._dependentsById[id];
471        });
472        return true;
473      }
474      return false;
475    }
476    return depend;
477  }() // http://docs.meteor.com/#dependency_changed
478  /**
479   * @summary Invalidate all dependent computations immediately and remove them as dependents.
480   * @locus Client
481   */
482  ;
483  _proto2.changed = function () {
484    function changed() {
485      for (var id in meteorBabelHelpers.sanitizeForInObject(this._dependentsById)) this._dependentsById[id].invalidate();
486    }
487    return changed;
488  }() // http://docs.meteor.com/#dependency_hasdependents
489  /**
490   * @summary True if this Dependency has one or more dependent Computations, which would be invalidated if this Dependency were to change.
491   * @locus Client
492   * @returns {Boolean}
493   */
494  ;
495  _proto2.hasDependents = function () {
496    function hasDependents() {
497      for (var id in meteorBabelHelpers.sanitizeForInObject(this._dependentsById)) return true;
498      return false;
499    }
500    return hasDependents;
501  }();
502  return Dependency;
503}();
504
505// http://docs.meteor.com/#tracker_flush
506
507/**
508 * @summary Process all reactive updates immediately and ensure that all invalidated computations are rerun.
509 * @locus Client
510 */
511Tracker.flush = function (options) {
512  Tracker._runFlush({
513    finishSynchronously: true,
514    throwFirstError: options && options._throwFirstError
515  });
516};
517
518/**
519 * @summary True if we are computing a computation now, either first time or recompute.  This matches Tracker.active unless we are inside Tracker.nonreactive, which nullfies currentComputation even though an enclosing computation may still be running.
520 * @locus Client
521 * @returns {Boolean}
522 */
523Tracker.inFlush = function () {
524  return inFlush;
525};
526
527// Run all pending computations and afterFlush callbacks.  If we were not called
528// directly via Tracker.flush, this may return before they're all done to allow
529// the event loop to run a little before continuing.
530Tracker._runFlush = function (options) {
531  // XXX What part of the comment below is still true? (We no longer
532  // have Spark)
533  //
534  // Nested flush could plausibly happen if, say, a flush causes
535  // DOM mutation, which causes a "blur" event, which runs an
536  // app event handler that calls Tracker.flush.  At the moment
537  // Spark blocks event handlers during DOM mutation anyway,
538  // because the LiveRange tree isn't valid.  And we don't have
539  // any useful notion of a nested flush.
540  //
541  // https://app.asana.com/0/159908330244/385138233856
542  if (Tracker.inFlush()) throw new Error("Can't call Tracker.flush while flushing");
543  if (inCompute) throw new Error("Can't flush inside Tracker.autorun");
544  options = options || {};
545  inFlush = true;
546  willFlush = true;
547  throwFirstError = !!options.throwFirstError;
548  var recomputedCount = 0;
549  var finishedTry = false;
550  try {
551    while (pendingComputations.length || afterFlushCallbacks.length) {
552      // recompute all pending computations
553      while (pendingComputations.length) {
554        var comp = pendingComputations.shift();
555        comp._recompute();
556        if (comp._needsRecompute()) {
557          pendingComputations.unshift(comp);
558        }
559        if (!options.finishSynchronously && ++recomputedCount > 1000) {
560          finishedTry = true;
561          return;
562        }
563      }
564      if (afterFlushCallbacks.length) {
565        // call one afterFlush callback, which may
566        // invalidate more computations
567        var func = afterFlushCallbacks.shift();
568        try {
569          func();
570        } catch (e) {
571          _throwOrLog("afterFlush", e);
572        }
573      }
574    }
575    finishedTry = true;
576  } finally {
577    if (!finishedTry) {
578      // we're erroring due to throwFirstError being true.
579      inFlush = false; // needed before calling `Tracker.flush()` again
580      // finish flushing
581      Tracker._runFlush({
582        finishSynchronously: options.finishSynchronously,
583        throwFirstError: false
584      });
585    }
586    willFlush = false;
587    inFlush = false;
588    if (pendingComputations.length || afterFlushCallbacks.length) {
589      // We're yielding because we ran a bunch of computations and we aren't
590      // required to finish synchronously, so we'd like to give the event loop a
591      // chance. We should flush again soon.
592      if (options.finishSynchronously) {
593        throw new Error("still have more to do?"); // shouldn't happen
594      }
595      setTimeout(requireFlush, 10);
596    }
597  }
598};
599
600// http://docs.meteor.com/#tracker_autorun
601//
602// Run f(). Record its dependencies. Rerun it whenever the
603// dependencies change.
604//
605// Returns a new Computation, which is also passed to f.
606//
607// Links the computation to the current computation
608// so that it is stopped if the current computation is invalidated.
609
610/**
611 * @callback Tracker.ComputationFunction
612 * @param {Tracker.Computation}
613 */
614/**
615 * @summary Run a function now and rerun it later whenever its dependencies
616 * change. Returns a Computation object that can be used to stop or observe the
617 * rerunning.
618 * @locus Client
619 * @param {Tracker.ComputationFunction} runFunc The function to run. It receives
620 * one argument: the Computation object that will be returned.
621 * @param {Object} [options]
622 * @param {Function} options.onError Optional. The function to run when an error
623 * happens in the Computation. The only argument it receives is the Error
624 * thrown. Defaults to the error being logged to the console.
625 * @returns {Tracker.Computation}
626 */
627Tracker.autorun = function (f) {
628  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
629  if (typeof f !== 'function') throw new Error('Tracker.autorun requires a function argument');
630  constructingComputation = true;
631  var c = new Tracker.Computation(f, Tracker.currentComputation, options.onError);
632  if (Tracker.active) Tracker.onInvalidate(function () {
633    c.stop();
634  });
635  return c;
636};
637
638// http://docs.meteor.com/#tracker_nonreactive
639//
640// Run `f` with no current computation, returning the return value
641// of `f`.  Used to turn off reactivity for the duration of `f`,
642// so that reactive data sources accessed by `f` will not result in any
643// computations being invalidated.
644
645/**
646 * @summary Run a function without tracking dependencies.
647 * @locus Client
648 * @param {Function} func A function to call immediately.
649 */
650Tracker.nonreactive = function (f) {
651  return Tracker.withComputation(null, f);
652};
653
654/**
655 * @summary Helper function to make the tracker work with promises.
656 * @param computation Computation that tracked
657 * @param func async function that needs to be called and be reactive
658 */
659Tracker.withComputation = function (computation, f) {
660  var previousComputation = Tracker.currentComputation;
661  Tracker.currentComputation = computation;
662  Tracker.active = !!computation;
663  try {
664    return f();
665  } finally {
666    Tracker.currentComputation = previousComputation;
667    Tracker.active = !!previousComputation;
668  }
669};
670
671// http://docs.meteor.com/#tracker_oninvalidate
672
673/**
674 * @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.
675 * @locus Client
676 * @param {Function} callback A callback function that will be invoked as `func(c)`, where `c` is the computation on which the callback is registered.
677 */
678Tracker.onInvalidate = function (f) {
679  if (!Tracker.active) throw new Error("Tracker.onInvalidate requires a currentComputation");
680  Tracker.currentComputation.onInvalidate(f);
681};
682
683// http://docs.meteor.com/#tracker_afterflush
684
685/**
686 * @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.
687 * @locus Client
688 * @param {Function} callback A function to call at flush time.
689 */
690Tracker.afterFlush = function (f) {
691  afterFlushCallbacks.push(f);
692  requireFlush();
693};
694////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
695
696}
696}}}},{
697  "extensions": [
698    ".js",
699    ".json"
700  ]
701});
702
703
704/* Exports */
705return {
706  export: function () { return {
707      Tracker: Tracker,
708      Deps: Deps
709    };},
710  require: require,
711  eagerModulePaths: [
712    "/node_modules/meteor/tracker/tracker.js"
713  ]
714}});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.