-
Notifications
You must be signed in to change notification settings - Fork 200
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
fix: clone record before emitting event #833
fix: clone record before emitting event #833
Conversation
Signed-off-by: Timo Glastra <timo@animo.id>
Codecov Report
@@ Coverage Diff @@
## main #833 +/- ##
==========================================
+ Coverage 87.71% 87.76% +0.05%
==========================================
Files 439 439
Lines 10830 10854 +24
Branches 1837 1837
==========================================
+ Hits 9499 9526 +27
+ Misses 1269 1267 -2
+ Partials 62 61 -1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the addition of adding the emitStateChangedEvent
and cloning/copying, but would it not make more sense to implement clone on the BaseRecord
class? This way, we would avoid calling const clonedRecord = record.clone()
.
I also think that this will be forgotten in the future and cause problems again. I am sure of a solution but it might be nice to revisit this later on.
this.emitStateChangedEvent(connectionRecord, previousState) | ||
} | ||
|
||
private emitStateChangedEvent(connectionRecord: ConnectionRecord, previousState: DidExchangeState | null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not
private emitStateChangedEvent(connectionRecord: ConnectionRecord, previousState: DidExchangeState | null) { | |
private emitStateChangedEvent(connectionRecord: ConnectionRecord, previousState?: DidExchangeState) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Events are emitted with previousState value null (which has a different meaning than undefined). If we change this now it would be a breaking change to events (because previousState
will now be undefined)
How could we avoid calling record.clone? I like the idea of adding a clone to the base record, but instead of calling |
Yeah record.clone(). Maybe clone adds a property |
I'm not 100% following you. Where would we add the clone property to? Could you give an example of how this would work? I'm going to merge this now to unblock me in the AATH work, but happy to make a follow up PR |
Yeah my apologies, not the best explanantion. I want to enforce calling This is for sure not the best solution and just an idea. Ignore this if its still too vague :). |
Clone records before emitting them in events to avoid mutation later on.
Fixes #832