-
-
Notifications
You must be signed in to change notification settings - Fork 672
per-account 6/n: Stop letting GlobalState cast to PerAccountState #5105
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
Changes from all commits
e8eeb68
cc4af46
3decb31
d0f4900
9f88c9c
85ecbb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -405,7 +405,7 @@ export type UsersState = $ReadOnlyArray<User>; | |
| * parts of our code will in that future operate on a particular account and | ||
| * which parts will operate on all accounts' data or none. | ||
| */ | ||
| export type PerAccountState = $ReadOnly<{ | ||
| type PerAccountStateImpl = $ReadOnly<{ | ||
| // TODO(#5006): Secretly we assume these objects also have `Account` data, | ||
| // like so: | ||
| // accounts: [Account, ...mixed], | ||
|
|
@@ -445,6 +445,8 @@ export type PerAccountState = $ReadOnly<{ | |
| ... | ||
| }>; | ||
|
|
||
| export opaque type PerAccountState: PerAccountStateImpl = PerAccountStateImpl; | ||
|
|
||
| /** | ||
| * Our complete Redux state tree. | ||
| * | ||
|
|
@@ -474,10 +476,6 @@ export type GlobalState = $ReadOnly<{| | |
| accounts: AccountsState, | ||
| |}>; | ||
|
|
||
| // For now, under our single-active-account model, we want a GlobalState | ||
| // to be seamlessly usable as a PerAccountState. | ||
| (s: GlobalState): PerAccountState => s; // eslint-disable-line no-unused-expressions | ||
|
|
||
| /** | ||
| * Assume the given per-account state object is secretly a GlobalState. | ||
| * | ||
|
|
@@ -493,6 +491,28 @@ export function assumeSecretlyGlobalState(state: PerAccountState): GlobalState { | |
| return state; | ||
| } | ||
|
|
||
| /** | ||
| * Use the given state object as a per-account state. | ||
| * | ||
| * TODO(#5006): We'll have to fix and eliminate each call to this. | ||
| */ | ||
| export function dubPerAccountState(state: GlobalState): PerAccountState { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm reading "dub" as a synonym of "assumeSecretly" in I'm not saying we need to replace "dub" with "assumeSecretly" in either of these. That'd make for some long names, and both will go away soon. But I wanted to check my understanding.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It basically is. I had a distinction in my mind when I picked a different name here... but I think at the end of this PR, where (I think the idea was that because at the time |
||
| // Here in this file, we can make this cast with no fixmes (for now, under | ||
| // our single-active-account model.) But from anywhere outside this file, | ||
| // that's forbidden because PerAccountState is opaque, so the way to do it | ||
| // is by calling this function. | ||
| return state; | ||
| } | ||
|
|
||
| /** | ||
| * For tests only. Use the given state object as *both* kinds of state. | ||
| * | ||
| * TODO(#5006): We'll have to fix and eliminate each call to this. | ||
| */ | ||
| export function dubJointState(state: GlobalState): GlobalState & PerAccountState { | ||
| return state; | ||
| } | ||
|
|
||
| // No substate should allow `undefined`; our use of AsyncStorage | ||
| // depends on it. (This check will also complain on `null`, which I | ||
| // don't think we'd have a problem with. We could try to write this | ||
|
|
||
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.
In particular (and I'm not sure if this needs a mention in the commit, I just want to check my understanding), this prevents GlobalState from posing as a PerAccountState in code outside this file. We totally can do that within the file, and in fact we do:
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.
Yes, that's right. Mmm, and I should update that comment and/or cast, too, because they become misleading with this change.