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

Method select

packages/core/src/createActor.ts:490–510  ·  view source on GitHub ↗
(
    selector: (snapshot: SnapshotFrom<TLogic>) => TSelected,
    equalityFn: (a: TSelected, b: TSelected) => boolean = Object.is
  )

Source from the content-addressed store, hash-verified

488 }
489
490 public select<TSelected>(
491 selector: (snapshot: SnapshotFrom<TLogic>) => TSelected,
492 equalityFn: (a: TSelected, b: TSelected) => boolean = Object.is
493 ): Readable<TSelected> {
494 return {
495 subscribe: (observerOrFn) => {
496 const observer = toObserver(observerOrFn);
497 const snapshot = this.getSnapshot();
498 let previousSelected = selector(snapshot);
499
500 return this.subscribe((snapshot) => {
501 const nextSelected = selector(snapshot);
502 if (!equalityFn(previousSelected, nextSelected)) {
503 previousSelected = nextSelected;
504 observer.next?.(nextSelected);
505 }
506 });
507 },
508 get: () => selector(this.getSnapshot())
509 };
510 }
511
512 /** Starts the Actor from the initial state */
513 public start(): this {

Callers

nothing calls this directly

Calls 6

getSnapshotMethod · 0.95
subscribeMethod · 0.95
toObserverFunction · 0.90
nextMethod · 0.80
selectorFunction · 0.50
equalityFnFunction · 0.50

Tested by

no test coverage detected