Usage

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);
});

Type declaration

ts
export type CostBudget = Partial<Counts>;

Members 13

NameTypeRequiredDescription
recordsAppliednumberNoRecords of the batches applied, the UI thread's prop writes included.
propWritesnumberNo—
wastedPropWritesnumberNoProp writes of the value the view already had.
layoutPassesnumberNoLayouts that computed at least one node.
wastedLayoutPassesnumberNoLayout passes after which no box changed.
nodesLaidOutnumberNoNodes the engine computed rather than took from its cache.
nodesFramednumberNoBoxes the renderer took from a pass.
wastedFramesnumberNoBoxes taken unchanged.
measureCallsnumberNoLeaves measured: each one a miss of the engine's measure cache.
wastedMeasuresnumberNoMeasures that answered what the leaf measured before it was marked dirty.
uiEntriesnumberNoCalls into the UI-thread kernel: operations received, events, frames.
wastedUiEntriesnumberNoEvents the UI-thread kernel had no handler for.
viewsCreatednumberNoViews made with a native view: a flattened node has none.
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.