Readonly
stop$Stream of stop events (might be useful to know when the actor stops)
Protected
messages$Actor message stream, allows to define actor behavior see example
Protected
answerSubscribes to an observable of events when there is an emission will send the event to a recipient (actor reference) when specified and to itself when not. completes when stop message is send to the actor.
import { Actor, createEvent } from 'reactive-actor';
export const getUsers = createEvent('[Users] Get Users');
export const getUsersSuccess = createEvent<GitHubUser[]>( '[Users] Get Users Success' );
export const getUsersFail = createEvent
export type UsersActorEvents = ReturnType
export class UsersActor extends Actor
// Recipient is not define thus will send the resulting event to itself
private readonly getUsers$ = this.messages$.pipe(
ofType(getUsers),
exhaustMap(() =>
ajax<GitHubUser[]>(https://api.github.com/users?per_page=5
).pipe(
map(({ response }) => getUsersSuccess(response)),
catchError((err) => of(getUsersFail(err)))
)
)
);
// Recipient is define thus will send event (getUsersFail) to specified recipient (logger) private readonly getUsersFail$ = this.messages$.pipe( ofType(getUsersFail), addRecipient(this.logger) );
constructor() { super('users'); this.answer(this.getUsers$, this.getUsersFail$); } }
Rest
...messages: Observable<Event<any> & AnswerConfig<Event<any>>>[]an observable of messages
Generated using TypeDoc
Reference: https://www.youtube.com/watch?v=7erJ1DV_Tlo&ab_channel=jasonofthel33t
Actor: Fundamental unit of computation Actor needs to embody
"One ant is no ant" - "One human is no human" - "One actor is no actor" Actors live within systems
Fundamental Properties: