EventDef
EventDef<
TName,TType,TEncoded,TDerived> =object
Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:30
Core type representing an event definition in LiveStore.
An EventDef defines the structure and behavior of an event type, including:
- A unique name identifying the event type (conventionally versioned, e.g.,
v1.TodoCreated) - A schema for validating and encoding/decoding event arguments
- Options controlling sync behavior and constraints
EventDefs are callable - invoking them creates a partial event object suitable for store.commit().
Example
Section titled “Example”import { Events } from '@livestore/livestore'import { Schema } from 'effect'
const todoCreated = Events.synced({ name: 'v1.TodoCreated', schema: Schema.Struct({ id: Schema.String, text: Schema.String, }),})
// Use the EventDef as a constructorstore.commit(todoCreated({ id: 'abc', text: 'Buy milk' }))Type Parameters
Section titled “Type Parameters”TName extends string
TType
TEncoded
Section titled “TEncoded”TEncoded = TType
TDerived
Section titled “TDerived”TDerived extends boolean = false
EventDef(
args):object
Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:53
Callable signature - creates a partial event with decoded arguments.
The returned object can be passed directly to store.commit().
Parameters
Section titled “Parameters”TType
Returns
Section titled “Returns”object
args:
TType
name:
TName
Properties
Section titled “Properties”encoded()
Section titled “encoded()”encoded: (
args) =>object
Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:61
Creates a partial event with pre-encoded arguments. Useful when working with already-serialized data.
Parameters
Section titled “Parameters”TEncoded
Returns
Section titled “Returns”object
args:
TEncoded
name:
TName
readonlyEvent:object
Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:66
Type helper for accessing the event’s shape with name and decoded args.
args:
TType
name:
TName
name:
TName
Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:32
Unique identifier for this event type. Conventionally versioned (e.g., v1.TodoCreated).
options
Section titled “options”options:
object
Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:35
clientOnly
Section titled “clientOnly”clientOnly:
boolean
When true, the event is only synced within the same client’s sessions (e.g., across tabs) but never sent to the sync backend. Useful for UI state like selected items or filters.
derived
Section titled “derived”derived:
TDerived
Whether this is a derived event. Derived events cannot have materializers.
facts:
FactsCallback<TType> |undefined
Callback defining fact constraints for this event. This feature is not fully implemented yet.
schema
Section titled “schema”schema:
Schema.Schema<TType,TEncoded>
Defined in: packages/@livestore/common/dist/schema/EventDef/event-def.d.ts:34
Effect Schema used for validating and encoding/decoding event arguments.