Verwendung

Limit the work an interaction performs.

tsx
// Limit the work an interaction performs.
import { Button, Text, VStack, signal } from 'kuito';
import { costOf, press, render, screen, test, type CostBudget } from 'kuito/tests';

function Like() {
  const liked = signal(false);

  return (
    <VStack>
      <Text color={liked.value ? '#ff3b30' : '#8e8e93'}>♥</Text>
      <Button onPress={() => (liked.value = !liked.value)}>Like</Button>
    </VStack>
  );
}

// A color change repaints one view: no layout, no new views.
const repaintOnly: CostBudget = { layoutPasses: 0, viewsCreated: 0, propWrites: 1 };

test('a like only repaints the heart', async () => {
  await render(<Like />);

  (await costOf(() => press(screen.getByText('Like')))).toStayWithin(repaintOnly);
});

Typdeklaration

ts
export type CostBudget = Partial<Counts>;

Mitglieder 13

NameTypErforderlichBeschreibung
recordsAppliednumberNeinRecords of the batches applied, the UI thread's prop writes included.
propWritesnumberNein—
wastedPropWritesnumberNeinProp writes of the value the view already had.
layoutPassesnumberNeinLayouts that computed at least one node.
wastedLayoutPassesnumberNeinLayout passes after which no box changed.
nodesLaidOutnumberNeinNodes the engine computed rather than took from its cache.
nodesFramednumberNeinBoxes the renderer took from a pass.
wastedFramesnumberNeinBoxes taken unchanged.
measureCallsnumberNeinLeaves measured: each one a miss of the engine's measure cache.
wastedMeasuresnumberNeinMeasures that answered what the leaf measured before it was marked dirty.
uiEntriesnumberNeinCalls into the UI-thread kernel: operations received, events, frames.
wastedUiEntriesnumberNeinEvents the UI-thread kernel had no handler for.
viewsCreatednumberNeinViews made with a native view: a flattened node has none.
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.