Reintent
/

useChoose

Reads a choice's value in this evaluation.

Call Signature

function useChoose<T>(c, opts): T;

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

A choice's value in this evaluation: the bind. Its identity is { of, name } (the entity it is about, and which question), so a read may sit under an if. The value comes from the choice's layers by the cascade: a preview, a person's decision, constraints, System One's belief or Code's prior, collapsed by the policy in scope; unresolved, defaultValue (or as otherwise says).

Type Parameters

Type Parameter
T

Parameters

ParameterType
c| Choices<T> | Generation<T> | Judged<T>
optsChooseOptions<T>

Returns

T

Example

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

// A choice is read by its identity, { of, name }: which entity, and which question.
function Reply(p: { id: string }) {
  const send = useChoose(choices('now', 'tomorrow'), {
    of: p.id,
    name: 'send',
    defaultValue: 'tomorrow',
  });
  return host('reply', { send });
}

const intent = createIntent({ program: <Reply id="r1" /> });
console.log(intent.realize().reads[0].value); // → 'tomorrow'

// A person's decision is the top of the cascade.
intent.decide({ of: 'r1', name: 'send' }, 'now');
console.log(intent.realize().reads[0].value); // → 'now'

Call Signature

function useChoose<R>(ref, ...opts): ReadOf<R>;

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

A declared choice's value, by its handle (0015 §5.1): useChoose(Man.hat(id)). What it depends on is handed in as given; where it does not apply it is not read, and is undefined.

Type Parameters

Type Parameter
R extends Declared

Parameters

ParameterType
refR
...optsDeclaredArgs<R>

Returns

ReadOf<R>

Call Signature

function useChoose<T>(
   id, 
   c, 
   opts?
): T;

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

A choice by its identity, its possibilities and how it is asked here (0092 §4): the identity is { of, name } or an entity's handle, and only says which choice; the possibilities, question, uses and ask are this read's.

Type Parameters

Type Parameter
T

Parameters

ParameterType
idId | Declared
c| Choices<T> | Generation<T> | Judged<T>
opts?Omit<ChooseOptions<T>, "of" | "name">

Returns

T


Last updated on

Edit on GitHub