Reintent

@reintent/language/binding

The two bindings, as a chain: what was said is bound to choices by identity (`said`), and a choice is bound to the picture by the view paths its `about.view` names (`man.hat`, `wardrobe.door.right`, written by `@reintent/lib/vocab`'s `view`).

Point at any of the three (a span, a choice, a place on the stage) and the chain is what it binds to in the other two.

chainOf        from what is pointed at, the spans, choices and view paths it binds to
choicesOfSpan  the choices a span is about
choicesAt      the choices whose view reaches a path on the stage, the closest first
viewsOf        the view paths a choice moves
reach          how well a view path names a path on the stage

Only ChoiceRead, its about and a Said are read: the chain is the same for a program written in JSX and one read from a declaration. It is data, with no view: a host draws it (the lab UI's words, rows and lines light what is in it).

Interfaces

Chain

Defined in: packages/language/src/binding.ts

What a focus binds to in the words (span ids), the choices (keys) and the picture (view paths).

Properties

PropertyType
choicesReadonlySet<string>
spansReadonlySet<string>
viewsReadonlySet<string>

Type Aliases

Focus

type Focus = 
  | {
  choice?: string;
  span?: string;
  view?: string;
}
  | null;

Defined in: packages/language/src/binding.ts

What a person points at: a span (its id), a choice (its key), or a path on the stage.

Variables

NO_CHAIN

const NO_CHAIN: Chain;

Defined in: packages/language/src/binding.ts

Nothing pointed at: an empty chain.

Functions

chainOf()

function chainOf(
   said, 
   reads, 
   focus, 
   shown?
): Chain;

Defined in: packages/language/src/binding.ts

From what is pointed at, the chain through the other two. A span gives its choices and their view paths; a choice gives its spans and view paths; a path on the stage gives the choices whose view reaches it, and their spans. shown says which choices are on the stage now (a dream's beat not on screen is bound to nothing there).

Parameters

ParameterType
saidSaid | null | undefined
readsreadonly ChoiceRead[]
focusFocus
shown(r) => boolean

Returns

Chain

Example

import { createIntent, entity, host, useChoose } from '@reintent/core';
import { chainOf } from '@reintent/language/binding';
import { bind } from '@reintent/language/said';
import { vocab } from '@reintent/lib/vocab';

const Size = vocab({ usual: { words: ['正常'] }, absurd: { words: ['大得离谱'] } });
const man = entity('man', { hat: Size.decl({ default: 'absurd', view: ['man.hat'] }) });
const Man = man(function Man() {
  return host('man', { hat: useChoose(man.hat).kind });
});
const { reads } = createIntent({ program: <Man /> }).realize();
const said = bind('一顶大得离谱的帽子', [['大得离谱', 'man', 'hat', 'absurd']]);

const fromWords = chainOf(said, reads, { span: 'w1' });
console.log([...fromWords.choices], [...fromWords.views]); // → [ 'man#hat' ] [ 'man.hat' ]

const fromStage = chainOf(said, reads, { view: 'man[man].hat' });
console.log([...fromStage.spans], [...fromStage.choices]); // → [ 'w1' ] [ 'man#hat' ]

choicesAt()

function choicesAt(
   path, 
   reads, 
   shown?
): string[];

Defined in: packages/language/src/binding.ts

The choices (their keys) whose view reaches a path on the stage, the closest only (all those equally close). shown says which choices are on the stage now.

Parameters

ParameterType
pathstring
readsreadonly ChoiceRead[]
shown(r) => boolean

Returns

string[]


choicesOfSpan()

function choicesOfSpan(s, reads): string[];

Defined in: packages/language/src/binding.ts

The choices a span is about (their keys): its choice, or (naming only the thing) every choice of the thing.

Parameters

ParameterType
sPick<Span, "of" | "name">
readsreadonly ChoiceRead[]

Returns

string[]


reach()

function reach(view, path): number;

Defined in: packages/language/src/binding.ts

How well a choice's view path names a path on the stage: 3 the same part, 2 the same instance, 1 the same thing, 0 not at all. A path is a semantic path (man[bedside].hat): an entity, an instance in brackets, parts after dots.

Parameters

ParameterType
viewstring
pathstring

Returns

number

Example

import { reach } from '@reintent/language/binding';

console.log(reach('man.hat', 'man[bedside].hat')); // → 3
console.log(reach('man[bedside]', 'man[bedside].eyes')); // → 2
console.log(reach('man', 'man[wardrobe]')); // → 1
console.log(reach('man.hat', 'wardrobe.door')); // → 0

viewsOf()

function viewsOf(r): string[];

Defined in: packages/language/src/binding.ts

The view paths a choice moves: its about.view, or else its thing.

Parameters

ParameterType
rPick<ChoiceRead, "about" | "id">

Returns

string[]

Example

import { viewsOf } from '@reintent/language/binding';

console.log(viewsOf({ id: { of: 'man', name: 'hat' }, about: { view: ['man.hat'] } }));
// → [ 'man.hat' ]
console.log(viewsOf({ id: { of: 'lamp', name: 'on' }, about: undefined })); // → [ 'lamp' ]

Last updated on

Edit on GitHub