- Регистрация
- 1 Мар 2015
- Сообщения
- 1,481
- Баллы
- 155
In this article, we review a commonly used utility named, throwError in Infero.js source code.
export function renderInternal(
input: VNode | InfernoNode,
parentDOM: ParentDOM,
callback: (() => void) | null,
context: ContextObject,
): void {
// Development warning
if (process.env.NODE_ENV !== 'production') {
if (documentBody === parentDOM) {
throwError(
'you cannot render() to the "document.body". Use an empty element as a container instead.',
);
}
if (isInvalid(parentDOM)) {
throwError(
`render target ( DOM ) is mandatory, received ${
parentDOM === null ? 'null' : typeof parentDOM
}`,
);
}
}
This above code snippet is picked from
throwError
throwError accepts one parameter which is a string, a message explaining the type of error thrown.
throwError(
`render target ( DOM ) is mandatory, received ${
parentDOM === null ? 'null' : typeof parentDOM
}`,
)
This throwError utility is used in mutiple places across the inferno codebase.
Declaration
This function is declared in a package, .
export function throwError(message?: string): void {
if (!message) {
message = ERROR_MSG;
}
throw new Error(`Inferno Error: ${message}`);
}
The message argument here is just a string, but you see that variable ERROR_MSG that is used a fallback in case there is no message, i.e., message is empty string or null or undefined? this ERROR_MSG is defined at the top of the same file.
export const ERROR_MSG =
'a runtime error occured! Use Inferno in development environment to find the error.';
About me:
Hey, my name is . I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.
Configure features such as Changesets in your Next.js project using .
Email — ramu@thinkthroo.com
My Github —
My website —
My YouTube channel —
Learning platform —
Codebase Architecture —
Best practices —
Production-grade projects —
References
export function renderInternal(
input: VNode | InfernoNode,
parentDOM: ParentDOM,
callback: (() => void) | null,
context: ContextObject,
): void {
// Development warning
if (process.env.NODE_ENV !== 'production') {
if (documentBody === parentDOM) {
throwError(
'you cannot render() to the "document.body". Use an empty element as a container instead.',
);
}
if (isInvalid(parentDOM)) {
throwError(
`render target ( DOM ) is mandatory, received ${
parentDOM === null ? 'null' : typeof parentDOM
}`,
);
}
}
This above code snippet is picked from
throwError
throwError accepts one parameter which is a string, a message explaining the type of error thrown.
throwError(
`render target ( DOM ) is mandatory, received ${
parentDOM === null ? 'null' : typeof parentDOM
}`,
)
This throwError utility is used in mutiple places across the inferno codebase.
Declaration
This function is declared in a package, .
export function throwError(message?: string): void {
if (!message) {
message = ERROR_MSG;
}
throw new Error(`Inferno Error: ${message}`);
}
The message argument here is just a string, but you see that variable ERROR_MSG that is used a fallback in case there is no message, i.e., message is empty string or null or undefined? this ERROR_MSG is defined at the top of the same file.
export const ERROR_MSG =
'a runtime error occured! Use Inferno in development environment to find the error.';
About me:
Hey, my name is . I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.
Configure features such as Changesets in your Next.js project using .
Email — ramu@thinkthroo.com
My Github —
My website —
My YouTube channel —
Learning platform —
Codebase Architecture —
Best practices —
Production-grade projects —
References