core: use immutable event results #29
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently mutable events are implemented via subclasses of
EventScopewhich need to useEventScopePropertyin order to make mutation impossible without access to aMutableEventScope.This PR explores a different solution using immutable objects instead. To make this possible event listeners now only have access to an
EventScope<E, R>in their context, which has been repurposed to hold both the event instance of typeEand the event result of typeR. Non-mutating listeners are registered vialistenlike before, while mutating listeners need to uselistenMut. An example usage could be:As seen above, the included
Cancellabletype was changed to a sealed interface with two subclasses,ActiveandCancelled, instead of having a mutable boolean property to indicate cancellation.I have also changed the generic parameter
Tfor the type of event instance toEso it better reflects the meaning together withR, and have made immutable events useUnitas their result type which is now possible without a bound on the result type.TODO:
Note that all names are bikesheddable and I have not yet adjusted the documentation comments because that this is only a draft and I wanted to get some general opinions first.