• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visgl / luma.gl / 26365832078

24 May 2026 03:53PM UTC coverage: 74.573% (+0.06%) from 74.51%
26365832078

push

github

web-flow
chore: Simplify arrow examples (#2636)

8463 of 12834 branches covered (65.94%)

Branch coverage included in aggregate %.

281 of 357 new or added lines in 3 files covered. (78.71%)

733 existing lines in 26 files now uncovered.

17709 of 22262 relevant lines covered (79.55%)

4350.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.17
/modules/engine/src/animation-loop/make-animation-loop.ts
1
// luma.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4

5
import {luma, Adapter, Device} from '@luma.gl/core';
6
import {AnimationLoopTemplate} from './animation-loop-template';
7
import {AnimationLoop, AnimationLoopProps} from './animation-loop';
8
import type {AnimationProps} from './animation-props';
9

10
/** Props accepted while constructing an animation loop from a template. */
11
export type MakeAnimationLoopProps = Omit<
12
  AnimationLoopProps,
13
  'onCreateDevice' | 'onInitialize' | 'onRedraw' | 'onFinalize'
14
> & {
15
  /** List of adapters to use when creating the device */
16
  adapters?: Adapter[];
17
};
18

19
/**
20
 * Instantiates an animation loop and initializes it with the template.
21
 * @note The application needs to call `start()` on the returned animation loop to start the rendering loop.
22
 */
23
export function makeAnimationLoop(
24
  AnimationLoopTemplateCtor: typeof AnimationLoopTemplate,
25
  props?: MakeAnimationLoopProps
26
): AnimationLoop {
27
  let renderLoop: AnimationLoopTemplate | null = null;
1✔
28

29
  const device =
30
    props?.device ||
1!
31
    luma.createDevice({id: 'animation-loop', adapters: props?.adapters, createCanvasContext: true});
32

33
  // Create an animation loop;
34
  const animationLoop = new AnimationLoop({
1✔
35
    ...props,
36

37
    device,
38

39
    async onInitialize(animationProps: AnimationProps): Promise<unknown> {
40
      clearError(animationProps.animationLoop.device);
1✔
41
      try {
1✔
42
        // @ts-expect-error abstract to prevent instantiation
43
        renderLoop = new AnimationLoopTemplateCtor(animationProps);
1✔
44
        // Any async loading can be handled here
45
        return await renderLoop?.onInitialize(animationProps);
1✔
46
      } catch (error) {
47
        // biome-ignore lint/suspicious/noConsole: fallback logging before rendering the in-canvas error banner.
48
        console.error(error);
1✔
49
        renderLoop = null;
1✔
50
        setError(animationProps.animationLoop.device, error as Error);
1✔
51
        animationProps.animationLoop.stop();
1✔
52
        return null;
1✔
53
      }
54
    },
55

UNCOV
56
    onRender: (animationProps: AnimationProps) => renderLoop?.onRender(animationProps),
×
57

58
    onFinalize: (animationProps: AnimationProps) => renderLoop?.onFinalize(animationProps)
1✔
59
  });
60

61
  // @ts-expect-error Hack: adds info for the website to find
62
  animationLoop.getInfo = () => {
1✔
63
    // @ts-ignore
64
    // eslint-disable-next-line no-invalid-this
65
    return this.AnimationLoopTemplateCtor.info;
×
66
  };
67

68
  return animationLoop;
1✔
69
}
70

71
function setError(device: Device | null, error: Error): void {
72
  if (!device) {
1!
73
    return;
×
74
  }
75

76
  const canvas = device.getDefaultCanvasContext().canvas;
1✔
77
  if (canvas instanceof HTMLCanvasElement) {
1!
78
    canvas.style.overflow = 'visible';
1✔
79
    let errorDiv = document.getElementById('animation-loop-error');
1✔
80
    errorDiv?.remove();
1✔
81
    errorDiv = document.createElement('h1');
1✔
82
    errorDiv.id = 'animation-loop-error';
1✔
83
    errorDiv.innerHTML = error.message;
1✔
84
    errorDiv.style.position = 'absolute';
1✔
85
    errorDiv.style.top = '10px'; // left: 50%; transform: translate(-50%, -50%);';
1✔
86
    errorDiv.style.left = '10px';
1✔
87
    errorDiv.style.color = 'black';
1✔
88
    errorDiv.style.backgroundColor = 'red';
1✔
89
    canvas.parentElement?.appendChild(errorDiv);
1✔
90
    // canvas.style.position = 'absolute';
91
  }
92
}
93

94
function clearError(device: Device | null): void {
95
  if (!device) {
1!
96
    return;
×
97
  }
98

99
  const errorDiv = document.getElementById('animation-loop-error');
1✔
100
  if (errorDiv) {
1!
UNCOV
101
    errorDiv.remove();
×
102
  }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc