Reintent
/

<World>

A boundary that says how the choices below it settle, and what happens when they cannot.

function World<T>(p): Child;

Defined in: packages/core/src/intent/handlers.ts

One boundary for the choices below it (0033 §5, 0046): how they collapse (minMargin), what to do when one cannot settle (onUnresolved), hypotheses written nowhere (as), and enumeration (each). What it leaves out, the next World out says; the root collapses, falls back when unsure, and reports to the host what fits nothing.

Type Parameters

Type ParameterDefault type
Tunknown

Parameters

ParameterType
pWorldProps<T>

Returns

Child

Examples

import { choices, createIntent, host, useChoose, World } from '@reintent/core';

// A prior that leans, but not by much: 0.55 against 0.45.
const fits = choices([
  { value: 'keep', weight: 0.55 },
  { value: 'fill', weight: 0.45 },
]);
function Photo(p: { id: string }) {
  const fit = useChoose(fits, { of: p.id, name: 'fit', defaultValue: 'fill' });
  return host('photo', { fit });
}

const intent = createIntent({
  program: (
    <>
      <Photo id="a" />
      <World minMargin={0.05}>
        <Photo id="b" />
      </World>
      <World as={{ 'c#fit': 'keep' }}>
        <Photo id="c" />
      </World>
    </>
  ),
});
const [a, b, c] = intent.realize().reads;
console.log(a.value, a.status); // → 'fill' 'unresolved'
console.log(b.value, b.status); // → 'keep' 'resolved'
console.log(c.value, c.source); // → 'keep' 'preview'
import {
  choices,
  createIntent,
  host,
  useChoose,
  World,
  type HostNode,
} from '@reintent/core';

function Card() {
  const tone = useChoose(choices('warm', 'formal'), { of: 'card', name: 'tone' });
  return host('card', { tone });
}

// Every possible card, one path each, with its probability.
const intent = createIntent({
  program: (
    <World each>
      <Card />
    </World>
  ),
});
const worlds = intent.realize().tree as HostNode;
console.log(worlds.children.map((w) => (w as HostNode).props.at)); // → [ { 'card#tone': 'warm' }, { 'card#tone': 'formal' } ]

Last updated on

Edit on GitHub