MCPcopy Create free account
hub / github.com/nodejs/node / V8CustomElement

Class V8CustomElement

deps/v8/tools/js/web-api-helper.mjs:7–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import {delay, formatBytes} from './helper.mjs';
6
7export class V8CustomElement extends HTMLElement {
8 _updateTimeoutId;
9 _updateCallback = this.forceUpdate.bind(this);
10
11 constructor(templateText) {
12 super();
13 const shadowRoot = this.attachShadow({mode: 'open'});
14 shadowRoot.innerHTML = templateText;
15 }
16
17 $(id) {
18 return this.shadowRoot.querySelector(id);
19 }
20
21 querySelectorAll(query) {
22 return this.shadowRoot.querySelectorAll(query);
23 }
24
25 requestUpdate(useAnimation = false) {
26 if (useAnimation) {
27 window.cancelAnimationFrame(this._updateTimeoutId);
28 this._updateTimeoutId =
29 window.requestAnimationFrame(this._updateCallback);
30 } else {
31 // Use timeout tasks to asynchronously update the UI without blocking.
32 clearTimeout(this._updateTimeoutId);
33 const kDelayMs = 5;
34 this._updateTimeoutId = setTimeout(this._updateCallback, kDelayMs);
35 }
36 }
37
38 forceUpdate() {
39 this._updateTimeoutId = undefined;
40 this._update();
41 }
42
43 _update() {
44 throw Error('Subclass responsibility');
45 }
46
47 get isFocused() {
48 return document.activeElement === this;
49 }
50}
51
52export class FileReader extends V8CustomElement {
53 constructor(templateText) {

Callers

nothing calls this directly

Calls 1

bindMethod · 0.45

Tested by

no test coverage detected