navigation-stack 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,5 +2,6 @@
2
2
  "private": true,
3
3
  "name": "navigation-stack/data-storage",
4
4
  "main": "./../lib/cjs/data-storage/index.js",
5
- "module": "./../lib/esm/data-storage/index.js"
5
+ "module": "./../lib/esm/data-storage/index.js",
6
+ "types": "./../lib/data-storage/index.d.ts"
6
7
  }
@@ -133,11 +133,11 @@ class ScrollPositionRestoration {
133
133
  // This function is only used in tests.
134
134
  // There seems to be no use of it in real life, hence it's not public API.
135
135
  // It's only used in tests.
136
- _getScrollPositionForLocation: _options && _options._getPageScrollPositionForLocation,
136
+ _getSavedScrollPositionOnLocationChange: _options && _options._getSavedPageScrollPositionOnLocationChange,
137
137
  // This function is only used in tests.
138
138
  // There seems to be no use of it in real life, hence it's not public API.
139
139
  // It's only used in tests.
140
- _shouldUpdateScrollPositionForLocation: _options && _options._shouldUpdatePageScrollPositionForLocation
140
+ _shouldSetScrollPositionOnLocationChange: _options && _options._shouldSetPageScrollPositionOnLocationChange
141
141
  };
142
142
  }
