-
-
Notifications
You must be signed in to change notification settings - Fork 638
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 Immutable
for state.flags
.
#4252
Comments
An empty object is badly formed data. It goes against `FlagsState`, and the upcoming new version of Flow (v0.113, with the RN v0.62 upgrade) would see that. But the implementation seems works for us, and the type complaint isn't resolved straightforwardly without introducing "gotcha" bugs that have to do with mutability, or making drastic changes. I've filed zulip#4252 for using `Immutable` for `state.flags`; I think it would be most productive to start there.
An empty object is badly formed data. It goes against `FlagsState`, and the upcoming new version of Flow (v0.113, with the RN v0.62 upgrade) would see that. But the implementation seems works for us, and the type complaint isn't resolved straightforwardly without introducing "gotcha" bugs that have to do with mutability, or making drastic changes. I've filed zulip#4252 for using `Immutable` for `state.flags`; I think it would be most productive to start there.
An empty object is badly formed data. It goes against `FlagsState`, and the upcoming new version of Flow (v0.113, with the RN v0.62 upgrade) would see that. But the implementation seems works for us, and the type complaint isn't resolved straightforwardly without introducing "gotcha" bugs that have to do with mutability, or making drastic changes. I've filed zulip#4252 for using `Immutable` for `state.flags`; I think it would be most productive to start there.
An empty object is badly formed data. It goes against `FlagsState`, and the upcoming new version of Flow (v0.113, with the RN v0.62 upgrade) would see that. But the implementation seems works for us, and the type complaint isn't resolved straightforwardly without introducing "gotcha" bugs that have to do with mutability, or making drastic changes. I've filed zulip#4252 for using `Immutable` for `state.flags`; I think it would be most productive to start there.
Sounds like a good plan to me!
I think this is likely a good use case for |
…te`. And tell Flow to ignore the lie. Obviously, we want to address this; I think zulip#4252 (using Immutable for this bit of state) is a good place to start. See discussion [1] for how this lie helps us in the short term. [1] zulip#4247 (comment)
Hmm, maybe! I came across that while putting this issue together, but I kind of got stuck on the name (and then still as I read a bit of its doc)—it sounds like a struct-like thing you'd reach for when you want to hold information about a single entity. |
…te`. And tell Flow to ignore the lie. Obviously, we want to address this; I think zulip#4252 (using Immutable for this bit of state) is a good place to start. See discussion [1] for how this lie helps us in the short term. [1] zulip#4247 (comment)
Greg pointed out that we should be doing this; see zulip#5188 (comment) The existing `$FlowFixMe`s put zulip#4252 as their reason. That issue would be good to fix, but it's not actually the reason the fixmes are needed. This is.
Greg pointed out that we should be doing this; see zulip#5188 (comment) The existing `$FlowFixMe`s put zulip#4252 as their reason. That issue would be good to fix, but it's not actually the reason the fixmes are needed. This is.
Greg pointed out that we should be doing this; see zulip#5188 (comment) The existing `$FlowFixMe`s put zulip#4252 as their reason. That issue would be good to fix, but it's not actually the reason the fixmes are needed. This is.
This would be another instance of #3949 and #3950.
Once something like #4201 lands, we'll have a roadmap for doing this.Done!In addition to the performance benefit, this would be a big improvement to code quality. The
FlagsState
type is the following:I'm not sure
state.flags
itself should be made anImmutable.Map
because it has a certain set of named and non-optional properties (seeFlagsState
above), but the values at those properties certainly look like good candidates forImmutable.Map
s. I'm not sure what we should land on forstate.flags
, but I do think it should be something fromImmutable
if we can.In addition to the performance benefit, this will also be good for code quality and correctness. Currently, we have two instances of
const newState = {};
in the flags reducer; that contradicts theFlagsState
type (its properties are not optional). Flow v0.113, which we get with RN v0.62 (#3782), will start to have an issue with this, indirectly. An obvious solution would be to initializenewState
toinitialState
instead of{}
; the properties we care about updating will clobber the ones oninitialState
, and it's much clearer that we won't end up with an incomplete state stored. But the implementation is such thatinitialState
itself—defined once, at the top offlagsReducer
—would get mutated. Which is no good. So I think it would be great to try to rework the logic with immutable data structures.The text was updated successfully, but these errors were encountered: