move actions to a separate state attribute
[scpubgit/DKit.git] / lib / DX / Op / ProposeAction.pm
index 2249496..e63eb40 100644 (file)
@@ -21,15 +21,12 @@ sub run {
   my @deps = $state->action_dependencies(map $_->id, @vars);
   my $action = $self->builder->(map $state->resolve_value($_), @vars)
                     ->but(dependencies => \@deps);
+  my ($rec_state, $action_id) = $state->record_action($action);
   my ($fact_type, $value) = $action->expected_effect;
-  my $id = $vars[0]->id;
-  my $var = $state->by_id->{$id}->with_action($action);
-  my $fact_set = $state->facts->{$fact_type}->with_value($value);
-  $state->but(
-            by_id => { %{$state->by_id}, $id => $var },
-            facts => { %{$state->facts}, $fact_type => $fact_set },
-          )
-        ->then($self->next);
+  my $final_value = $value->but(required_action => $action_id);
+  my $fact_set = $state->facts->{$fact_type}->with_value($final_value);
+  $rec_state->but(facts => { %{$state->facts}, $fact_type => $fact_set })
+            ->then($self->next);
 }
 
 1;