What the framework does
LoadState, ErrorFallback, IslandMarker, Inspector. They are copied into your app’s ui/ by qatjs add framework: the code is yours to edit.
Example
Leyla Məmmədova, customer since 2021.
user.errorCouldn’t load the accountThis part of the page failedThe rest keeps working. Your cart is saved.
src/Checkout.qx:41 — cart() is nullisland Cart, 612 B
Tandir bread × 2
import Button from './ui/button/button.qx'
import { ErrorFallback, IslandMarker, LoadState, type Loadable } from './ui/framework/framework.qx'
const failed: Loadable<{ name: string }> = {
loading: () => false,
data: () => undefined,
error: () => new Error('api.user(42) answered 503 after 2 tries.'),
reload: () => {},
}
export default function Example() {
let reloads = state(0)
let ready: Loadable<{ name: string; since: number }> = {
loading: () => reloads % 2 === 1,
data: () => ({ name: 'Leyla Məmmədova', since: 2021 }),
error: () => undefined,
reload: () => reloads++,
}
return (
<div class="example-grid">
<LoadState of={ready} name="user">
{(u) => (
<p>
{u.name}, customer since {u.since}.{' '}
<Button size="sm" on:click={() => reloads++}>
Refresh
</Button>
</p>
)}
</LoadState>
<LoadState of={failed} name="user" errorTitle="Couldn’t load the account">
{(u) => <p>{u.name}</p>}
</LoadState>
<ErrorFallback error={new Error('cart() is null')} where="src/Checkout.qx:41">
The rest keeps working. Your cart is saved.
</ErrorFallback>
<IslandMarker name="Cart" bytes={612}>
<p>Tandir bread × 2</p>
</IslandMarker>
</div>
)
}reloads stateAdd it
npx qatjs add frameworkLoadState
As a custom element: <ui-load-state>.
| Prop | Type | Attribute |
|---|---|---|
of | Loadable<T> | property only |
name | string | yes |
label | string | yes |
errorTitle | QatNode | property only |
retryLabel | string | yes |
ErrorFallback
As a custom element: <ui-error-fallback>.
| Prop | Type | Attribute |
|---|---|---|
error | unknown | property only |
title | QatNode | property only |
where | string | yes |
retry | () => void | property only |
retryLabel | string | yes |
IslandMarker
As a custom element: <ui-island-marker>.
| Prop | Type | Attribute |
|---|---|---|
name | string | yes |
bytes | number | yes |
Inspector
The devtools panel's chrome: tabs, a count, the graph as rows (WAI-APG tabs and a list to choose from). As a custom element: <ui-inspector>.
| Prop | Type | Attribute |
|---|---|---|
tabs | string[] | property only |
tab | string | yes |
summary | string | yes |
nodes | InspectorNode[] | property only |
selected | string | yes |
label | string | yes |
| Event | Detail |
|---|---|
on:update:tab | CustomEvent<string> |
on:update:selected | CustomEvent<string> |