Strictness
Qite components may declare a
static strict = { ... }
object to verify that
certain expected targets really exist. This is a lightweight safety net for
component structure — it helps catch cases where a template changed,
a child component is missing, or a selector no longer matches what your
component logic expects.
By default, strictness reports warnings through the component logger, so you'll get a console WARNING explaining exactly which component is problematic and lacks a target.
Basic usage
A strictness declaration may include the following keys:
- parts
- fields
- children
- parent
- selectors
Declare strict targets on the component class like this:
class CheckoutForm extends BaseComponent {
static strict = {
parts: ["title", "actions"],
fields: ["email", "name"],
children: [{ roles: "submit" }],
parent: "RootComponent",
selectors: [".checkout-marker"]
};
}
When the component is initialized, Qite validates these expectations by checking if there's at least one DOM element corresponding to each target in the component DOM tree.
What happens on failure
By default, strictness reports through the component logger with log level
WARN. A typical warning says that a particular part, field, child, parent
or selector was declared as strict but has no corresponding HTML element or
structure. Unknown strictness keys are also reported as warnings.
Example:
static strict = {
bananas: ["banana"]
};
This would report:
Unknown strictness type: bananas
Error mode
ComponentStrictness
uses:
ComponentStrictness.error_type = "WARN";
If you want strictness failures to be treated as errors instead, set:
ComponentStrictness.error_type = "ERROR";
This is useful in tests or during aggressive development, when you want broken component structure to fail immediately instead of merely warning.
When to use strictness
Strictness is best for targets your component truly depends on. It helps in large teams with many components when it's not always possible to remember or pass on the knowledge perfectly and a warning about a missing target can easily uncover a mistake.
It's perfectly fine NOT to use strictness in your components. Strictness is an extra harness, not a requirement, for writing components. It's useful because of the nature of how Qite works and the fact that HTML is separate from JavaScript code and is usually rendered in the back-end.
Do not overuse it for everything in the template. The goal is not to describe all HTML, but to protect important assumptions — and some targets may be optional, so they should not be included into strictness declaration.
In short: use strictness for things that would make the component invalid or misleading if they were missing.