Utilisation

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

Déclaration du type

ts
export type CostBudget = Partial<Counts>;

Membres 13

NomTypeRequisDescription
recordsAppliednumberNonRecords of the batches applied, the UI thread's prop writes included.
propWritesnumberNon—
wastedPropWritesnumberNonProp writes of the value the view already had.
layoutPassesnumberNonLayouts that computed at least one node.
wastedLayoutPassesnumberNonLayout passes after which no box changed.
nodesLaidOutnumberNonNodes the engine computed rather than took from its cache.
nodesFramednumberNonBoxes the renderer took from a pass.
wastedFramesnumberNonBoxes taken unchanged.
measureCallsnumberNonLeaves measured: each one a miss of the engine's measure cache.
wastedMeasuresnumberNonMeasures that answered what the leaf measured before it was marked dirty.
uiEntriesnumberNonCalls into the UI-thread kernel: operations received, events, frames.
wastedUiEntriesnumberNonEvents the UI-thread kernel had no handler for.
viewsCreatednumberNonViews made with a native view: a flattened node has none.
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.