Skip to content

FacetRef

The description of a facet: its name, the kind of thing it is attached to, how its values are merged, whether it is shared with other devices, and which values it accepts. It also provides the three operations that every facet has. of reads a value, and set and clear build the requests that write and remove a value.

The facets that ship with the app are available as FacetRef objects under ctx.facets.core, for example ctx.facets.core.tasks.status. A facet that a plugin defines with ctx.facets.define is returned as a FacetHandle, which is a FacetRef with two further members.

const status = ctx.facets.core.tasks.status.of(row); // read the value
await ctx.dispatch(ctx.facets.core.tasks.status.set(row.id, { state: 'done' })); // write the value
Type Parameter Description
T the type of the values of the facet
readonly alias?: string;

A short name that searches can use for the facet, for example pomodoro in the search pomodoro>3.


readonly key: string;

The name of the facet, written <plugin id>/<name>. The library saves each value under this name. Code normally uses the facet object and does not need to type the name.


readonly merge: MergeKind;

Determines the result when two devices change the value at the same time. lww, which stands for “last write wins”, keeps the later change. set keeps what both devices added to the set. text merges the two texts into one. counter adds up what each device added.


readonly paths?: readonly string[];

The parts of the value that searches are able to look at quickly. The path . designates the whole value. A facet must declare its paths for a search to be able to use its index.


readonly schema: Schema;

The description of the values that the facet accepts. The app checks every value against it when the value is written, and refuses a value that does not conform.


readonly sync: boolean;

When false, the value stays on the device where it was written, and other devices never receive it. Otherwise the value is shared with the other devices of the person.


readonly target: FacetTarget;

The kind of thing that the facet is attached to: a row, an outline or the library.

clear(id): BuiltIntent;

Builds the request that removes the value of the facet from a row or an outline. The request is not run by this call: pass it to ctx.dispatch, or return it from a hook as a follow-up.

Parameter Type Description
id string the id of the row or of the outline

BuiltIntent

the request


of(entity): T | undefined;

Reads the value of the facet on a row or an outline, or on any other object that has a facets field.

Parameter Type Description
entity | { facets: Readonly<Record<string, unknown>>; } | null | undefined the row or outline whose value to read

T | undefined

the value, or undefined when the facet has no value there


set(id, value): BuiltIntent;

Builds the request that gives the facet a value on a row or an outline. The request is not run by this call: pass it to ctx.dispatch, or return it from a hook as a follow-up. For a facet of the library, pass the id of the library.

Parameter Type Description
id string the id of the row or of the outline
value T the new value

BuiltIntent

the request