Class: Document

Document

Represents a Sync Document, the contents of which is a single JSON object.

Properties:
Name Type Argument Default Description
sid String The immutable identifier of this document, assigned by the system.
uniqueName String <optional>
null An optional immutable identifier that may be assigned by the programmer to this document during creation. Globally unique among other Documents.
value Object The contents of this document.
Fires:

Methods


mutate(mutator)

Schedules a modification to this document that will apply a mutation function.
Parameters:
Name Type Description
mutator Document~Mutator A function that outputs a new value based on the existing value. May be called multiple times, particularly if this Document is modified concurrently by remote code. If the mutation ultimately succeeds, the Document will have made the particular transition described by this function.
Returns:
Type
Promise.<Object>

removeDocument()

Delete a document
Returns:
A promise which resolves if (and only if) the document is ultimately deleted.
Type
Promise.<void>

set(value [, conditional])

Assign new contents to this document.
Parameters:
Name Type Argument Default Description
value Object The new contents to assign.
conditional Boolean <optional>
false Determines whether to detect remote modifications that would race with this new value.
Returns:
A promise describing the outcome of the set. Among common network failures and incorrect permissions, this promise will be rejected if value was remotely modified and the `conditional` flag was set.
Type
Promise.<Object>

update(obj)

Modify a document by appending new fields (or by overwriting existing ones) with the values from the provided Object.
Parameters:
Name Type Description
obj Object Specifies the particular (top-level) attributes that will receive new values.
Returns:
A promise resolving to the modified item in its new state.
Type
Promise.<Object>

Type Definitions


Mutator(data)

Applies a transformation to the document value.
Parameters:
Name Type Description
data Object The current value of the item in the cloud.
Returns:
The desired new value for the item.
Type
Object

Events


removed

Fired when the document is removed, whether the remover was local or remote.
Parameters:
Type Description
Boolean 'true' if the item was removed by local code, 'false' otherwise

removedRemotely

Fired when the document is removed by remote code.

updated

Fired when the document's contents have changed, whether the updater was local or remote.
Parameters:
Type Description
Object A snapshot of the document's new contents.
Boolean Equals 'true' if item was removed by local actor, 'false' otherwise

updatedRemotely

Fired when a document's contents were changed by remote code.
Parameters:
Type Description
Object A snapshot of the document's new contents.