-
Notifications
You must be signed in to change notification settings - Fork 308
model [nfc]: Remove StreamColorSwatch; just use ColorSwatch<StreamColorVariant> #642
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
Conversation
We'll soon make this enum public, for consuming code to use directly to get individual colors from the swatch. Move the dartdocs now, to simplify the diff in that upcoming change.
…iant> This indirection was mildly helpful; it let us consume these colors with slightly more concise code, and without needing `!` to satisfy the analyzer. But we get the same correct functionality without the indirection, and a bit more transparently. The more substantive benefit of using ColorSwatch directly is that we now have a ready-made lerp function -- `ColorSwatch.lerp` -- that can operate on our swatch instances. That should be helpful later when we want stream colors to animate smoothly when dark mode is toggled, along with various other style attributes that will naturally animate too.
The old name seems longer than it needs to be.
3b658bd
to
689ac37
Compare
Hmm, it does feel like the code that's using this class generally all gets worse this way. For the lerp, how about we just copy that method's implementation? It doesn't seem like it's doing anything all that complicated. In order to have the map lying around, we could save it on our own private field in addition to passing it to the superclass. The redundancy is mildly annoying, but it's only duplicating one pointer, so it's not a material cost at runtime. |
Sure, makes sense. Since that approach will be pretty different from what's in this PR, I'll close this PR and open a new one. -> #654 |
It's convenient in this method to access the colors as they're stored in a Map, like the superclass ColorSwatch does. So, in our own private field, we save the same Map that we pass along to the superclass constructor. As Greg says at zulip#642 (comment) : > The redundancy is mildly annoying, but it's only duplicating one > pointer, so it's not a material cost at runtime.
It's convenient in this method to access the colors as they're stored in a Map, like the superclass ColorSwatch does. So, in our own private field, we save the same Map that we pass along to the superclass constructor. As Greg says at zulip#642 (comment) : > The redundancy is mildly annoying, but it's only duplicating one > pointer, so it's not a material cost at runtime.
It's convenient in this method to access the colors as they're stored in a Map, like the superclass ColorSwatch does. So, in our own private field, we save the same Map that we pass along to the superclass constructor. As Greg says at zulip#642 (comment) : > The redundancy is mildly annoying, but it's only duplicating one > pointer, so it's not a material cost at runtime.
This indirection was mildly helpful; it let us consume these colors
with slightly more concise code, and without needing
!
to satisfythe analyzer.
But we get the same correct functionality without the indirection,
and a bit more transparently. The more substantive benefit of using
ColorSwatch directly is that we now have a ready-made lerp function
--
ColorSwatch.lerp
-- that can operate on our swatch instances.That should be helpful later when we want stream colors to animate
smoothly when dark mode is toggled, along with various other style
attributes that will naturally animate too.
Quoting that
ColorSwatch.lerp
: