set.eventSource()
Creates an event source that tracks changes to documents in a supported Set.
Description
The eventSource()
method creates an event source
token that tracks changes to documents in a
supported Set. The token has the
EventSource type:
"g9WD1YPG..."
You can only call eventSource()
on a
supported Set. The exact
behavior of the method depends on this source. The calling Set isn’t
changed.
Source Sets for event sources support a limited number of transformations and filters.
Return value
Type | Description |
---|---|
A string-encoded token that represents the event source. Use the token to consume events as an Event Feed or Event Stream. |
Examples
Collection event sources
Calling eventSource()
directly on
collection.all()
tracks
any change to any document in the collection.
Product.all().eventSource()
The query returns an event source:
"g9WD1YPG..."
Index event sources
Event sources for indexes only send events for changes to the index’s terms or values fields.
For example, the following Product
collection’s byName()
index has:
-
A term field of
name
-
Value fields of
name
andprice
collection Product {
*: Any
index byName {
terms [.name]
values [.name, .price]
}
...
}
The following query only tracks changes to the name
or price
fields for Product
documents with a name
of limes
.
Product.byName("limes").eventSource()
Document event sources
You can use event sources to track changes to a Set containing a single document. These event sources are only sent events when the document changes.
// Uses the `Product` collection's `byName()` index and
// the `first()` method to get a single document.
let product = Product.byName("cups").first()
Set.single(product).eventSource()
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!