Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions js/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@ export function createDirections({ key, consent = () => false, maps = loadMaps,
const ready = () => (consent() && globalThis.navigator?.onLine !== false ? maps(key, doc) : Promise.reject(new Error('unavailable')));

return {
// Bumped by the caller whenever the origin or the date moves. A response
// that comes back against an old generation is dropped rather than
// rendered, which is the rule docs/research/walking-routes-115.md sets: a
// stale answer must never reorder or relabel a list already on screen.
get generation() {
return generation;
},
// Bumped by the caller whenever the origin or the date moves, and handed
// back so the caller can tell generations apart without this object
// keeping a second, readable copy of the count. A response that comes
// back against an old generation is dropped rather than rendered, which
// is the rule docs/research/walking-routes-115.md sets: a stale answer
// must never reorder or relabel a list already on screen.
invalidate() {
generation += 1;
return generation;
Expand Down
2 changes: 0 additions & 2 deletions scripts/test/directions.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ test('an answer against an old generation is dropped', async () => {
test('invalidate counts up so a caller can tell generations apart', () => {
const { maps } = fakeMaps({ leg: LEG });
const d = createDirections({ key: 'k', consent: yes, maps });
assert.equal(d.generation, 0);
assert.equal(d.invalidate(), 1);
assert.equal(d.invalidate(), 2);
assert.equal(d.generation, 2);
});

// --- the matrix, all or nothing
Expand Down
Loading