@reintent/lib/stamps
Cache keys for results a host keeps (a layout a model wrote, System One's approval): the choice values a result was made under, and the context they were read in.
A result holds only while they all do; it is never thrown away, so it holds again when the values come back. One made for one context does not hold in another just because the values match, unless the caller carries it on purpose. Built on the trace only.
under(reads, of?) → Stamp what to stamp a result with
stale(stamped, reads, { carry }) why it does not hold now (empty: it holds)
createCache().get(reads, { check }) the newest that holds, and passes `check`Type Aliases
Stamp
type Stamp = Record<string, unknown>;Defined in: packages/lib/src/stamps.ts
Stamped
type Stamped<R> = object;Defined in: packages/lib/src/stamps.ts
Type Parameters
| Type Parameter |
|---|
R |
Properties
| Property | Type |
|---|---|
under | Stamp |
value | R |
Functions
createCache()
function createCache<R>(): object;Defined in: packages/lib/src/stamps.ts
Stamped results, newest first. get returns the newest whose stamp holds and that passes check.
Type Parameters
| Type Parameter |
|---|
R |
Returns
object
| Name | Type |
|---|---|
get size | number |
get() | (reads, opts?) => Stamped<R> | undefined |
put() | (value, stamp) => void |
Example
import { choices, createIntent, host, useChoose } from '@reintent/core';
import { createCache, under } from '@reintent/lib/stamps';
function Slide() {
const layout = useChoose(choices('cols1', 'cols2'), {
of: 's1',
name: 'layout',
defaultValue: 'cols1',
});
return host('slide', { layout });
}
const intent = createIntent({ program: <Slide /> });
// A layout a model wrote for this evaluation, kept under the values it was written for.
const cache = createCache<string>();
cache.put('<one column, written by a model>', under(intent.realize().reads));
intent.decide({ of: 's1', name: 'layout' }, 'cols2');
console.log(cache.get(intent.realize().reads)); // → undefined
intent.history.undo(); // the values come back, and so does the result
const hit = cache.get(intent.realize().reads);
console.log(hit?.value); // → '<one column, written by a model>'stale()
function stale(
s,
reads,
opts?
): string[];Defined in: packages/lib/src/stamps.ts
Why a stamped result does not hold for this evaluation: the choices whose value moved, or that
are no longer read at all (the structure it was made for is gone), and '@ctx' when it was made
in another context. carry: true lets it hold in another context. Empty: it holds.
Parameters
| Parameter | Type |
|---|---|
s | Pick<Stamped<unknown>, "under"> |
reads | readonly ChoiceRead[] |
opts | { carry?: boolean; } |
opts.carry? | boolean |
Returns
string[]
Example
import { choices, createIntent, host, useChoose } from '@reintent/core';
import { stale, under } from '@reintent/lib/stamps';
function Slide() {
const layout = useChoose(choices('cols1', 'cols2'), {
of: 's1',
name: 'layout',
defaultValue: 'cols1',
});
return host('slide', { layout });
}
const intent = createIntent({ program: <Slide /> });
const stamped = { under: under(intent.realize().reads) };
console.log(stale(stamped, intent.realize().reads)); // → []
intent.decide({ of: 's1', name: 'layout' }, 'cols2');
console.log(stale(stamped, intent.realize().reads)); // → [ 's1#layout' ]under()
function under(reads, of?): Stamp;Defined in: packages/lib/src/stamps.ts
The values an evaluation went on (for the choices of these entities, or all), and the context.
Parameters
| Parameter | Type |
|---|---|
reads | readonly ChoiceRead[] |
of? | readonly string[] |
Returns
Last updated on
Edit on GitHub