_hasCrossedThreshold()

in packages/appear/src/web/intersection-observer.ts [420:441]


  _hasCrossedThreshold(oldEntry, newEntry) {
    // To make comparing easier, an entry that has a ratio of 0
    // but does not actually intersect is given a value of -1
    const oldRatio = oldEntry && oldEntry.isIntersecting
      ? oldEntry.intersectionRatio || 0 : -1;
    const newRatio = newEntry.isIntersecting
      ? newEntry.intersectionRatio || 0 : -1;

    // Ignore unchanged ratios
    if (oldRatio === newRatio) return;

    for (let i = 0; i < this.thresholds.length; i++) {
      const threshold = this.thresholds[i];

      // Return true if an entry matches a threshold or if the new ratio
      // and the old ratio are on the opposite sides of a threshold.
      if (threshold == oldRatio || threshold == newRatio ||
        threshold < oldRatio !== threshold < newRatio) {
        return true;
      }
    }
  }