Skip to main content
Collections provide type-safe management of synchronized entities. They wrap the sync client’s store with a convenient API for creating, reading, updating, and deleting records.

Overview

Creating a Collection

The entity name should match what your server-side Mutator uses.

Collection Methods

Create

Creates a new entity:
This:
  1. Stores the entity locally (immediate)
  2. Queues a mutation (background sync)
  3. Returns an Entity reference

Get

Gets an entity reference by ID:
This returns an Entity even if it doesn’t exist yet. Use Exists() to check.

All

Returns all entities in the collection (reactive):

Count

Returns the number of entities (reactive):

Find

Finds entities matching a predicate:

Has

Checks if an entity exists:

Entity Methods

An Entity is a reference to a single record.

ID

Returns the entity’s unique identifier:

Get

Returns the current value (reactive):

Set

Updates the entity value:
This:
  1. Updates local store (immediate)
  2. Queues an update mutation (background sync)

Delete

Removes the entity:
This:
  1. Removes from local store (immediate)
  2. Queues a delete mutation (background sync)

Exists

Checks if the entity exists:

Reactive Usage

Collections and entities are reactive. Use them with Computed and Effect:

Computed Example

Effect Example

Complete Example: Todo App

Patterns

CRUD Operations

List with Filter

Sorted List

Pagination

Multiple Collections

Best Practices

1. Use Meaningful IDs

2. Keep Entities Small

3. Check Existence

4. Use Computed for Derived Data