Wire up garden controls
This commit is contained in:
parent
018f8c9d4d
commit
839747304e
15 changed files with 1457 additions and 393 deletions
24
src/utils/dom.ts
Normal file
24
src/utils/dom.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { ErrorCode, RuntimeError } from './error-handler';
|
||||
|
||||
type ElementConstructor<T extends Element> = abstract new () => T;
|
||||
|
||||
export const queryRequiredElement = <T extends Element>(
|
||||
selector: string,
|
||||
constructor: ElementConstructor<T>
|
||||
): T => {
|
||||
const element = document.querySelector(selector);
|
||||
if (!(element instanceof constructor)) {
|
||||
throw new RuntimeError(
|
||||
ErrorCode.DOM_ELEMENT_MISSING,
|
||||
`Missing required DOM element: ${selector}`,
|
||||
{
|
||||
details: {
|
||||
expectedType: constructor.name,
|
||||
selector,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return element;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue