Set.single()

Create a Set containing a single provided element.

Signature

Set.single(element: A) => Set<A>

Description

Creates a Set containing a single element. The element is passed to the method as an argument.

You can use an event source to track changes to a Set containing a single document. These event sources only emit events when the document changes.

You typically use Set.single() to create a Set from a Document for a document event source.

Parameters

Parameter Type Required Description

element

Generic

Yes

Value for the returned Set's element.

Return value

Type Description

Set<Generic>

Set containing the provided element.

Examples

The following uses single() to creates a Set from a single document.

// 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)
{
  data: [
    {
      id: "111",
      coll: Product,
      ts: Time("2099-03-21T19:40:45.430Z"),
      name: "cups",
      description: "Translucent 9 Oz, 100 ct",
      price: 698,
      stock: 100,
      category: Category("123")
    }
  ]
}

You can call set.eventsOn() or set.eventSource() on the Set to create a document event sources.

let product = Product.byName("cups").first()
Set.single(product).eventSource()

The query returns an event source:

"g9WD1YPG..."

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!