Skip to main content

Defining Initial Status

Each Retomus machine starts in an initial status, which you can define as a fixed string or a function that dynamically determines the starting point.


๐Ÿ”ง Static Initial Statusโ€‹

The simplest form is a string value:

initialStatus: {
status: 'idle',
options: { staticSetup: true },
}

๐Ÿค– Dynamic Initial Statusโ€‹

Use a function to determine the starting status based on context:

initialStatus: {
status: (ctx) => {
return ctx.state.count > 0 ? 'incrementing' : 'idle';
},
options: { dynamicSetup: true },
}

This is useful for restoring persisted state or initializing based on runtime conditions.


๐Ÿงช Available Optionsโ€‹

OptionDescription
staticSetupUse a static string (default)
dynamicSetupEvaluate function at runtime

You can combine both:

initialStatus: {
status: (ctx) => 'idle',
options: {
staticSetup: true,
dynamicSetup: true,
},
}

โš ๏ธ Gotchasโ€‹

  • If both staticSetup and dynamicSetup are true, dynamic logic takes precedence
  • Always return a valid status from dynamic functions

๐Ÿ”— Config Placementโ€‹

initialStatus is passed as part of your machine config:

createMachineConfig({
...
initialStatus: { ... }
});