Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { actor } from "rivetkit";

export const onStateChangeActor = actor({
onAuth: () => {},
state: {
value: 0,
changeCount: 0,
},
actions: {
// Action that modifies state - should trigger onStateChange
setValue: (c, newValue: number) => {
c.state.value = newValue;
return c.state.value;
},
// Action that modifies state multiple times - should trigger onStateChange for each change
incrementMultiple: (c, times: number) => {
for (let i = 0; i < times; i++) {
c.state.value++;
}
return c.state.value;
},
// Action that doesn't modify state - should NOT trigger onStateChange
getValue: (c) => {
return c.state.value;
},
// Action that reads and returns without modifying - should NOT trigger onStateChange
getDoubled: (c) => {
const doubled = c.state.value * 2;
return doubled;
},
// Get the count of how many times onStateChange was called
getChangeCount: (c) => {
return c.state.changeCount;
},
// Reset change counter for testing
resetChangeCount: (c) => {
c.state.changeCount = 0;
},
},
// Track onStateChange calls
onStateChange: (c) => {
c.state.changeCount++;
},
});
Loading
Loading