Tivet Actors have built-in RPC, state, and events — the easiest way to build modern applications.
Usage
Make sure you've installed the Tivet CLI.
# Create project
tivet init
# Deploy actor
tivet deploy
See the setup guide for more information.
Example
import { Actor } from "@tivet-fun/actor";
import type { Rpc } from "@tivet-fun/actor";
// Durable state for the counter (https://tivet.fun/docs/state)
interface State {
count: number;
}
export default class Counter extends Actor<State> {
// Create the initial state when the actor is first created (https://tivet.fun/docs/state)
override _onInitialize(): State {
return { count: 0 };
}
// Listen for state changes (https://tivet.fun/docs/lifecycle)
override _onStateChange(newState: State): void | Promise<void> {
// Broadcast a state update event to all clients (https://tivet.fun/docs/events)
this._broadcast("count", newState.count);
}
// Expose a remote procedure call for clients to update the count (https://tivet.fun/docs/rpc)
increment(_rpc: Rpc<Counter>, count: number): number {
this._state.count += count;
return this._state.count;
}
}