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

Upcasting #255

Merged
merged 11 commits into from
Feb 13, 2017
Merged

Upcasting #255

merged 11 commits into from
Feb 13, 2017

Conversation

prolic
Copy link
Member

@prolic prolic commented Feb 7, 2017

resolves #254

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.5%) to 93.031% when pulling 7151f0b on upcasting into 81bffea on develop.

@prolic
Copy link
Member Author

prolic commented Feb 7, 2017

For discussion:

  • We need an instance of a message to create a new message - this means when updating events, you need to create a new class, f.e. UserRegistered => UserRegisterd + UserRegisteredV2 - is that okay?
  • Should we maybe prefer to do upcasting with message name / payload / metadata only? If should remove the message factory from the event store, add our own (maybe GenericMessageFactory) - and use the real MessageFactory only within this plugin - how can this be achieved, if this is preferred?
  • Do we need support for looking into the future of the stream per upcasting? Or can the upcaster itself store some information internally is required?

@coveralls
Copy link

Coverage Status

Coverage decreased (-8.4%) to 91.107% when pulling 8782848 on upcasting into 81bffea on develop.

@mrook
Copy link

mrook commented Feb 7, 2017

That was fast! I'll take an in-depth look as soon as I have time.

As for the discussion points:

  • the new event class needs to exist before the upcaster can work.
  • the question is whether you want each upcaster individually to handle deserializing the raw event (so that would indeed mean only passing metadata & payload), or present the deserialized domain event to the upcaster; I think I prefer the first version, as serialization may have changed over time as well.
  • some upcasters could need this to merge events, they may be more interested in the past than the future however. In general I think this is something best handled in individual upcasters.

@prolic
Copy link
Member Author

prolic commented Feb 8, 2017

@codeliner @mrook tests now included

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 99.572% when pulling d4e89d6 on upcasting into 81bffea on develop.

@jkuchar
Copy link

jkuchar commented Feb 8, 2017

Why not put upcast and downcast methods directly into events? These up/downcast methods are tightly coupled with event in particuar version anyway...

@prolic
Copy link
Member Author

prolic commented Feb 8, 2017

@jkuchar Single Responsibility Principle

@mrook
Copy link

mrook commented Feb 8, 2017

@jkuchar because some upcasters would need information from other events (i.e., if you are merging) or emit multiple events (if you are splitting).

@prolic
Copy link
Member Author

prolic commented Feb 10, 2017

/cc @codeliner

$this->upcasters = $upcasters;
}

public function upcast(Message $message): array
Copy link
Member

Choose a reason for hiding this comment

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

Can you take a second look on the message?

Why is the message turned into a messages array just to foreach over it?

You wanted to return messages, right? But $result is returned.
Foreach can be removed in either case.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. I will fix this later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, you are not right :)

At the first iteration of upcasters, you would have been right, but in the second iteration, I might have an array of messages, that may need further upcasting. see: UpcasterChainTest::it_chains_upcasts

This test would immediately break, if we would make the suggested change.

Copy link
Member

Choose a reason for hiding this comment

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

ok, I see. Just a few lines of code but very tricky ;)

$messages = $this->upcaster->upcast($this->innerIterator->current());

if (empty($messages)) {
$this->next();
Copy link
Member Author

Choose a reason for hiding this comment

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

$this->innerIterator->next();

if (empty($messages)) {
$this->next();

if ($this->valid()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

$this->innerIterator->valid()

@prolic
Copy link
Member Author

prolic commented Feb 11, 2017

There is still a bug in the iterator... I am trying to fix this now.

@prolic
Copy link
Member Author

prolic commented Feb 11, 2017

@codeliner I fixed the upcasting iterator

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 99.577% when pulling a578736 on upcasting into 81bffea on develop.

@prolic
Copy link
Member Author

prolic commented Feb 12, 2017

@mrook @codeliner your thoughts in the implementation?

@mrook
Copy link

mrook commented Feb 13, 2017

@prolic looks fine for the initial implementation!

@codeliner
Copy link
Member

LGTM

@codeliner codeliner merged commit 43f644d into develop Feb 13, 2017
@mrook
Copy link

mrook commented Feb 13, 2017

👍

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.

5 participants