statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
26.98k stars 1.24k forks source link

[core] Propagate `clock` and `logger` from system #4822

Closed davidkpiano closed 5 months ago

davidkpiano commented 6 months ago

The clock and logger specified in the options object of createActor(logic, options) will now propagate to all actors created within the same actor system.

import { setup, log, createActor } from 'xstate';

const childMachine = setup({
  // ...
}).createMachine({
  // ...
  // Uses custom logger from root actor
  entry: log('something')
});

const parentMachine = setup({
  // ...
}).createMachine({
  // ...
  invoke: {
    src: childMachine
  }
});

const actor = createActor(parentMachine, {
  logger: (...args) => {
    // custom logger for args
  }
});

actor.start();
changeset-bot[bot] commented 6 months ago

🦋 Changeset detected

Latest commit: 63446e9de33dc1e8efc829537e621840ed30e2da

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------ | ----- | | xstate | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

codesandbox-ci[bot] commented 6 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.