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.
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
Serializing/deserializing methods for
Event
instances #251Serializing/deserializing methods for
Event
instances #251Changes from 11 commits
44f9bcc
ce19f12
9a55df9
1846d97
65c353d
03dcdbe
7a7511e
9d2bd10
886b253
9df20b3
f16b37a
9602053
2d58a3d
760d9b7
3977ae8
d71b224
bd2fae1
7fd9071
8cacb0b
1a85335
b412b59
e1d45d5
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
instead of creating our own, can we use something from package:collection? like
DeepCollectionEquality
?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.
Good idea, this commit has it updated to use
DeepCollectionEquality.equals
to compare instead@christopherfujino, i know we discussed trimming down dependencies for this package, do you think this is a valid reason to add another dep?
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.
Following up on offline discussions with @christopherfujino, going to remove the dep on collection and use the same function for comparing two separate maps to reduce dependencies for this package
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 think you can simplify this using pattern matching:
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 nice, this is a clever, had to catch up on Craigs pattern matching video to understand the syntax but it looks like this use case is highlighted pretty much exactly!
https://www.youtube.com/watch?v=aLvlqD4QS7Y&ab_channel=Flutter
Thank you for the suggestion! :)
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.
(Still digging through if this is possible) but i was able to simplify by adding a
when
clause to thecase
as the belowBut it seems like i would have to make a call to
DashEvent.getDashEventByLabel
twice, do you know if its possible to assign this variable AND have it get checked within thewhen
clause?If it's not possible, i'll probably remove the
when
clause and leave the check within the body of theif
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.
drive by comment--at least with this particular code, I think the solution is to pull
DashEvent.getDashEventByLabel(eventName)
into a local variable before the if statement.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 wouldn't have access to that variable above the if statement though because it gets assigned in the
if-case
statement.. unless we don't check if it is a string firstThere 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.
ahh yeah, I see what you mean. carry on :)
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.
Ah yeah I'm now sure if
DashEvent.getDashEventByLabel(eventName)
can be stored in a variable. Maybe @munificent knows?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.
There isn't always a great way to interleave a series of pattern matches and guards so that you can incrementally bind stuff after a guard passes. In this case, you could do:
Whether you like seeing nested if-case statements like this is a matter of taste. :)
If you wanted to really jam everything into a pattern, you could make
DashEvent.getDashEventByLabel
an extension on String:You can call extension getters in object patterns, so that would let you do:
Then the pattern will only match if the map's
'eventName'
key is mapped to a string where callingdashEventForLabel
on it returns a non-null value. When that happens, the value is bound toevent
.But this feels to me like twisting the language out of shape and I wouldn't do it (though it is kind of cool that you can).
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.
We've discussed making
case
an expression instead of directly built into the if-case statement. If we did that, then you could probably chain them using&&
like:But that's not in the language now and it's not clear if it's a good idea. It raises lots of tricky questions around the scope of the pattern variables.
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.
@munificent yeah looks like your example in the second comment would be ideal but i can see how it get tricky.. i went with just having a separate conditional within the body of the
if-case
so it's easy to understand, thank you for the thorough comment!