MCPcopy
hub / github.com/statelyai/xstate / fromTransition

Function fromTransition

packages/core/src/actors/transition.ts:167–216  ·  view source on GitHub ↗
(
  transition: (
    snapshot: TContext,
    event: TEvent,
    actorScope: ActorScope<
      TransitionSnapshot<TContext>,
      TEvent,
      TSystem,
      TEmitted
    >
  ) => TContext,
  initialContext:
    | TContext
    | (({
        input,
        self
      }: {
        input: TInput;
        self: TransitionActorRef<TContext, TEvent>;
      }) => TContext) // TODO: type
)

Source from the content-addressed store, hash-verified

165 * @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
166 */
167export function fromTransition<
168 TContext,
169 TEvent extends EventObject,
170 TSystem extends AnyActorSystem,
171 TInput extends NonReducibleUnknown,
172 TEmitted extends EventObject = EventObject
173>(
174 transition: (
175 snapshot: TContext,
176 event: TEvent,
177 actorScope: ActorScope<
178 TransitionSnapshot<TContext>,
179 TEvent,
180 TSystem,
181 TEmitted
182 >
183 ) => TContext,
184 initialContext:
185 | TContext
186 | (({
187 input,
188 self
189 }: {
190 input: TInput;
191 self: TransitionActorRef<TContext, TEvent>;
192 }) => TContext) // TODO: type
193): TransitionActorLogic<TContext, TEvent, TInput, TEmitted> {
194 return {
195 config: transition,
196 transition: (snapshot, event, actorScope) => {
197 return {
198 ...snapshot,
199 context: transition(snapshot.context, event, actorScope as any)
200 };
201 },
202 getInitialSnapshot: (_, input) => {
203 return {
204 status: 'active',
205 output: undefined,
206 error: undefined,
207 context:
208 typeof initialContext === 'function'
209 ? (initialContext as any)({ input })
210 : initialContext
211 };
212 },
213 getPersistedSnapshot: (snapshot) => snapshot,
214 restoreSnapshot: (snapshot: any) => snapshot
215 };
216}

Callers 15

input.test.tsFile · 0.90
transition.test.tsFile · 0.90
actor.test.tsFile · 0.90
actorLogic.test.tsFile · 0.90
system.test.tsFile · 0.90
emit.test.tsFile · 0.90
issue5454.test.tsFile · 0.90
invoke.test.tsFile · 0.90
errors.test.tsFile · 0.90
index.tsFile · 0.90

Calls 1

transitionFunction · 0.50

Tested by 5

createCustomActorFunction · 0.68
createCustomLogicFunction · 0.68
AppFunction · 0.68
TestFunction · 0.68
createSimpleActorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…