Skip to content

Commit

Permalink
feat: Add shouldPersist property to MachineDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
YunusEmreNalbant committed Jan 22, 2024
1 parent a38e519 commit aa807d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Actor/Machine.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ public function start(State|string|null $state = null): self
*/
public function send(
EventBehavior|array|string $event,
bool $shouldPersist = true,
): State {
if ($this->state !== null) {
$lock = Cache::lock('mre:'.$this->state->history->first()->root_event_id, 60);
Expand All @@ -187,7 +186,7 @@ public function send(
default => $this->definition->transition($event, $this->state)
};

if ($shouldPersist === true) {
if ($this->definition->shouldPersist) {
$this->persist();
}

Expand Down
5 changes: 5 additions & 0 deletions src/Definition/MachineDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class MachineDefinition
/** Indicates whether the scenario is enabled. */
public bool $scenariosEnabled = false;

/** machine-based variable that determines whether to persist the state change. */
public bool $shouldPersist = true;

// endregion

// region Constructor
Expand All @@ -83,6 +86,8 @@ private function __construct(
) {
$this->scenariosEnabled = isset($this->config['scenarios_enabled']) && $this->config['scenarios_enabled'] === true;

$this->shouldPersist = $this->config['should_persist'] ?? $this->shouldPersist;

$this->root = $this->createRootStateDefinition($config);

// Checks if the scenario is enabled, and if true, creates scenario state definitions.
Expand Down

0 comments on commit aa807d4

Please sign in to comment.