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

Method _initState

packages/core/src/createActor.ts:261–278  ·  view source on GitHub ↗
(persistedState?: Snapshot<unknown>)

Source from the content-addressed store, hash-verified

259 }
260
261 private _initState(persistedState?: Snapshot<unknown>) {
262 try {
263 this._snapshot = persistedState
264 ? this.logic.restoreSnapshot
265 ? this.logic.restoreSnapshot(persistedState, this._actorScope)
266 : persistedState
267 : this.logic.getInitialSnapshot(this._actorScope, this.options?.input);
268 } catch (err) {
269 // if we get here then it means that we assign a value to this._snapshot that is not of the correct type
270 // we can't get the true `TSnapshot & { status: 'error'; }`, it's impossible
271 // so right now this is a lie of sorts
272 this._snapshot = {
273 status: 'error',
274 output: undefined,
275 error: err
276 } as any;
277 }
278 }
279
280 // array of functions to defer
281 private _deferred: Array<() => void> = [];

Callers 1

constructorMethod · 0.95

Calls 2

restoreSnapshotMethod · 0.80
getInitialSnapshotMethod · 0.80

Tested by

no test coverage detected