Skip to content

StateView

A view of the library as it is at the moment of the call, which is what ctx.state provides. The data that it returns is a copy that a plugin cannot modify, and it does not change afterwards: to see later changes, call the view again.

Every member of this view requires the read permission.

const row = ctx.state.row(rowId);
if (row) {
const siblings = ctx.state.children(row.outline, row.parent);
const path = ctx.state.ancestors(row.id);
}
readonly libraryId: string;

The id of the library, which identifies it when a facet of the library is written.


readonly rev: number;

The number of the revision of the library that this view shows.


readonly viewer: string | null;

The id of the person who uses this device, which is the id of their group, or null while synchronization is not set up.

ancestors(id): readonly RowView[];

Lists the rows above a row: its parent first, then the parent of its parent, up to the top of the outline.

Parameter Type Description
id string the id of the row

readonly RowView[]

the ancestors, nearest first


children(outline, parent): readonly RowView[];

Lists the rows at one level of an outline, in order: either the rows at the top of the outline, or the children of one row.

Parameter Type Description
outline string the id of the outline
parent string | null the id of the row whose children to list, or null for the rows at the top level

readonly RowView[]

the rows


descendants(id): readonly RowView[];

Lists everything below a row, depth first and in order. The row itself is not included.

Parameter Type Description
id string the id of the row

readonly RowView[]

the descendants


friends(outline?): readonly FriendView[];

Lists the friends of the person, by name. The group of a friend is what ctx.crypto.sealTo({ friend: group }, …) takes to lock a text for them.

With an outline, it lists only the friends who are on the share of that outline: its owner and its active members. A friend who was invited and has not joined, who left or who was removed is not listed, and an outline that is not shared lists nobody.

Parameter Type Description
outline? string the id of a shared outline, to list only the friends who are on it

readonly FriendView[]

the friends: the id of each one’s group, and the name

const friends = ctx.state.friends();
// [{ group: 'a1b2…', name: 'Ann' }, { group: 'c3d4…', name: 'Bob' }]
const envelope = await ctx.crypto.sealTo({ friend: friends[0].group }, 'dinner at eight', { purpose: 'note' });
// only the friends who are on the shared outline of this row
const onIt = ctx.state.friends(row.outline); // [] when the outline is not shared

libraryFacet<T>(facet): T | undefined;

Reads the value of a facet that is attached to the library as a whole, for example a setting.

Type Parameter Description
T the type of the values of the facet
Parameter Type Description
facet Pick<FacetRef<T>, "key"> the facet

T | undefined

the value, or undefined when the facet has no value


outline(id): OutlineView | undefined;

Looks up an outline.

Parameter Type Description
id string the id of the outline

OutlineView | undefined

the outline, or undefined when there is no such outline


outlineRows(outline): readonly RowView[];

Lists all the rows of an outline, depth first and in order.

Parameter Type Description
outline string the id of the outline

readonly RowView[]

the rows


outlines(): readonly OutlineView[];

Lists every outline, in the order in which the person sees them.

readonly OutlineView[]

the outlines


row(id): RowView | undefined;

Looks up a row.

Parameter Type Description
id string the id of the row

RowView | undefined

the row, or undefined when there is no such row


rowCount(outline): number;

Counts the rows of an outline, headings included.

Parameter Type Description
outline string the id of the outline

number

the number of rows


search(id): SearchView | undefined;

Looks up a saved search.

Parameter Type Description
id string the id of the saved search

SearchView | undefined

the saved search, or undefined when there is no such search


searches(): readonly SearchView[];

Lists the saved searches, in order.

readonly SearchView[]

the saved searches