@reintent/lib/changes
What a change of program did to the decisions a person made, from the evaluations before and after (a reprogramming was accepted, a guard went the other way):
added / removed choices read now and not before, and the other way round
kept a decision that applied before and still does
waiting one that applied and no longer does: its choice is not read, or its value
is not one of the possibilities (ChoiceRead.waiting). Kept, not applied
back one that waited and applies againNothing here writes.
Interfaces
ProgramChange
Defined in: packages/lib/src/changes.ts
Properties
Functions
changes()
function changes(
before,
after,
decided
): ProgramChange;Defined in: packages/lib/src/changes.ts
Parameters
| Parameter | Type |
|---|---|
before | readonly ChoiceRead[] |
after | readonly ChoiceRead[] |
decided | readonly string[] |
Returns
Example
import { choices, createIntent, host, useChoose } from '@reintent/core';
import { changes } from '@reintent/lib/changes';
const Reply = (p: { tones: readonly string[] }) =>
host('reply', {
tone: useChoose(choices(p.tones), { of: 'r1', name: 'tone', defaultValue: 'warm' }),
});
const intent = createIntent({ program: <Reply tones={['formal', 'warm']} /> });
// A person asks for a tone the program does not have yet: kept, and waiting.
intent.decide({ of: 'r1', name: 'tone' }, 'playful');
const before = intent.realize().reads;
// A reprogramming adds it: the decision applies again.
intent.setProgram(<Reply tones={['formal', 'warm', 'playful']} />);
const after = intent.realize().reads;
console.log(changes(before, after, ['r1#tone']));
// → { added: [], removed: [], kept: [], waiting: [], back: [ 'r1#tone' ] }diff()
function diff(before, after): string[];Defined in: packages/lib/src/changes.ts
What changed between two evaluations, choice by choice: key: was → is (source). A choice is
named by its possibility, its tag ("big", not the host data { kind: 'big', … }), as a trace
compares them: the same possibility with other data (a reprogramming rescaled it) is not a change.
Parameters
| Parameter | Type |
|---|---|
before | readonly ChoiceRead[] |
after | readonly ChoiceRead[] |
Returns
string[]
Example
import { choices, createIntent, host, useChoose } from '@reintent/core';
import { diff } from '@reintent/lib/changes';
function Reply() {
const tone = useChoose(choices('formal', 'warm'), {
of: 'r1',
name: 'tone',
defaultValue: 'warm',
});
return host('reply', { tone });
}
const intent = createIntent({ program: <Reply /> });
const before = intent.realize().reads;
intent.decide({ of: 'r1', name: 'tone' }, 'formal');
console.log(diff(before, intent.realize().reads));
// → [ 'r1#tone: "warm" → "formal" (decision)' ]Last updated on
Edit on GitHub