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

Method resolveState

packages/core/src/StateMachine.ts:223–272  ·  view source on GitHub ↗
(
    config: {
      value: StateValue;
      context?: TContext;
      historyValue?: HistoryValue<TContext, TEvent>;
      status?: SnapshotStatus;
      output?: TOutput;
      error?: unknown;
    } & (Equals<TContext, MachineContext> extends false
      ? { context: unknown }
      : {})
  )

Source from the content-addressed store, hash-verified

221 }
222
223 public resolveState(
224 config: {
225 value: StateValue;
226 context?: TContext;
227 historyValue?: HistoryValue<TContext, TEvent>;
228 status?: SnapshotStatus;
229 output?: TOutput;
230 error?: unknown;
231 } & (Equals<TContext, MachineContext> extends false
232 ? { context: unknown }
233 : {})
234 ): MachineSnapshot<
235 TContext,
236 TEvent,
237 TChildren,
238 TStateValue,
239 TTag,
240 TOutput,
241 TMeta,
242 TStateSchema
243 > {
244 const resolvedStateValue = resolveStateValue(this.root, config.value);
245 const nodeSet = getAllStateNodes(
246 getStateNodes(this.root, resolvedStateValue)
247 );
248
249 return createMachineSnapshot(
250 {
251 _nodes: [...nodeSet],
252 context: config.context || ({} as TContext),
253 children: {},
254 status: isInFinalState(nodeSet, this.root)
255 ? 'done'
256 : config.status || 'active',
257 output: config.output,
258 error: config.error,
259 historyValue: config.historyValue
260 },
261 this
262 ) as MachineSnapshot<
263 TContext,
264 TEvent,
265 TChildren,
266 TStateValue,
267 TTag,
268 TOutput,
269 TMeta,
270 TStateSchema
271 >;
272 }
273
274 /**
275 * Determines the next snapshot given the current `snapshot` and received

Callers 10

postEventFunction · 0.80
meta.test.tsFile · 0.80
microstep.test.tsFile · 0.80
machine.test.tsFile · 0.80
invalid.test.tsFile · 0.80
graph.test.tsFile · 0.80

Calls 5

resolveStateValueFunction · 0.90
getAllStateNodesFunction · 0.90
getStateNodesFunction · 0.90
createMachineSnapshotFunction · 0.90
isInFinalStateFunction · 0.90

Tested by 1

postEventFunction · 0.64