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.
Example
Section titled “Example”const row = ctx.state.row(rowId);if (row) { const siblings = ctx.state.children(row.outline, row.parent); const path = ctx.state.ancestors(row.id);}Properties
Section titled “Properties”libraryId
Section titled “libraryId”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.
viewer
Section titled “viewer”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.
Methods
Section titled “Methods”ancestors()
Section titled “ancestors()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
the id of the row |
Returns
Section titled “Returns”readonly RowView[]
the ancestors, nearest first
children()
Section titled “children()”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.
Parameters
Section titled “Parameters”| 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 |
Returns
Section titled “Returns”readonly RowView[]
the rows
descendants()
Section titled “descendants()”descendants(id): readonly RowView[];Lists everything below a row, depth first and in order. The row itself is not included.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
the id of the row |
Returns
Section titled “Returns”readonly RowView[]
the descendants
friends()
Section titled “friends()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
outline? |
string |
the id of a shared outline, to list only the friends who are on it |
Returns
Section titled “Returns”readonly FriendView[]
the friends: the id of each one’s group, and the name
Example
Section titled “Example”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 rowconst onIt = ctx.state.friends(row.outline); // [] when the outline is not sharedlibraryFacet()
Section titled “libraryFacet()”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 Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
T |
the type of the values of the facet |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
facet |
Pick<FacetRef<T>, "key"> |
the facet |
Returns
Section titled “Returns”T | undefined
the value, or undefined when the facet has no value
outline()
Section titled “outline()”outline(id): OutlineView | undefined;Looks up an outline.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
the id of the outline |
Returns
Section titled “Returns”OutlineView | undefined
the outline, or undefined when there is no such outline
outlineRows()
Section titled “outlineRows()”outlineRows(outline): readonly RowView[];Lists all the rows of an outline, depth first and in order.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
outline |
string |
the id of the outline |
Returns
Section titled “Returns”readonly RowView[]
the rows
outlines()
Section titled “outlines()”outlines(): readonly OutlineView[];Lists every outline, in the order in which the person sees them.
Returns
Section titled “Returns”readonly OutlineView[]
the outlines
row(id): RowView | undefined;Looks up a row.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
the id of the row |
Returns
Section titled “Returns”RowView | undefined
the row, or undefined when there is no such row
rowCount()
Section titled “rowCount()”rowCount(outline): number;Counts the rows of an outline, headings included.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
outline |
string |
the id of the outline |
Returns
Section titled “Returns”number
the number of rows
search()
Section titled “search()”search(id): SearchView | undefined;Looks up a saved search.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
the id of the saved search |
Returns
Section titled “Returns”SearchView | undefined
the saved search, or undefined when there is no such search
searches()
Section titled “searches()”searches(): readonly SearchView[];Lists the saved searches, in order.
Returns
Section titled “Returns”readonly SearchView[]
the saved searches
