Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generic sent event types (sendBack events) to callback-based actors #5143

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
15 changes: 9 additions & 6 deletions packages/core/src/actors/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export type CallbackSnapshot<TInput> = Snapshot<undefined> & {
export type CallbackActorLogic<
TEvent extends EventObject,
TInput = NonReducibleUnknown,
TEmitted extends EventObject = EventObject
TEmitted extends EventObject = EventObject,
TSentEvent extends EventObject = AnyEventObject
> = ActorLogic<
CallbackSnapshot<TInput>,
TEvent,
TInput,
AnyActorSystem,
TEmitted
TEmitted,
TSentEvent
>;

/**
Expand Down Expand Up @@ -183,11 +185,12 @@ export type CallbackLogicFunction<
export function fromCallback<
TEvent extends EventObject,
TInput = NonReducibleUnknown,
TEmitted extends EventObject = EventObject
TEmitted extends EventObject = EventObject,
TSentEvent extends EventObject = EventObject
>(
callback: CallbackLogicFunction<TEvent, AnyEventObject, TInput, TEmitted>
): CallbackActorLogic<TEvent, TInput, TEmitted> {
const logic: CallbackActorLogic<TEvent, TInput, TEmitted> = {
callback: CallbackLogicFunction<TEvent, TSentEvent, TInput, TEmitted>
): CallbackActorLogic<TEvent, TInput, TEmitted, TSentEvent> {
const logic: CallbackActorLogic<TEvent, TInput, TEmitted, TSentEvent> = {
config: callback,
start: (state, actorScope) => {
const { self, system, emit } = actorScope;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,8 @@ export interface ActorLogic<
in out TEvent extends EventObject, // it's invariant because it's also part of `ActorScope["self"]["send"]`
in TInput = NonReducibleUnknown,
TSystem extends AnyActorSystem = AnyActorSystem,
in out TEmitted extends EventObject = EventObject // it's invariant because it's also aprt of `ActorScope["self"]["on"]`
in out TEmitted extends EventObject = EventObject, // it's invariant because it's also aprt of `ActorScope["self"]["on"]`
_TSentEvent extends EventObject = AnyEventObject // currently unused at this level, but used by `CallbackActorLogic`
> {
/** The initial setup/configuration used to create the actor logic. */
config?: unknown;
Expand Down
Loading