Skip to content

DraftBuilder

A DraftBuilder is passed to the propose function of a command and to normalize functions. It lets you describe the modifications that you want to make to the library: changing fields and facets of rows and outlines, creating rows, and deleting rows. Calling its methods does not change anything by itself. When your function returns, the app validates the draft and applies it like any other change.

A change is a list of deltas, each of which describes one modification, such as a title that went from “A” to “B”. When a draft modifies the same row several times, the app records a single delta for that row, holding the value before the first modification and the value after the last one.

A draft cannot move rows or create outlines. To do either, call the corresponding command with ctx.dispatch, or return it as a follow-up from didUpdate or didWrite.

build(): ChangeDraft;

Produces the draft. It contains one updated delta for each thing that was modified, and only the fields that really changed. A thing that returned to its original value produces no delta.

ChangeDraft

the draft


createRows(next, rows): string[];

Creates rows at the same level as an existing row, immediately after it and after the rows that are below it. The new rows are created in the order given, and each of them can start with facets.

Parameter Type Description
next string the id of the row after which the new rows are inserted
rows readonly object[] the rows to create: each has a title and, optionally, facets

string[]

the ids of the new rows, in order


deleteRow(id): this;

Deletes a row, together with all the rows below it.

Parameter Type Description
id string the id of the row

this

the builder, so that calls can be chained


deleteSearch(id): this;

Deletes a saved search.

Parameter Type Description
id string the id of the saved search

this

the builder, so that calls can be chained


facet<T>(id, ref): object;

Modifies the value of a facet on a row or on an outline. A saved search has no facets.

Type Parameter Description
T the type of the values of the facet
Parameter Type Description
id string the id of the row or of the outline
ref Pick<FacetRef<T>, "key"> the facet

object

an object with set(value), which gives the facet a value, and remove(), which removes the value

Name Type
remove() () => void
set() (value) => void

newId(): string;

Generates a new unique id, using the random number source of the app.

string

the id


now(): number;

Returns the current time in milliseconds, read from the clock of the app.

number

the time, in milliseconds


update(id, fields): this;

Modifies fields of a row, of an outline or of a saved search, for example title or note. For an outline, kind switches between standard and journal, and the Inbox cannot change its kind.

Parameter Type Description
id string the id of the row, of the outline or of the saved search
fields Fields the fields to modify, with their new values

this

the builder, so that calls can be chained