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

Method on

packages/core/src/createActor.ts:468–488  ·  view source on GitHub ↗
(
    type: TType,
    handler: (
      emitted: EmittedFrom<TLogic> &
        (TType extends '*' ? unknown : { type: TType })
    ) => void
  )

Source from the content-addressed store, hash-verified

466 }
467
468 public on<TType extends EmittedFrom<TLogic>['type'] | '*'>(
469 type: TType,
470 handler: (
471 emitted: EmittedFrom<TLogic> &
472 (TType extends '*' ? unknown : { type: TType })
473 ) => void
474 ): Subscription {
475 let listeners = this.eventListeners.get(type);
476 if (!listeners) {
477 listeners = new Set();
478 this.eventListeners.set(type, listeners);
479 }
480 const wrappedHandler = handler.bind(undefined);
481 listeners.add(wrappedHandler);
482
483 return {
484 unsubscribe: () => {
485 listeners.delete(wrappedHandler);
486 }
487 };
488 }
489
490 public select<TSelected>(
491 selector: (snapshot: SnapshotFrom<TLogic>) => TSelected,

Callers 15

ComponentFunction · 0.45
types.test.tsxFile · 0.45
validate.test.tsFile · 0.45
fromStore.test.tsFile · 0.45
store.test.tsFile · 0.45
undo.test.tsFile · 0.45
types.test.tsFile · 0.45
emit.test.tsFile · 0.45
errors.test.tsFile · 0.45
ComponentFunction · 0.45
ComponentFunction · 0.45
inspectFunction · 0.45

Calls 2

getMethod · 0.80
setMethod · 0.65

Tested by 5

ComponentFunction · 0.36
ComponentFunction · 0.36
ComponentFunction · 0.36
ComponentFunction · 0.36
ComponentFunction · 0.36