Create a new StreamModel by providing the initial state.
The initial state of the stream.
Private
eventReadonly
initialSpawns a new stream from this model. This stream can be used to dispatch events and subscribe to changes in the state.
The configuration for the stream.
Adds a new handler for when a specific type of event is dispatched.
The identifier of the event. This must be unique for this event source. For example: 'increment'
The Zod schema to use for the payload of the event. For example z.number().int().min(1).max(5)
The handler that will apply the payload to the state. This method receives the state, the dispatcher, and the payload. You can manipulate the state directly (made possible by Immer) or return a new state object.
Returns a constructor for creating type safe events.
A stream model represents a typesafe state that can be derived from an event log. The projection also support optimistic events, which are events that are applied to the state before the server has confirmed the event was successfully appended to the state.
Note: Keep in mind that the events should be safe to JSON decode and encode. Only use primitives, don't use classes, functions, or other complex types as part of your events.