-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: add VersionedMessage.deserializeMessageVersion utility function #27415
Conversation
Codecov Report
@@ Coverage Diff @@
## master #27415 +/- ##
========================================
Coverage 76.9% 76.9%
========================================
Files 48 51 +3
Lines 2505 2660 +155
Branches 355 364 +9
========================================
+ Hits 1927 2048 +121
- Misses 448 481 +33
- Partials 130 131 +1 |
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.
@@ -5,17 +5,26 @@ import {MessageV0} from './v0'; | |||
export type VersionedMessage = Message | MessageV0; | |||
// eslint-disable-next-line no-redeclare | |||
export const VersionedMessage = { |
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 haven't checked how tree-shakers treat this. If I do:
import {VersionedMessage} from 'src/message/versioned';
// ...but then only use one function
if (VersionedMessage.deserializeMessageVersion(message) === 'legacy') {
/* ... */
}
…does the compiler shake out the other methods I haven't used?
I know it definitely works if you export each function.
export function deserializeMessageVersion(...) { ... }
…then
import {deserializeMessageVersion} from 'src/message/versioned';
if (deserializeMessageVersion(message) === 'legacy') {
/* ... */
}
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.
Oh good question, I'd like to punt on this for now and would happily accept / implement a change that's more tree-shaker friendly if it's an issue
Problem
Lack of utility function to check the version of a serialized message without fully deserializing the message
Summary of Changes
VersionedMessage.deserializeMessageVersion
Fixes #