143
143
  addScrollableContainer(scrollableContainerKey, scrollableContainer, _options) {
@@ -172,11 +172,11 @@ class ScrollPositionRestoration {
172
172
  // This function is only used in tests.
173
173
  // There seems to be no use of it in real life, hence it's not public API.
174
174
  // It's only used in tests.
175
- _shouldUpdateScrollPositionForLocation: _options && _options._shouldUpdateScrollPositionForLocation,
175
+ _shouldSetScrollPositionOnLocationChange: _options && _options._shouldSetScrollPositionOnLocationChange,
176
176
  // This function is only used in tests.
177
177
  // There seems to be no use of it in real life, hence it's not public API.
178
178
  // It's only used in tests.
179
- _getScrollPositionForLocation: _options && _options._getScrollPositionForLocation
179
+ _getSavedScrollPositionOnLocationChange: _options && _options._getSavedScrollPositionOnLocationChange
180
180
  };
181
181
 
182
182
  // Scrollable containers could be added at any time, including page mount.
@@ -334,8 +334,8 @@ class ScrollPositionRestoration {
334
334
  // This function is only used in tests.
335
335
  // There seems to be no use of it in real life, hence it's not public API.
336
336
  // It's only used in tests.
337
- if (scrollableContainerEntry._shouldUpdateScrollPositionForLocation) {
338
- if (!scrollableContainerEntry._shouldUpdateScrollPositionForLocation(this._location, this._prevLocation)) {
337
+ if (scrollableContainerEntry._shouldSetScrollPositionOnLocationChange) {
338
+ if (!scrollableContainerEntry._shouldSetScrollPositionOnLocationChange(this._location, this._prevLocation)) {
339
339
  return Promise.resolve();
340
340
  }
341
341
  }
@@ -346,8 +346,8 @@ class ScrollPositionRestoration {
346
346
  // This function is only used in tests.
347
347
  // There seems to be no use of it in real life, hence it's not public API.
348
348
  // It's only used in tests.
349
- if (scrollableContainerEntry._getScrollPositionForLocation) {
350
- scrollPositionOrAnchorToSet = scrollableContainerEntry._getScrollPositionForLocation(this._location, this._prevLocation);
349
+ if (scrollableContainerEntry._getSavedScrollPositionOnLocationChange) {
350
+ scrollPositionOrAnchorToSet = scrollableContainerEntry._getSavedScrollPositionOnLocationChange(this._location, this._prevLocation);
351
351
  }
352
352
 
353
353
  // Get scroll position (or anchor) to set.
@@ -128,11 +128,11 @@ export default class ScrollPositionRestoration {
128
128
  // This function is only used in tests.
129
129
  // There seems to be no use of it in real life, hence it's not public API.
130
130
  // It's only used in tests.
131
- _getScrollPositionForLocation: _options && _options._getPageScrollPositionForLocation,
131
+ _getSavedScrollPositionOnLocationChange: _options && _options._getSavedPageScrollPositionOnLocationChange,
132
132
  // This function is only used in tests.
133
133
  // There seems to be no use of it in real life, hence it's not public API.
134
134
  // It's only used in tests.
135
- _shouldUpdateScrollPositionForLocation: _options && _options._shouldUpdatePageScrollPositionForLocation
135
+ _shouldSetScrollPositionOnLocationChange: _options && _options._shouldSetPageScrollPositionOnLocationChange
136
136
  };
137
137
  }
138
138
  addScrollableContainer(scrollableContainerKey, scrollableContainer, _options) {
@@ -167,11 +167,11 @@ export default class ScrollPositionRestoration {
167
167
  // This function is only used in tests.
168
168
  // There seems to be no use of it in real life, hence it's not public API.
169
169
  // It's only used in tests.
170
- _shouldUpdateScrollPositionForLocation: _options && _options._shouldUpdateScrollPositionForLocation,
170
+ _shouldSetScrollPositionOnLocationChange: _options && _options._shouldSetScrollPositionOnLocationChange,
171
171
  // This function is only used in tests.
172
172
  // There seems to be no use of it in real life, hence it's not public API.
173
173
  // It's only used in tests.
174
- _getScrollPositionForLocation: _options && _options._getScrollPositionForLocation
174
+ _getSavedScrollPositionOnLocationChange: _options && _options._getSavedScrollPositionOnLocationChange
175
175
  };
176
176
 
177
177
  // Scrollable containers could be added at any time, including page mount.
@@ -329,8 +329,8 @@ export default class ScrollPositionRestoration {
329
329
  // This function is only used in tests.
330
330
  // There seems to be no use of it in real life, hence it's not public API.
331
331
  // It's only used in tests.
332
- if (scrollableContainerEntry._shouldUpdateScrollPositionForLocation) {
333
- if (!scrollableContainerEntry._shouldUpdateScrollPositionForLocation(this._location, this._prevLocation)) {
332
+ if (scrollableContainerEntry._shouldSetScrollPositionOnLocationChange) {
333
+ if (!scrollableContainerEntry._shouldSetScrollPositionOnLocationChange(this._location, this._prevLocation)) {
334
334
  return Promise.resolve();
335
335
  }
336
336
  }
@@ -341,8 +341,8 @@ export default class ScrollPositionRestoration {
341
341
  // This function is only used in tests.
342
342
  // There seems to be no use of it in real life, hence it's not public API.
343
343
  // It's only used in tests.
344
- if (scrollableContainerEntry._getScrollPositionForLocation) {
345
- scrollPositionOrAnchorToSet = scrollableContainerEntry._getScrollPositionForLocation(this._location, this._prevLocation);
344
+ if (scrollableContainerEntry._getSavedScrollPositionOnLocationChange) {
345
+ scrollPositionOrAnchorToSet = scrollableContainerEntry._getSavedScrollPositionOnLocationChange(this._location, this._prevLocation);
346
346
  }
347
347
 
348
348
  // Get scroll position (or anchor) to set.
@@ -15,18 +15,18 @@ export class ScrollPositionRestoration<
15
15
 
16
16
  // `_options` are currently only used in tests.
17
17
  _options?: {
18
- // `_options._shouldUpdatePageScrollPositionForLocation`
18
+ // `_options._shouldSetPageScrollPositionOnLocationChange`
19
19
  // isn't used in real life and is not part of the public API.
20
20
  // It's only used in tests.
21
- _shouldUpdatePageScrollPositionForLocation?: (
21
+ _shouldSetPageScrollPositionOnLocationChange?: (
22
22
  location: Location,
23
23
  prevLocation: Location | undefined,
24
24
  ) => boolean;
25
25
 
26
- // `_options._getPageScrollPositionForLocation`
26
+ // `_options._getSavedPageScrollPositionOnLocationChange`
27
27
  // isn't used in real life and is not part of the public API.
28
28
  // It's only used in tests.
29
- _getPageScrollPositionForLocation?: (
29
+ _getSavedPageScrollPositionOnLocationChange?: (
30
30
  location: Location,
31
31
  prevLocation: Location | undefined,
32
32
  ) => [number, number] | undefined;
@@ -34,7 +34,7 @@ export class ScrollPositionRestoration<
34
34
  // Using this option, a developer could theoretically provide their own implementation
35
35
  // of setting a scroll position. For example, it could use "smooth" (animated) scrolling, etc.
36
36
  // This could be part of the public API if anyone provided a sensible real-world use case for it.
37
- _pageScrollPositionSetter: ScrollPositionSetter<
37
+ _pageScrollPositionSetter?: ScrollPositionSetter<
38
38
  ScrollableContainer,
39
39
  Anchor
40
40
  >;
@@ -47,18 +47,18 @@ export class ScrollPositionRestoration<
47
47
 
48
48
  // `_options` are currently only used in tests.
49
49
  _options?: {
50
- // `_options._shouldUpdateScrollPositionForLocation`
50
+ // `_options._shouldSetScrollPositionOnLocationChange`
51
51
  // isn't used in real life and is not part of the public API.
52
52
  // It's only used in tests.
53
- _shouldUpdateScrollPositionForLocation?: (
53
+ _shouldSetScrollPositionOnLocationChange?: (
54
54
  location: Location,
55
55
  prevLocation: Location | undefined,
56
56
  ) => boolean;
57
57
 
58
- // `_options._getScrollPositionForLocation`
58
+ // `_options._getSavedScrollPositionOnLocationChange`
59
59
  // isn't used in real life and is not part of the public API.
60
60
  // It's only used in tests.
61
- _getScrollPositionForLocation?: (
61
+ _getSavedScrollPositionOnLocationChange?: (
62
62
  location: Location,
63
63
  prevLocation: Location | undefined,
64
64
  ) => [number, number] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "navigation-stack",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Handles navigation in a web browser",
5
5
  "keywords": [
6
6
  "history",
@@ -2,5 +2,6 @@
2
2
  "private": true,
3
3
  "name": "navigation-stack/redux",
4
4
  "main": "./../lib/cjs/redux/index.js",
5
- "module": "./../lib/esm/redux/index.js"
5
+ "module": "./../lib/esm/redux/index.js",
6
+ "types": "./../lib/redux/index.d.ts"
6
7
  }
@@ -2,5 +2,6 @@
2
2
  "private": true,
3
3
  "name": "navigation-stack/scroll-position",
4
4
  "main": "./../lib/cjs/scroll-position/index.js",
5
- "module": "./../lib/esm/scroll-position/index.js"
5
+ "module": "./../lib/esm/scroll-position/index.js",
6
+ "types": "./../lib/scroll-position/index.d.ts"
6
7
  }
@@ -59,14 +59,14 @@ export default class ScrollPositionRestoration {
59
59
  // This function is only used in tests.
60
60
  // There seems to be no use of it in real life, hence it's not public API.
61
61
  // It's only used in tests.
62
- _getScrollPositionForLocation:
63
- _options && _options._getPageScrollPositionForLocation,
62
+ _getSavedScrollPositionOnLocationChange:
63
+ _options && _options._getSavedPageScrollPositionOnLocationChange,
64
64
 
65
65
  // This function is only used in tests.
66
66
  // There seems to be no use of it in real life, hence it's not public API.
67
67
  // It's only used in tests.
68
- _shouldUpdateScrollPositionForLocation:
69
- _options && _options._shouldUpdatePageScrollPositionForLocation,
68
+ _shouldSetScrollPositionOnLocationChange:
69
+ _options && _options._shouldSetPageScrollPositionOnLocationChange,
70
70
  };
71
71
  }
72
72
 
@@ -114,14 +114,14 @@ export default class ScrollPositionRestoration {
114
114
  // This function is only used in tests.
115
115
  // There seems to be no use of it in real life, hence it's not public API.
116
116
  // It's only used in tests.
117
- _shouldUpdateScrollPositionForLocation:
118
- _options && _options._shouldUpdateScrollPositionForLocation,
117
+ _shouldSetScrollPositionOnLocationChange:
118
+ _options && _options._shouldSetScrollPositionOnLocationChange,
119
119
 
120
120
  // This function is only used in tests.
121
121
  // There seems to be no use of it in real life, hence it's not public API.
122
122
  // It's only used in tests.
123
- _getScrollPositionForLocation:
124
- _options && _options._getScrollPositionForLocation,
123
+ _getSavedScrollPositionOnLocationChange:
124
+ _options && _options._getSavedScrollPositionOnLocationChange,
125
125
  };
126
126
 
127
127
  // Scrollable containers could be added at any time, including page mount.
@@ -390,9 +390,11 @@ export default class ScrollPositionRestoration {
390
390
  // This function is only used in tests.
391
391
  // There seems to be no use of it in real life, hence it's not public API.
392
392
  // It's only used in tests.
393
- if (scrollableContainerEntry._shouldUpdateScrollPositionForLocation) {
393
+ if (
394
+ scrollableContainerEntry._shouldSetScrollPositionOnLocationChange
395
+ ) {
394
396
  if (
395
- !scrollableContainerEntry._shouldUpdateScrollPositionForLocation(
397
+ !scrollableContainerEntry._shouldSetScrollPositionOnLocationChange(
396
398
  this._location,
397
399
  this._prevLocation,
398
400
  )
@@ -407,9 +409,9 @@ export default class ScrollPositionRestoration {
407
409
  // This function is only used in tests.
408
410
  // There seems to be no use of it in real life, hence it's not public API.
409
411
  // It's only used in tests.
410
- if (scrollableContainerEntry._getScrollPositionForLocation) {
412
+ if (scrollableContainerEntry._getSavedScrollPositionOnLocationChange) {
411
413
  scrollPositionOrAnchorToSet =
412
- scrollableContainerEntry._getScrollPositionForLocation(
414
+ scrollableContainerEntry._getSavedScrollPositionOnLocationChange(
413
415
  this._location,
414
416
  this._prevLocation,
415
417
  );
@@ -255,42 +255,145 @@ describe('NavigationStack', () => {
255
255
  index: 1,
256
256
  });
257
257
  });
258
+ });
259
+
260
+ describe('NavigationStack (maintainScrollPosition: true)', () => {
261
+ let navigationStack;
262
+
263
+ afterEach(() => {
264
+ // Even if a test errors, the `NavigationStack` should still be stopped
265
+ // in order to remove the potential "popstate" listener so that it doesn't
266
+ // interfere with other tests.
267
+ //
268
+ // `navigationStack.stop()` method is "idempotent", i.e. it can be called multiple times.
269
+ //
270
+ navigationStack.stop();
271
+ });
258
272
 
259
273
  it('should support `maintainScrollPosition: true` option', async () => {
260
274
  navigationStack = new NavigationStack(new WebBrowserSession(), {
261
275
  maintainScrollPosition: true,
262
276
  });
263
277
 
278
+ // Start with the "/initial" page.
279
+ window.history.replaceState(null, null, '/initial');
280
+
281
+ // Initialize `NavigationStack`.
264
282
  navigationStack.init();
265
283
 
266
- navigationStack.locationRendered();
284
+ // "/initial" page rendered.
285
+ // Restore scroll position (no saved scroll position to restore).
286
+ await navigationStack.locationRendered();
267
287
 
268
- navigationStack.push('/new');
288
+ // Create a content <div/> that "overflows" the window so that it becomes scrollable.
289
+ const content = document.createElement('div');
290
+ content.style.height = '10000px';
291
+ content.style.width = '10000px';
292
+ document.body.appendChild(content);
269
293
 
270
- navigationStack.locationRendered();
294
+ // Scroll the page to some position.
295
+ // The scroll position will be saved.
296
+ window.scrollTo(0, 1000);
297
+
298
+ // Check that it has scrolled to that position.
299
+ expect(window.pageYOffset).to.be.closeTo(1000, 0.5);
300
+
301
+ // Wait a bit for `ScrollPositionRestoration` to save the scroll position
302
+ // because it does that "asynchronously", i.e. in an "immediate" timeout
303
+ // as a way of "throttling" scroll events.
304
+ await delay(20);
305
+
306
+ // Go to "/new" page.
307
+ navigationStack.push('/new');
271
308
 
309
+ // Create a scrollable container to test its scroll position restoration later.
272
310
  const scrollableContainer = document.createElement('div');
311
+ scrollableContainer.style.height = '100px';
312
+ scrollableContainer.style.width = '100px';
313
+ // With default `overflow` value, the scrollable container won't become scrollable
314
+ // and will simply stretch vertically according to the child content.
315
+ scrollableContainer.style.overflow = 'auto';
316
+ // "Overflow" the scrollable container with nested content so that it becomes scrollable.
317
+ scrollableContainer.innerHTML = '<div style="height: 10000px"></div>';
273
318
  document.body.appendChild(scrollableContainer);
274
319
 
275
- const removeScrollableContainer = navigationStack.addScrollableContainer(
320
+ // "/new" page rendered.
321
+ // Restore scroll position (no saved scroll position to restore).
322
+ await navigationStack.locationRendered();
323
+
324
+ // It should've reset page scroll position.
325
+ expect(window.pageYOffset).to.equal(0);
326
+
327
+ // Scroll the page to some position.
328
+ // The scroll position will be saved.
329
+ window.scrollTo(0, 500);
330
+
331
+ // Check that it has scrolled to that position.
332
+ expect(window.pageYOffset).to.be.closeTo(500, 0.5);
333
+
334
+ // Scroll inside the scrollable container to see if the scroll position
335
+ // is restored later when revisiting this page.
336
+ scrollableContainer.scrollTo(0, 1000);
337
+
338
+ // Check that it has scrolled to that position.
339
+ expect(scrollableContainer.scrollTop).to.be.closeTo(1000, 0.5);
340
+
341
+ // Wait a bit for `ScrollPositionRestoration` to save the scroll position
342
+ // because it does that "asynchronously", i.e. in an "immediate" timeout
343
+ // as a way of "throttling" scroll events.
344
+ await delay(20);
345
+
346
+ // Register the scrollable container on the "/new" page.
347
+ const untrackScrollableContainer = navigationStack.addScrollableContainer(
276
348
  'container',
277
349
  scrollableContainer,
278
350
  );
279
351
 
280
- // `PageScrollPositionSetter` works in an asynchronous fashion,
281
- // so this delay lets it finish setting page scroll position
282
- // before proceeding to next location.
283
- await delay(20);
352
+ // Go to "/new-2" page to check that it resets the scroll position inside the scrollable container.
353
+ navigationStack.push('/new-2');
354
+
355
+ // "/new-2" page rendered.
356
+ // Restore scroll position (no saved scroll position to restore).
357
+ await navigationStack.locationRendered();
284
358
 
285
- removeScrollableContainer();
359
+ // Check that it has reset the scroll position inside the scrollable container.
360
+ expect(scrollableContainer.scrollTop).to.equal(0);
286
361
 
362
+ // It should also reset page scroll position on any "push" navigation.
363
+ expect(window.pageYOffset).to.equal(0);
364
+
365
+ // Return to the "/new" page to check if it restores scroll position inside the scrollable container.
287
366
  navigationStack.shift(-1);
288
367
 
289
- navigationStack.locationRendered();
368
+ // Wait for the web browser to emit a "popstate" event from `window.history.go(-1)` navigation.
369
+ await delay(20);
370
+
371
+ // "/new" page rendered.
372
+ // Restore scroll position.
373
+ await navigationStack.locationRendered();
374
+
375
+ // Check that it has restored the scroll position inside the scrollable container.
376
+ expect(scrollableContainer.scrollTop).to.be.closeTo(1000, 0.5);
377
+
378
+ // Check that it has restored page scroll position.
379
+ expect(window.pageYOffset).to.be.closeTo(500, 0.5);
290
380
 
291
- // `PageScrollPositionSetter` works in an asynchronous fashion,
292
- // so this delay lets it finish setting page scroll position
293
- // before proceeding to next location.
381
+ // Return to the "/initial" page to check if it restores scroll position.
382
+ navigationStack.shift(-1);
383
+
384
+ // Wait for the web browser to emit a "popstate" event from `window.history.go(-1)` navigation.
294
385
  await delay(20);
386
+
387
+ // The scrollable container is only present at the "/new" or "/new-2" pages so remove it now.
388
+ document.body.removeChild(scrollableContainer);
389
+ // The scrollable container is only present at the "/new" or "/new-2" pages so untrack it now.
390
+ untrackScrollableContainer();
391
+
392
+ // "/initial" page rendered.
393
+ // Restore scroll position.
394
+ await navigationStack.locationRendered();
395
+
396
+ // Check that it has restored page scroll position.
397
+ expect(window.pageYOffset).to.be.closeTo(1000, 0.5);
295
398
  });
296
399
  });
@@ -133,7 +133,7 @@ describe('ScrollPositionRestoration', () => {
133
133
  it('should allow scroll suppression', (done) => {
134
134
  const app = addScrollableContainerWithAnchors(
135
135
  createApp({
136
- shouldUpdatePageScrollPositionForLocation: (
136
+ shouldSetPageScrollPositionOnLocationChange: (
137
137
  location,
138
138
  prevLocation,
139
139
  ) => {
@@ -208,7 +208,7 @@ describe('ScrollPositionRestoration', () => {
208
208
  it('should allow custom position', (done) => {
209
209
  const app = addScrollableContainerWithAnchors(
210
210
  createApp({
211
- getPageScrollPositionForLocation: () => [10, 20],
211
+ getSavedPageScrollPositionOnLocationChange: () => [10, 20],
212
212
  }),
213
213
  );
214
214
 
@@ -236,8 +236,8 @@ describe('ScrollPositionRestoration', () => {
236
236
  // If there were no scroll events, the scroll position doesn't get saved.
237
237
  // The rationale is that when there were no scroll events, the scroll position
238
238
  // is gonna be either a default one or a custom one specified by passing a custom
239
- // `getPageScrollPositionForLocation()` function. In the latter case, the custom
240
- // `getPageScrollPositionForLocation()` function is responsible to return a correct scroll position
239
+ // `getSavedPageScrollPositionOnLocationChange()` function. In the latter case, the custom
240
+ // `getSavedPageScrollPositionOnLocationChange()` function is responsible to return a correct scroll position
241
241
  // every time it gets called rather than just return a correct scroll position once,
242
242
  // save it immediately and then restore it when returning to the page.
243
243
  //
@@ -247,7 +247,7 @@ describe('ScrollPositionRestoration', () => {
247
247
  // const app = addScrollableContainerWithAnchors(
248
248
  // createApp({
249
249
  // // eslint-disable-next-line no-unused-vars
250
- // getPageScrollPositionForLocation(location, prevLocation) {
250
+ // getSavedPageScrollPositionOnLocationChange(location, prevLocation) {
251
251
  // // Only when navigated via `.goTo()`. Ignore `.goBack()` navigation.
252
252
  // if (prevLocation && location.index > prevLocation.index) {
253
253
  // return [10, 20];
@@ -290,7 +290,7 @@ describe('ScrollPositionRestoration', () => {
290
290
  it('should follow browser scroll behavior', (done) => {
291
291
  const { container, ...app } = addScrollableContainer(
292
292
  createApp({
293
- shouldUpdatePageScrollPositionForLocation: () => false,
293
+ shouldSetPageScrollPositionOnLocationChange: () => false,
294
294
  }),
295
295
  );
296
296
 
@@ -325,7 +325,7 @@ describe('ScrollPositionRestoration', () => {
325
325
  const { container, ...app } =
326
326
  withScrollableContainerAtIndexPageWithDisabledAutomaticScrollPositionRestoration(
327
327
  createApp({
328
- shouldUpdatePageScrollPositionForLocation: () => false,
328
+ shouldSetPageScrollPositionOnLocationChange: () => false,
329
329
  }),
330
330
  );
331
331
 
@@ -359,7 +359,7 @@ describe('ScrollPositionRestoration', () => {
359
359
  it('should save element scroll position on scroll event, i.e. before navigation is even attempted', (done) => {
360
360
  const app1 = addScrollableContainer(
361
361
  createApp({
362
- shouldUpdatePageScrollPositionForLocation: () => false,
362
+ shouldSetPageScrollPositionOnLocationChange: () => false,
363
363
  }),
364
364
  );
365
365
 
@@ -375,7 +375,7 @@ describe('ScrollPositionRestoration', () => {
375
375
  createApp({
376
376
  // Restore the data of the session of `app1`.
377
377
  sessionKey: app1.getSessionKey(),
378
- shouldUpdatePageScrollPositionForLocation: () => false,
378
+ shouldSetPageScrollPositionOnLocationChange: () => false,
379
379
  }),
380
380
  );
381
381
 
@@ -5,8 +5,8 @@ import WebBrowserSession from '../../src/session/WebBrowserSession';
5
5
  // Creates a website with `ScrollPositionRestoration`.
6
6
  export default function createApp({
7
7
  sessionKey,
8
- shouldUpdatePageScrollPositionForLocation,
9
- getPageScrollPositionForLocation,
8
+ shouldSetPageScrollPositionOnLocationChange,
9
+ getSavedPageScrollPositionOnLocationChange,
10
10
  } = {}) {
11
11
  let currentLocation = null;
12
12
 
@@ -65,9 +65,10 @@ export default function createApp({
65
65
  }
66
66
  navigationStack = new NavigationStack(session);
67
67
  scrollPositionRestoration = new ScrollPositionRestoration(session, {
68
- _shouldUpdatePageScrollPositionForLocation:
69
- shouldUpdatePageScrollPositionForLocation,
70
- _getPageScrollPositionForLocation: getPageScrollPositionForLocation,
68
+ _shouldSetPageScrollPositionOnLocationChange:
69
+ shouldSetPageScrollPositionOnLocationChange,
70
+ _getSavedPageScrollPositionOnLocationChange:
71
+ getSavedPageScrollPositionOnLocationChange,
71
72
  });
72
73
 
73
74
  unlisten = navigationStack.subscribe(onLocationDidChange);
@@ -92,10 +93,10 @@ export default function createApp({
92
93
  // Registers a scrollable container on a page.
93
94
  function registerScrollableContainer(key, element, options) {
94
95
  return scrollPositionRestoration.addScrollableContainer(key, element, {
95
- _shouldUpdateScrollPositionForLocation:
96
- options && options.shouldUpdateScrollPositionForLocation,
97
- _getScrollPositionForLocation:
98
- options && options.getScrollPositionForLocation,
96
+ _shouldSetScrollPositionOnLocationChange:
97
+ options && options.shouldSetScrollPositionOnLocationChange,
98
+ _getSavedScrollPositionOnLocationChange:
99
+ options && options.getSavedScrollPositionOnLocationChange,
99
100
  });
100
101
  }
101
102
 
@@ -37,7 +37,7 @@ export default function withScrollableContainerAtIndexPageWithDisabledAutomaticS
37
37
  'container',
38
38
  container,
39
39
  {
40
- shouldUpdateScrollPositionForLocation:
40
+ shouldSetScrollPositionOnLocationChange:
41
41
  shouldUpdateScrollableContainerScrollPositionForLocation,
42
42
  },
43
43
  );
@@ -15,18 +15,18 @@ export class ScrollPositionRestoration<
15
15
 
16
16
  // `_options` are currently only used in tests.
17
17
  _options?: {
18
- // `_options._shouldUpdatePageScrollPositionForLocation`
18
+ // `_options._shouldSetPageScrollPositionOnLocationChange`
19
19
  // isn't used in real life and is not part of the public API.
20
20
  // It's only used in tests.
21
- _shouldUpdatePageScrollPositionForLocation?: (
21
+ _shouldSetPageScrollPositionOnLocationChange?: (
22
22
  location: Location,
23
23
  prevLocation: Location | undefined,
24
24
  ) => boolean;
25
25
 
26
- // `_options._getPageScrollPositionForLocation`
26
+ // `_options._getSavedPageScrollPositionOnLocationChange`
27
27
  // isn't used in real life and is not part of the public API.
28
28
  // It's only used in tests.
29
- _getPageScrollPositionForLocation?: (
29
+ _getSavedPageScrollPositionOnLocationChange?: (
30
30
  location: Location,
31
31
  prevLocation: Location | undefined,
32
32
  ) => [number, number] | undefined;
@@ -34,7 +34,7 @@ export class ScrollPositionRestoration<
34
34
  // Using this option, a developer could theoretically provide their own implementation
35
35
  // of setting a scroll position. For example, it could use "smooth" (animated) scrolling, etc.
36
36
  // This could be part of the public API if anyone provided a sensible real-world use case for it.
37
- _pageScrollPositionSetter: ScrollPositionSetter<
37
+ _pageScrollPositionSetter?: ScrollPositionSetter<
38
38
  ScrollableContainer,
39
39
  Anchor
40
40
  >;
@@ -47,18 +47,18 @@ export class ScrollPositionRestoration<
47
47
 
48
48
  // `_options` are currently only used in tests.
49
49
  _options?: {
50
- // `_options._shouldUpdateScrollPositionForLocation`
50
+ // `_options._shouldSetScrollPositionOnLocationChange`
51
51
  // isn't used in real life and is not part of the public API.
52
52
  // It's only used in tests.
53
- _shouldUpdateScrollPositionForLocation?: (
53
+ _shouldSetScrollPositionOnLocationChange?: (
54
54
  location: Location,
55
55
  prevLocation: Location | undefined,
56
56
  ) => boolean;
57
57
 
58
- // `_options._getScrollPositionForLocation`
58
+ // `_options._getSavedScrollPositionOnLocationChange`
59
59
  // isn't used in real life and is not part of the public API.
60
60
  // It's only used in tests.
61
- _getScrollPositionForLocation?: (
61
+ _getSavedScrollPositionOnLocationChange?: (
62
62
  location: Location,
63
63
  prevLocation: Location | undefined,
64
64
  ) => [number, number] | undefined;