--- /dev/null
+package DX::Action::AddValue;
+
+use DX::Update::AddValue;
+use DX::Class;
+
+with 'DX::Role::SimpleAction';
+
+has new_value => (is => 'ro', required => 1);
+
+sub _build__updates {
+ my ($self) = @_;
+ DX::Update::AddValue->new(
+ target_path => $self->target_path,
+ new_value => $self->new_value,
+ );
+}
+
+1;
use DX::Update::SetValue;
use DX::Class;
-has target_path => (is => 'ro', required => 1);
+with 'DX::Role::SimpleAction';
has new_value => (is => 'ro', required => 1);
-has _update => (is => 'lazy');
-
-sub dry_run {
- my ($self, $hyp) = @_;
- my ($scope, @events) = $self->_update->apply_to($hyp->scope);
- return (
- $hyp->but(
- actions => [ @{$hyp->actions}, $self ],
- scope => $scope
- ),
- @events,
- );
-}
-
-sub _build__update {
+sub _build__updates {
my ($self) = @_;
DX::Update::SetValue->new(
target_path => $self->target_path,
package DX::ActionBuilder::Normal;
+use DX::Action::SetValue;
+use DX::Action::AddValue;
use DX::Class;
with 'DX::Role::ActionBuilder';
);
}
+sub action_for_add_member {
+ my ($self, $at, $value) = @_;
+ my @add_path = (@{$self->target_path}, ref($at) ? $at->string_value : $at);
+ DX::Action::AddValue->new(
+ target_path => \@add_path,
+ new_value => $value->but_set_action_builder(
+ $self->but(target_path => \@add_path)
+ )
+ );
+}
+
+sub action_for_remove_member { die 'WHUT' }
+
1;
);
DX::Action::SetValue->new(
target_path => $self->target_path,
- new_value => $value->but_set_action_builder($ab),
+ new_value => $value->but_set_action_builder($ab)
+ ->but_set_identity_path($self->target_path),
);
}
sub _expand_deps {
my ($self, $deps) = @_;
my @exp;
- DEP: foreach my $dep (@$deps) {
+ DEP: foreach my $dep (map @{$_}[1..$#$_], @$deps) {
my ($type, @path) = @$dep;
push @exp, [
$type,
unless $arg->isa('DX::Value::Dict');
return step(
actions => [],
- depends_on => [ [ TYPE_OF ,=> $arg ] ]
+ depends_on => [ [ undef ,=> [ TYPE_OF ,=> $arg ] ] ]
);
}
my $set = $arg->action_for_set_value(dict());
return step(
actions => [ $set ],
- depends_on => [ [ TYPE_OF ,=> $arg ] ]
+ depends_on => [ [ undef ,=> [ TYPE_OF ,=> $arg ] ] ]
);
}
package DX::Predicate::MemberAt;
-use DX::Utils qw(step INDICES_OF EXISTENCE_OF);
+use DX::Utils qw(step INDICES_OF EXISTENCE_OF CONTENTS_OF);
use DX::Class;
with 'DX::Role::Predicate';
return (
($key->is_set
? map $_->but_with_dependencies_on(
- [ undef ,=> [ $coll, EXISTENCE_OF ,=> $key ], $key ]
+ [ undef ,=>
+ [ EXISTENCE_OF ,=> $coll, $key->string_value ],
+ [ CONTENTS_OF ,=> $key ],
+ ]
), do {
if (my $cur_val = $coll->get_member_at($key)) {
$self->_make_equal($cur_val, $value);
} elsif (
$value->is_set
- and my $add = $coll->action_for_add_value($key, $value)
+ and my $add = $coll->action_for_add_member($key, $value)
) {
step(
actions => [ $add ],
depends_on => [
- [ $coll => [ $coll, $key ], $value ]
+ [ $value =>
+ [ CONTENTS_OF ,=> $coll, $key->string_value ],
+ [ CONTENTS_OF ,=> $value ],
+ ],
],
);
} else {
my $set_key = $key->action_for_set_value($_);
map $_->but_first($set_key)
->but_with_dependencies_on(
- [ undef ,=> [ $coll, EXISTENCE_OF ,=> $key ] ]
+ [ undef ,=>
+ [ EXISTENCE_OF ,=> $coll, $key->string_value ]
+ ]
),
$self->_make_equal($coll->get_member_at($_), $value);
} $coll->index_list
sub selection_depends_on {
my ($self, $coll, $key, $value) = @_;
+ die "NEEDS REDOING";
[ [ $coll => ($key->can_set_value ? INDICES_OF : (EXISTENCE_OF ,=> $key)) ],
$key,
$value,
if ($left->is_set and my $set = $right->action_for_set_value($left)) {
step(
actions => [ $set ],
- depends_on => [ [ $right => [ $left, $right ] ] ],
+ depends_on => [
+ [ $right =>
+ [ $left ], [ $right ]
+ ]
+ ]
)
} else {
()
if ($right->is_set and my $set = $left->action_for_set_value($right)) {
step(
actions => [ $set ],
- depends_on => [ [ $left => [ $left, $right ] ] ],
+ depends_on => [
+ [ $left =>
+ [ $left ], [ $right ]
+ ]
+ ]
)
} else {
()
use DX::Role;
-has updates => (is => 'lazy');
+has target_path => (is => 'ro', required => 1);
-requires '_build_updates';
+has _updates => (is => 'lazy');
-sub dry_run_against {
+requires '_build__updates';
+
+sub dry_run {
my ($self, $hyp) = @_;
- my ($scope, @events) = $hyp->scope->apply_updates($self->updates);
+ my ($scope, @events) = $hyp->scope->apply_updates($self->_updates);
return (
$hyp->but(
scope => $scope,
$self->but(action_builder => $ab);
}
+sub but_set_identity_path {
+ my ($self, $path) = @_;
+ $self->but(identity_path => $path);
+}
+
1;
);
}
+sub apply_updates {
+ my ($self, @updates) = @_;
+ my @events;
+ my $scope = $self;
+ ($scope, @events) = ($_->apply_to($scope), @events) for @updates;
+ return ($scope, @events);
+}
+
1;
has alternative_step => (is => 'ro');
+sub but_with_dependencies_on {
+ my ($self, @deps) = @_;
+ $self->but(depends_on => [ @{$self->depends_on}, @deps ]);
+}
+
sub but_with_alternative_step {
my ($self, $step) = @_;
bless { %$self, alternative_step => $step }, ref($self);
has new_value => (is => 'ro', required => 1);
sub apply_to {
- my ($self, $scope) = @-;
+ my ($self, $scope) = @_;
my @path = my @whole_path = @{$self->target_path};
my $target = pop @path;
my $new_value = $self->new_value;
has '+action_builder' => (
handles => [ qw(
can_set_value action_for_set_value
- action_for_add_member action_for_set_member action_for_remove_member
+ action_for_add_member action_for_remove_member
) ]
);
-Action::AddValue
- RemoveValue
+Action::RemoveValue
BindValue
SetBoundValue
AddBoundValue
resolved_propositions => use_module('DX::ResolvedPropositionSet')->new_empty,
outstanding_propositions => [
proposition(is_dict => 'X'),
+ proposition(member_at => 'X', string('a'), string('b')),
],
actions => [],
);
alternatives => [],
);
-::Dwarn($ss->with_one_step);
+::Dwarn($ss->with_one_step->with_one_step);