move actions to a separate state attribute
[scpubgit/DKit.git] / lib / DX / Op / ProposeAction.pm
index 7031b4f..e63eb40 100644 (file)
@@ -19,12 +19,14 @@ sub run {
   ($state, my %args) = $self->_expand_args($state, %{$self->_arg_map});
   my @vars = @args{sort keys %args};
   my @deps = $state->action_dependencies(map $_->id, @vars);
-  my $action = $self->builder->(@vars)
+  my $action = $self->builder->(map $state->resolve_value($_), @vars)
                     ->but(dependencies => \@deps);
-  my ($id, $value) = $action->expected_effect;
-  my $var = $state->by_id->{$id}->with_value($value)->with_action($action);
-  $state->but(by_id => { %{$state->by_id}, $id => $var })
-        ->then($self->next);
+  my ($rec_state, $action_id) = $state->record_action($action);
+  my ($fact_type, $value) = $action->expected_effect;
+  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;