use FactRef objects to sanify action handling
[scpubgit/DKit.git] / lib / DX / Op / ProposeAction.pm
index 7031b4f..2249496 100644 (file)
@@ -19,11 +19,16 @@ 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 })
+  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);
 }