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.
Methods
Section titled “Methods”build()
Section titled “build()”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.
Returns
Section titled “Returns”the draft
createRows()
Section titled “createRows()”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.
Parameters
Section titled “Parameters”| 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 |
Returns
Section titled “Returns”string[]
the ids of the new rows, in order
deleteRow()
Section titled “deleteRow()”deleteRow(id): this;Deletes a row, together with all the rows below it.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
the id of the row |
Returns
Section titled “Returns”this
the builder, so that calls can be chained
deleteSearch()
Section titled “deleteSearch()”deleteSearch(id): this;Deletes a saved search.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
the id of the saved search |
Returns
Section titled “Returns”this
the builder, so that calls can be chained
facet()
Section titled “facet()”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 Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
T |
the type of the values of the facet |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id |
string |
the id of the row or of the outline |
ref |
Pick<FacetRef<T>, "key"> |
the facet |
Returns
Section titled “Returns”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()
Section titled “newId()”newId(): string;Generates a new unique id, using the random number source of the app.
Returns
Section titled “Returns”string
the id
now(): number;Returns the current time in milliseconds, read from the clock of the app.
Returns
Section titled “Returns”number
the time, in milliseconds
update()
Section titled “update()”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.
Parameters
Section titled “Parameters”| 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 |
Returns
Section titled “Returns”this
the builder, so that calls can be chained
