⚓
Tivet Docs
  • Overview
  • Getting started
    • Initial Setup
    • Actor SDK
  • build with actors
    • Create & Manage Actors
    • Remote Procedure Calls
    • State
    • Events
    • Lifecycle
  • Resources
    • Configuration
    • Troubleshooting
    • FAQ
    • Service Tokens
  • Socials
Powered by GitBook
On this page
  • Usage
  • Example
  1. Getting started

Actor SDK

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;
	}
}
PreviousInitial SetupNextCreate & Manage Actors

Last updated 3 months ago