01Actors
An actor is the basic unit in Arbor: a function over its saved state and a batch of messages. This one is plain code with no model in it. A person's message arrives as a user_msg, and isMessage picks those out of the batch. The actor counts them in its saved state and answers with ctx.emit. .wake('chat') runs it whenever a person writes. The last line is a bundle(): app names the app, roots lists the actors the app starts with in each session (one conversation with your app), and exposed lists the roots people can talk to. Every example ends with a bundle(...) like this one.
import { actor, bundle, isMessage } from '@arbor/sdk';
// An actor is plain code: a function over its saved state and a batch of messages.
const front = actor('front', { state: { seen: 0 } })
.wake('chat')
.receive((ctx, batch) => {
for (const m of batch) {
if (!isMessage(m, 'user_msg')) continue;
ctx.state.seen += 1;
ctx.emit('reply', { text: `Message ${ctx.state.seen}: ${m.body.text}` });
}
});
export default bundle({ app: 'desk', roots: [front], session: { exposed: [front] } });