Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow aggregate state to be an object #45

Merged
merged 1 commit into from
Oct 2, 2017
Merged

Conversation

prolic
Copy link
Member

@prolic prolic commented Oct 1, 2017

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.9%) to 93.023% when pulling e5887f8 on aggregate_state into 6e8b868 on master.

@@ -45,8 +45,12 @@ function changeUserName(callable $stateResolver, ChangeUserName $command): array

const apply = '\Prooph\MicroExample\Model\User\apply';

function apply(array $state, Message ...$events): array
function apply($state, Message ...$events): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function requires $state to be an array or null and would raise an exception otherwise.
So I think ?array $state is the better type hint here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_merge would not work with an object. Also if $events is an empty array, $state would be returned untouched. The return type hint is array and could therefore not be an object without raising an exception.

@prolic
Copy link
Member Author

prolic commented Oct 2, 2017 via email

@prolic
Copy link
Member Author

prolic commented Oct 2, 2017 via email

@prolic
Copy link
Member Author

prolic commented Oct 2, 2017

@codeliner can you please check this PR?

@codeliner
Copy link
Member

LGTM

A state object is mutable unless implemented as an immutable object, whereby PHP arrays are semi-immutable because they are not passed by reference.And we lost the type hints (or turned them into type checks performed by prooph micro) for state. BUT passing objects around is faster than passing arrays and state objects are more user and IDE friendly, so +1 for the change.

@prolic Did you get the idea from aggregates in Haskell article? ;)
Should we also determine new aggregate state version based on new recorded events?
ATM we require the developer to set new version: https://github.com/prooph/micro/blob/master/examples/Model/User.php#L32
I'd like to get rid of it if possible.

@prolic
Copy link
Member Author

prolic commented Oct 2, 2017 via email

@codeliner
Copy link
Member

yeah, count events should work. I'll create a separate issue.

@codeliner codeliner merged commit db15268 into master Oct 2, 2017
@codeliner codeliner deleted the aggregate_state branch October 2, 2017 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants