-
Notifications
You must be signed in to change notification settings - Fork 401
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
Use map syntax to clean up null
handling in toJson
functions
#1443
Conversation
Inspired by dart-lang/sdk@6c92bab Thanks @parlough !! |
'Inigo', | ||
'Montoya', | ||
DateTime(1560, 5, 5), | ||
middleName: 'Bob', |
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.
Added `middleName since it's nullable – to exercise behavior here!
return val; | ||
} | ||
Map<String, dynamic> _$OrderToJson(Order instance) => <String, dynamic>{ | ||
if (instance.count case final val?) 'count': val, |
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.
On the flip-side (I can't comment there), it would be great for final code size to have a library of helpers for common patterns like
..count = (json['count'] as num?)?.toInt()
-->
..count = helper$.nullableInt(json, 'count')
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.
How could we measure the delta here? I'm game, but I'd like to see numbers...
I wonder what the lint is here, too. If this is such a big win...how can we codify it more?
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.
If we land parts-with-imports this gets easy enough to just do it without worrying about the specific delta.
https://github.com/dart-lang/language/blob/main/working/augmentation-libraries/parts_with_imports.md
IMO it's not worth spending much time one before then.
No description provided.