diff --git a/api/js-sdk-react.api.d.ts b/api/js-sdk-react.api.d.ts index 4fba31f..3da0db8 100644 --- a/api/js-sdk-react.api.d.ts +++ b/api/js-sdk-react.api.d.ts @@ -12,19 +12,26 @@ export { I as InfoBubbleEntry, M as MarkerAnimationStore } from './MarkerAnimati * shows nothing until they are drawn, and these say that work is going on. * * "On the map" is what each state's `onAdded` means: drawn natively, or, for a - * state drawn in tiles, its tiles handed to the map (their images may still be - * loading). + * state drawn in tiles, its tiles handed to the map. The work does not end + * there for tiles, so the collection also counts as busy while its tiles are + * being drawn ({@link AddProgressTracker.drawingChanged}): after a filter + * change, and while the camera moves to where tiles are not drawn yet. * - * - `onAddStart(total)`: a list brought states that are not on the map yet; - * `total` is how many. + * - `onAddStart(total)`: a list was handed over, or tiles have been drawn for + * {@link DRAW_START_DELAY_MS} without one; `total` is how many states the + * list brought that are not on the map yet (0 when it only removed or + * updated states, or for tiles alone). An empty list after an empty one + * calls nothing. * - `onAddProgress(added, total)`: how many of them are on the map so far, at - * most every 100 ms, and once more with `added === total` before the end. - * - `onAddEnd(total)`: all of them are on the map. A state taken out of the - * list before it got there no longer counts against the end. + * most every 100 ms, and once more with `added === total` before the end + * when `total` is not 0. + * - `onAddEnd(total)`: all of them are on the map and nothing has been drawn + * for {@link SETTLE_MS}. A state taken out of the list before it got there + * no longer counts against the end. * * A list that brings new states while an earlier one is still being added * starts over: a new `onAddStart` with only the new states, and no `onAddEnd` - * for the earlier list. A list that only updates or removes states calls nothing. + * for the earlier list. */ interface AddProgressCallbacks { onAddStart?: (total: number) => void; diff --git a/src/AddProgress.ts b/src/AddProgress.ts index e0c40ae..73c6a03 100644 --- a/src/AddProgress.ts +++ b/src/AddProgress.ts @@ -1,5 +1,5 @@ import { useCallback, useEffect, useRef, useState } from 'react'; -import { subscribeOverlaysAdded } from '@mapconductor/js-sdk-core'; +import { subscribeOverlaysAdded, type TileActivity } from '@mapconductor/js-sdk-core'; /** * How far a collection (``, ``, ``, ``) @@ -7,19 +7,26 @@ import { subscribeOverlaysAdded } from '@mapconductor/js-sdk-core'; * shows nothing until they are drawn, and these say that work is going on. * * "On the map" is what each state's `onAdded` means: drawn natively, or, for a - * state drawn in tiles, its tiles handed to the map (their images may still be - * loading). + * state drawn in tiles, its tiles handed to the map. The work does not end + * there for tiles, so the collection also counts as busy while its tiles are + * being drawn ({@link AddProgressTracker.drawingChanged}): after a filter + * change, and while the camera moves to where tiles are not drawn yet. * - * - `onAddStart(total)`: a list brought states that are not on the map yet; - * `total` is how many. + * - `onAddStart(total)`: a list was handed over, or tiles have been drawn for + * {@link DRAW_START_DELAY_MS} without one; `total` is how many states the + * list brought that are not on the map yet (0 when it only removed or + * updated states, or for tiles alone). An empty list after an empty one + * calls nothing. * - `onAddProgress(added, total)`: how many of them are on the map so far, at - * most every 100 ms, and once more with `added === total` before the end. - * - `onAddEnd(total)`: all of them are on the map. A state taken out of the - * list before it got there no longer counts against the end. + * most every 100 ms, and once more with `added === total` before the end + * when `total` is not 0. + * - `onAddEnd(total)`: all of them are on the map and nothing has been drawn + * for {@link SETTLE_MS}. A state taken out of the list before it got there + * no longer counts against the end. * * A list that brings new states while an earlier one is still being added * starts over: a new `onAddStart` with only the new states, and no `onAddEnd` - * for the earlier list. A list that only updates or removes states calls nothing. + * for the earlier list. */ export interface AddProgressCallbacks { onAddStart?: (total: number) => void; @@ -28,6 +35,21 @@ export interface AddProgressCallbacks { } const PROGRESS_INTERVAL_MS = 100; +/** Drawing alone counts as work only once it has lasted this long: a camera move over cached tiles does not. */ +export const DRAW_START_DELAY_MS = 200; +/** Quiet this long -- nothing handed over, arriving or drawn -- before onAddEnd. */ +export const SETTLE_MS = 400; + +/** How the tracker waits; injectable so that tests can drive time. */ +export interface AddProgressTimers { + set(callback: () => void, ms: number): unknown; + clear(handle: unknown): void; +} + +const realTimers: AddProgressTimers = { + set: (callback, ms) => setTimeout(callback, ms), + clear: (handle) => clearTimeout(handle as ReturnType), +}; /** * The states one collection handed over and how many of them are on the map. @@ -39,18 +61,41 @@ export class AddProgressTracker { private total = 0; private added = 0; private lastProgressAt = 0; - private timer: ReturnType | null = null; + private timer: unknown = null; + + /** Between an onAddStart and its onAddEnd. */ + private started = false; + /** The last list had states: an empty list after an empty one hands nothing over. */ + private hadStates = false; + /** The collection's tiles are being drawn (or its tiler is taking a list). */ + private drawing = false; + /** When the last reason to be busy ended: a hand-over, the last arrival, drawing stopping. */ + private quietSince = -Infinity; + private settle: unknown = null; + private drawStart: unknown = null; private readonly callbacks: () => AddProgressCallbacks; private readonly now: () => number; + private readonly timers: AddProgressTimers; - constructor(callbacks: () => AddProgressCallbacks, now: () => number = () => performance.now()) { + constructor( + callbacks: () => AddProgressCallbacks, + now: () => number = () => performance.now(), + timers: AddProgressTimers = realTimers, + ) { this.callbacks = callbacks; this.now = now; + this.timers = timers; } - /** A list was handed to the collector: the states it added and the ids it removed. */ - track(added: readonly { id: string }[], removedIds: readonly string[]): void { + /** + * A list of `size` states was handed to the collector: the states it added + * and the ids it removed. + */ + track(added: readonly { id: string }[], removedIds: readonly string[], size: number): void { + const hadStates = this.hadStates; + this.hadStates = size > 0; + if (size === 0 && !hadStates) return; if (this.pending.size > 0 && removedIds.length > 0) { const removed = new Set(removedIds); for (const [state, id] of this.pending) { @@ -59,15 +104,21 @@ export class AddProgressTracker { this.total--; } } - if (added.length === 0) this.finishIfDone(); } - if (added.length === 0) return; - this.cancelTimer(); - this.pending = new Map(added.map(state => [state as object, state.id])); - this.total = added.length; - this.added = 0; - this.lastProgressAt = 0; - this.callbacks().onAddStart?.(this.total); + this.quietSince = this.now(); + if (added.length > 0) { + this.cancelTimer(); + this.pending = new Map(added.map(state => [state as object, state.id])); + this.total = added.length; + this.added = 0; + this.lastProgressAt = 0; + this.begin(this.total); + } else if (!this.started) { + this.total = 0; + this.added = 0; + this.begin(0); + } + this.scheduleSettle(); } /** States reached the map (any collection's: the others are not ours). */ @@ -81,27 +132,79 @@ export class AddProgressTracker { } } if (!hit) return; - if (this.pending.size === 0) this.finishIfDone(); - else this.reportProgress(); + if (this.pending.size === 0) { + this.quietSince = this.now(); + this.scheduleSettle(); + } else { + this.reportProgress(); + } + } + + /** Whether the collection's tiles are being drawn now. */ + drawingChanged(drawing: boolean): void { + if (drawing === this.drawing) return; + this.drawing = drawing; + if (drawing) { + this.clear('settle'); + if (!this.started && this.drawStart == null) { + this.drawStart = this.timers.set(() => { + this.drawStart = null; + if (this.drawing && !this.started) { + this.total = 0; + this.added = 0; + this.begin(0); + } + }, DRAW_START_DELAY_MS); + } + } else { + this.clear('drawStart'); + this.quietSince = this.now(); + this.scheduleSettle(); + } } dispose(): void { this.cancelTimer(); + this.clear('settle'); + this.clear('drawStart'); this.pending.clear(); } - private finishIfDone(): void { - if (this.pending.size > 0) return; + private begin(total: number): void { + this.started = true; + this.clear('drawStart'); + this.callbacks().onAddStart?.(total); + } + + private scheduleSettle(): void { + if (!this.started) return; + this.clear('settle'); + this.settle = this.timers.set(() => { + this.settle = null; + this.finishIfIdle(); + }, SETTLE_MS); + } + + private finishIfIdle(): void { + if (!this.started || this.drawing || this.pending.size > 0) return; + if (this.quietSince + SETTLE_MS - this.now() > 0) { + this.scheduleSettle(); + return; + } this.cancelTimer(); - this.callbacks().onAddProgress?.(this.total, this.total); - this.callbacks().onAddEnd?.(this.total); + this.started = false; + const count = this.total; + this.total = 0; + this.added = 0; + if (count > 0) this.callbacks().onAddProgress?.(count, count); + this.callbacks().onAddEnd?.(count); } private reportProgress(): void { if (this.timer != null) return; const wait = this.lastProgressAt + PROGRESS_INTERVAL_MS - this.now(); if (wait <= 0) this.emitProgress(); - else this.timer = setTimeout(() => this.emitProgress(), wait); + else this.timer = this.timers.set(() => this.emitProgress(), wait); } private emitProgress(): void { @@ -112,17 +215,25 @@ export class AddProgressTracker { } private cancelTimer(): void { - if (this.timer != null) clearTimeout(this.timer); + if (this.timer != null) this.timers.clear(this.timer); this.timer = null; } + + private clear(which: 'settle' | 'drawStart'): void { + const handle = this[which]; + if (handle != null) this.timers.clear(handle); + this[which] = null; + } } /** * Tracks the states one collection hands over. Call the returned function from - * the effect that hands a list to the collector, with the states it added and - * the ids it removed. + * the effect that hands a list to the collector, with the states it added, the + * ids it removed and how many states the collection now has. With `activity` + * (see `useOverlayTileActivity`), it also follows the map's tiler for this + * kind of overlay: busy while it draws tiles. */ -export function useAddProgress({ onAddStart, onAddProgress, onAddEnd }: AddProgressCallbacks) { +export function useAddProgress({ onAddStart, onAddProgress, onAddEnd }: AddProgressCallbacks, activity?: TileActivity | null) { const callbacks = useRef({}); callbacks.current = { onAddStart, onAddProgress, onAddEnd }; const wanted = onAddStart != null || onAddProgress != null || onAddEnd != null; @@ -133,11 +244,21 @@ export function useAddProgress({ onAddStart, onAddProgress, onAddEnd }: AddProgr return subscribeOverlaysAdded(states => tracker.arrived(states)); }, [wanted, tracker]); + useEffect(() => { + if (!wanted || !activity) return; + tracker.drawingChanged(activity.active); + const unsubscribe = activity.subscribe(busy => tracker.drawingChanged(busy)); + return () => { + unsubscribe(); + tracker.drawingChanged(false); + }; + }, [wanted, activity, tracker]); + useEffect(() => () => tracker.dispose(), [tracker]); return useCallback( - (added: readonly { id: string }[], removedIds: readonly string[]) => { - if (wanted) tracker.track(added, removedIds); + (added: readonly { id: string }[], removedIds: readonly string[], size: number) => { + if (wanted) tracker.track(added, removedIds, size); }, [wanted, tracker], ); diff --git a/src/Circle.tsx b/src/Circle.tsx index 351c0a2..f1153b3 100644 --- a/src/Circle.tsx +++ b/src/Circle.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useMemo, useRef } from 'react'; import { useMapViewScope } from './MapViewScope'; import { OwnedOverlays } from './OwnedOverlays'; import { useAddProgress, type AddProgressCallbacks } from './AddProgress'; +import { useOverlayTileActivity } from './OverlayTileActivity'; import { createCircleState, type CircleState, @@ -50,11 +51,11 @@ export function Circles({ states, onAddStart, onAddProgress, onAddEnd }: Circles const { circleCollector } = useMapViewScope(); const owned = useMemo(() => new OwnedOverlays(circleCollector, syncCircleState), [circleCollector]); - const trackAdd = useAddProgress({ onAddStart, onAddProgress, onAddEnd }); + const trackAdd = useAddProgress({ onAddStart, onAddProgress, onAddEnd }, useOverlayTileActivity('circle')); useEffect(() => { const { added, removedIds } = owned.set(states); - trackAdd(added, removedIds); + trackAdd(added, removedIds, owned.size); }, [states, owned, trackAdd]); useEffect(() => () => owned.clear(), [owned]); diff --git a/src/Marker.tsx b/src/Marker.tsx index 454f5e9..71025f1 100644 --- a/src/Marker.tsx +++ b/src/Marker.tsx @@ -74,7 +74,7 @@ export function Markers({ states, onAddStart, onAddProgress, onAddEnd }: Markers if (added.length > 0 || removedIds.length > 0) { markerCollector.applyDiff(added, removedIds); } - trackAdd(added, removedIds); + trackAdd(added, removedIds, stableStatesRef.current.size); }); }, [states, markerCollector, trackAdd]); diff --git a/src/OverlayTileActivity.ts b/src/OverlayTileActivity.ts new file mode 100644 index 0000000..f0f5ab3 --- /dev/null +++ b/src/OverlayTileActivity.ts @@ -0,0 +1,17 @@ +import { useContext } from 'react'; +import type { OverlayKind, TileActivity } from '@mapconductor/js-sdk-core'; +import { MapContext, mapContextInternal } from './MapContext'; + +/** + * Whether the map's tiler of `kind` is busy -- taking a list or drawing tiles -- + * for a collection's onAddStart / onAddEnd ({@link useAddProgress}). Null + * outside a map, before its controller exists, or for a kind without tiles. + * + * @internal + */ +export function useOverlayTileActivity(kind: OverlayKind): TileActivity | null { + const context = useContext(MapContext); + const controller = context ? mapContextInternal(context).controller : null; + return (controller as { overlayTileActivity?(kind: OverlayKind): TileActivity | null } | null) + ?.overlayTileActivity?.(kind) ?? null; +} diff --git a/src/Polygon.tsx b/src/Polygon.tsx index cab60b2..ac677de 100644 --- a/src/Polygon.tsx +++ b/src/Polygon.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useRef } from 'react'; import { useMapViewScope } from './MapViewScope'; import { useAddProgress, type AddProgressCallbacks } from './AddProgress'; +import { useOverlayTileActivity } from './OverlayTileActivity'; import { createPolygonState, type PolygonState, @@ -45,7 +46,7 @@ interface PolygonsProps extends AddProgressCallbacks { */ export function Polygons({ states, onAddStart, onAddProgress, onAddEnd }: PolygonsProps): null { const { polygonCollector } = useMapViewScope(); - const trackAdd = useAddProgress({ onAddStart, onAddProgress, onAddEnd }); + const trackAdd = useAddProgress({ onAddStart, onAddProgress, onAddEnd }, useOverlayTileActivity('polygon')); const stableStatesRef = useRef>(new Map()); useEffect(() => { @@ -75,7 +76,7 @@ export function Polygons({ states, onAddStart, onAddProgress, onAddEnd }: Polygo if (added.length > 0 || removedIds.length > 0) { polygonCollector.applyDiff(added, removedIds); } - trackAdd(added, removedIds); + trackAdd(added, removedIds, stableStatesRef.current.size); }); }, [states, polygonCollector, trackAdd]); diff --git a/src/Polyline.tsx b/src/Polyline.tsx index 700f23b..4018a85 100644 --- a/src/Polyline.tsx +++ b/src/Polyline.tsx @@ -2,6 +2,7 @@ import React, { useEffect, useMemo } from 'react'; import { useMapViewScope } from './MapViewScope'; import { OwnedOverlays } from './OwnedOverlays'; import { useAddProgress, type AddProgressCallbacks } from './AddProgress'; +import { useOverlayTileActivity } from './OverlayTileActivity'; import { createPolylineState, type PolylineState, @@ -51,11 +52,11 @@ export function Polylines({ states, onAddStart, onAddProgress, onAddEnd }: Polyl const { polylineCollector } = useMapViewScope(); const owned = useMemo(() => new OwnedOverlays(polylineCollector, syncPolylineState), [polylineCollector]); - const trackAdd = useAddProgress({ onAddStart, onAddProgress, onAddEnd }); + const trackAdd = useAddProgress({ onAddStart, onAddProgress, onAddEnd }, useOverlayTileActivity('polyline')); useEffect(() => { const { added, removedIds } = owned.set(states); - trackAdd(added, removedIds); + trackAdd(added, removedIds, owned.size); }, [states, owned, trackAdd]); useEffect(() => () => owned.clear(), [owned]); diff --git a/test/addProgress.test.mjs b/test/addProgress.test.mjs index adde213..74b13b6 100644 --- a/test/addProgress.test.mjs +++ b/test/addProgress.test.mjs @@ -2,18 +2,20 @@ import assert from 'node:assert/strict'; import { test } from 'node:test'; import { createCircleState, createGeoPoint, notifyOverlaysAdded, OverlayCollector, subscribeOverlaysAdded } from '@mapconductor/js-sdk-core'; -import { AddProgressTracker } from '../src/AddProgress.ts'; +import { AddProgressTracker, DRAW_START_DELAY_MS, SETTLE_MS } from '../src/AddProgress.ts'; import { OwnedOverlays } from '../src/OwnedOverlays.ts'; /** * `` / `` / `` / `` の onAddStart / onAddProgress / onAddEnd - * (src/AddProgress.ts)。 + * (src/AddProgress.ts)。android-sdk-compose の `AddProgressTrackerTest`、ios-sdk の + * `AddProgressTests` と同じ内容。 * - * - 地図に未だ無い state を持ち込んだリストで onAddStart(total)。 + * - リストを渡したら onAddStart(total)。total は地図に未だ無い state の数(削除・更新だけなら 0、空のあとの空は何も呼ばない)。 * - 各 state の onAdded と同じ時点で 1 つ数える。途中経過は 100 ms に 1 回まで。 - * - 全部載ったら onAddProgress(total, total) と onAddEnd(total)。 + * - 全部載り、タイルの描画も止まって 400 ms 静かになったら onAddProgress(total, total) と onAddEnd(total)。 + * - タイルの描画だけ(カメラの移動)は 200 ms 続いたら onAddStart(0)。それより短ければ何も呼ばない。 * - 載る前に外された state は数から抜ける。新しい追加は数え直し、前のリストの onAddEnd は来ない。 - * - 更新・削除だけのリストは何も呼ばない。他のコレクションの state は数えない。 + * - 他のコレクションの state は数えない。 */ const p = (latitude, longitude) => createGeoPoint({ latitude, longitude }); @@ -22,6 +24,15 @@ const circle = (id) => createCircleState({ id, center: p(42.35, -71.06), radiusM function setUp() { const calls = []; let clock = 1000; + let due = []; + const timers = { + set: (callback, ms) => { + const handle = { at: clock + ms, callback }; + due.push(handle); + return handle; + }, + clear: (handle) => { due = due.filter((h) => h !== handle); }, + }; const tracker = new AddProgressTracker( () => ({ onAddStart: (total) => calls.push(['start', total]), @@ -29,79 +40,142 @@ function setUp() { onAddEnd: (total) => calls.push(['end', total]), }), () => clock, + timers, ); const owned = new OwnedOverlays(new OverlayCollector(), () => {}); const set = (states) => { const { added, removedIds } = owned.set(states); - tracker.track(added, removedIds); + tracker.track(added, removedIds, owned.size); + }; + /** Moves the clock, running each timer that comes due on the way. */ + const advance = (ms) => { + const until = clock + ms; + for (;;) { + const next = due.filter((h) => h.at <= until).sort((a, b) => a.at - b.at)[0]; + if (!next) break; + due = due.filter((h) => h !== next); + clock = next.at; + next.callback(); + } + clock = until; }; - return { calls, tracker, set, advance: (ms) => (clock += ms) }; + return { calls, tracker, set, advance, settle: () => advance(SETTLE_MS) }; } -test('全部載ったら start → progress(total) → end', () => { - const { calls, tracker, set } = setUp(); +test('全部載り、静かになったら start → progress(total) → end', () => { + const { calls, tracker, set, settle } = setUp(); const states = [circle('a'), circle('b'), circle('c')]; set(states); assert.deepEqual(calls, [['start', 3]]); tracker.arrived([states[0]]); tracker.arrived([states[1], states[2]]); + assert.deepEqual(calls, [['start', 3], ['progress', 1, 3]]); + settle(); assert.deepEqual(calls, [['start', 3], ['progress', 1, 3], ['progress', 3, 3], ['end', 3]]); }); -test('途中経過は 100 ms に 1 回まで', async () => { - const { calls, tracker, set, advance } = setUp(); +test('途中経過は 100 ms に 1 回まで', () => { + const { calls, tracker, set, advance, settle } = setUp(); const states = Array.from({ length: 5 }, (_, i) => circle(`s${i}`)); set(states); - advance(1000); tracker.arrived([states[0]]); // emits now tracker.arrived([states[1]]); // throttled tracker.arrived([states[2]]); // throttled assert.deepEqual(calls.slice(1), [['progress', 1, 5]]); advance(100); - await new Promise((r) => setTimeout(r, 120)); assert.deepEqual(calls.slice(1), [['progress', 1, 5], ['progress', 3, 5]]); tracker.arrived([states[3], states[4]]); + settle(); assert.deepEqual(calls.at(-1), ['end', 5]); }); test('載る前に外された state は数から抜け、残りが載れば終わる', () => { - const { calls, tracker, set } = setUp(); + const { calls, tracker, set, settle } = setUp(); const [a, b, c] = [circle('a'), circle('b'), circle('c')]; set([a, b, c]); tracker.arrived([a]); set([a, b]); // c removed before it arrived tracker.arrived([b]); + settle(); assert.deepEqual(calls.slice(-2), [['progress', 2, 2], ['end', 2]]); }); -test('残りを全部外せば、その場で終わる', () => { - const { calls, tracker, set } = setUp(); +test('残りを全部外せば、静かになったところで終わる', () => { + const { calls, tracker, set, settle } = setUp(); const [a, b] = [circle('a'), circle('b')]; set([a, b]); tracker.arrived([a]); set([a]); + settle(); assert.deepEqual(calls.slice(-2), [['progress', 1, 1], ['end', 1]]); }); test('追加の途中で新しい追加が来たら数え直し、前のリストの end は来ない', () => { - const { calls, tracker, set } = setUp(); + const { calls, tracker, set, settle } = setUp(); const [a, b, c] = [circle('a'), circle('b'), circle('c')]; set([a, b]); set([a, b, c]); // only c is new assert.deepEqual(calls, [['start', 2], ['start', 1]]); tracker.arrived([a, b]); // from the earlier list: no longer counted tracker.arrived([c]); + settle(); assert.deepEqual(calls.slice(2), [['progress', 1, 1], ['end', 1]]); }); -test('更新・削除だけのリストと、他のコレクションの state では何も呼ばない', () => { - const { calls, tracker, set } = setUp(); +test('更新・削除だけのリストは 0 で始まり 0 で終わり、他のコレクションの state は数えない', () => { + const { calls, tracker, set, settle } = setUp(); const [a, b] = [circle('a'), circle('b')]; set([a, b]); tracker.arrived([a, b]); + settle(); calls.length = 0; set([circle('a')]); // a updated in place, b removed tracker.arrived([circle('other')]); + assert.deepEqual(calls, [['start', 0]]); + settle(); + assert.deepEqual(calls, [['start', 0], ['end', 0]]); +}); + +test('空のあとの空のリストでは何も呼ばない', () => { + const { calls, set, settle } = setUp(); + set([]); + settle(); + assert.deepEqual(calls, []); +}); + +test('タイルを描いている間は end を待ち、止んで静かになったら終わる', () => { + const { calls, tracker, set, advance } = setUp(); + const a = circle('a'); + set([a]); + tracker.arrived([a]); + tracker.drawingChanged(true); + advance(2000); + assert.deepEqual(calls, [['start', 1]]); + tracker.drawingChanged(false); + advance(SETTLE_MS - 1); + assert.deepEqual(calls, [['start', 1]]); + advance(1); + assert.deepEqual(calls, [['start', 1], ['progress', 1, 1], ['end', 1]]); +}); + +test('描画だけなら 200 ms 続いたところで 0 で始まり、静かになったら終わる', () => { + const { calls, tracker, advance, settle } = setUp(); + tracker.drawingChanged(true); + advance(DRAW_START_DELAY_MS - 1); + assert.deepEqual(calls, []); + advance(1); + assert.deepEqual(calls, [['start', 0]]); + tracker.drawingChanged(false); + settle(); + assert.deepEqual(calls, [['start', 0], ['end', 0]]); +}); + +test('短い描画では何も呼ばない', () => { + const { calls, tracker, advance } = setUp(); + tracker.drawingChanged(true); + advance(DRAW_START_DELAY_MS / 2); + tracker.drawingChanged(false); + advance(2000); assert.deepEqual(calls, []); });