updateDocument
The updateDocument method is responsible for updating a document in the underlying content source.
The visual editor calls this method when the user updates one of the document fields using the visual editing UI.
Parameters
This method receives an options
object with the following properties:
document:
Document
: The existing document from the visual editing cache before any updates are applied.operations: UpdateOperation[]
: An array ofUpdateOperation
. Please introspect theUpdateOperation
in the@stackbit/types
package for more information.userContext?: UserContext
: An object that contains the user'semail
,name
, and optional OAuth access tokens defined by theUserContext
generic type.
The visual editor may delay and group several changes into a single method call. In this case, the operations
array will contain multiple operations, each representing a value change of a different field.
Return Value
This method should return a Promise
that resolves with void
, indicating that the document has been successfully updated.
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
The convertOperationsToUpdateAPI
method is an example of a utility method that receives an array of update operations and converts them to the updated fields expected by the content source API.