Skip to content

Commit 6aa8c75

Browse files
committed
prefill previous page
1 parent e7313d1 commit 6aa8c75

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

src/prefill.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,43 @@ export default class Prefill {
1111
return;
1212
}
1313

14-
let distance = this.ias.distance();
15-
16-
if (distance > 0) {
17-
return;
18-
}
19-
2014
this.ias.emitter.emit(Events.PREFILL);
2115

22-
return this._prefill().then(() => {
16+
return Promise.all([this._prefillNext(), this._prefillPrev()]).then(() => {
2317
this.ias.emitter.emit(Events.PREFILLED);
2418

2519
// @todo reevaluate if we should actually call `measure` here.
2620
this.ias.measure();
2721
});
2822
}
2923

30-
_prefill() {
31-
return this.ias.next().then((hasNextUrl) => {
32-
if (!hasNextUrl) {
33-
return;
34-
}
24+
_prefillNext() {
25+
let distance = this.ias.distance();
26+
27+
if (distance > 0) {
28+
return;
29+
}
30+
31+
return this.ias.next()
32+
.then((hasNextUrl) => {
33+
if (!hasNextUrl) {
34+
return;
35+
}
3536

36-
let distance = this.ias.distance();
37+
let distance = this.ias.distance();
3738

38-
if (distance < 0) {
39-
return this._prefill();
40-
}
41-
});
39+
if (distance < 0) {
40+
return this._prefillNext();
41+
}
42+
})
43+
;
44+
}
45+
46+
_prefillPrev() {
47+
if (!this.ias.options.prev) {
48+
return;
49+
}
50+
51+
return this.ias.prev();
4252
}
4353
}

0 commit comments

Comments
 (0)