summaryrefslogtreecommitdiffstats
path: root/client/components/mixins/infiniteScrolling.js
blob: eb02b76f8b977e8dc84886311249bbfa26a1038d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const peakAnticipation = 200;

Mixins.InfiniteScrolling = BlazeComponent.extendComponent({
  onCreated() {
    this._nextPeak = Infinity;
  },

  setNextPeak(v) {
    this._nextPeak = v;
  },

  getNextPeak() {
    return this._nextPeak;
  },

  resetNextPeak() {
    this._nextPeak = Infinity;
  },

  events() {
    return [{
      scroll(evt) {
        const domElement = evt.currentTarget;
        let altitude = domElement.scrollTop + domElement.offsetHeight;
        altitude += peakAnticipation;
        if (altitude >= this.callFirstWith(null, 'getNextPeak')) {
          this.mixinParent().callFirstWith(null, 'reachNextPeak');
        }
      },
    }];
  },
});