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

Duck typing of events and commands #34

Merged
merged 2 commits into from
Nov 1, 2022
Merged

Duck typing of events and commands #34

merged 2 commits into from
Nov 1, 2022

Conversation

kzu
Copy link
Member

@kzu kzu commented Nov 1, 2022

Basic support including:

  • Plain records for events and commands
  • No return type conversion for commands
  • No deep hierarchy clone, just first-level primitive properties/ctor args
  • Custom conversion supported for advanced scenarios

@kzu kzu enabled auto-merge (rebase) November 1, 2022 07:05
A new records-based generator emits an __[Type]Factory that can convert from dynamic to the target record type.

Observe now adds another Subject that can convert, and we register this subject as compatible whenever the target type doesn't equal the given event. We optimize this scenario by caching these new compatible subjects like we did before. If no converter is available, the event type will just never be invoked in this "duck typing" manner.

We offer two conversion mechanisms: the generated factory, and an explicitly declared `Create(dynamic)` method on the record type. This can allow more complex scenarios to still work even if we don't generate code for them.

Closes #31
We do not perform conversion on return types (yet).

Closes #33
@kzu kzu merged commit 7198202 into main Nov 1, 2022
@kzu kzu deleted the feature/ducktyping branch November 1, 2022 15:24
@kzu kzu added the enhancement New feature or request label Jan 29, 2024
@devlooped devlooped locked and limited conversation to collaborators Nov 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant