Skip to content
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

per-account 7/n: Sort out plain actions #5113

Merged
merged 15 commits into from
Nov 9, 2021

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented Nov 8, 2021

This is the next PR in the series after #5105, #5083, #5066, #5030, #5016, #5017, and #5023, produced from the branch described at #5006 (comment).

From the foreshadowing last time:

After that, we'll start distinguishing plain actions: just like other areas of our code before the start of this PR series, most of them implicitly refer to the active account while others don't, and we'll start tracking which is which so that we can later reinterpret the former group as referring to whichever specific account their caller had in mind.

That's this PR.

And this is the end of that draft branch! 🎉

There's still more to do for #5006. But at the end of this PR, we've accomplished this (from that comment #5006 (comment) where I described the draft branch these came from):

That lets us use the type-checker to trace how the data flows around to ensure that we're consistent in which code gets which kind of type [i.e. per-account vs. global], and to identify exactly which spots of code rely on assumptions that won't stay true in the future where these objects are actually distinct.

The next task will be to fix those spots one by one.

@chrisbobbe
Copy link
Contributor

Thanks, this LGTM! Looks like just a Prettier failure on the last commit, otherwise please merge at will.

This was basically an attempted workaround for zulip#3999.  But it
falsely tells the user that the settings have actually taken --
there's no indication that we're still saving them.  And once
the user wises to the fact that we pretend to have saved them
when we haven't, there's no way for them to tell when we *have*
actually succeeded in saving them.

It'd be good to do better here; details on that in the issue.
For the moment, just stop pretending.
We'll want to separate per-account from global actions.  This one
is now used only in global contexts, so make it global.  If we need
a per-account version in the future, we can add one.

(We'll also give it a more specific name, in the next commit.)
This was called just SETTINGS_CHANGE.  We want to specifically
distinguish changing a global from a per-account setting, because
those will start being stored in different places.

The action already only touches global settings -- we don't have any
per-account settings that aren't server data, and therefore covered by
event actions instead -- so all it needs is a rename to make that
clear, and so that if we add a local per-account setting in the future
it'll be natural to make a new action type for that.
We're about to sort our actions into those acting on per-account
vs. global state.  These two sub-groupings straddle those categories;
and all these sub-groupings exist only for local convenience in this
file, so just dissolve these.
We'll turn these groupings into named, usable types shortly.  Doing
this separately first simplifies the diffs.
We'll use these subtypes to tighten down which actions can be
dispatched from per-account vs. global contexts, and which actions
can be expected by per-account vs. global reducers.

That will help put us in a position to have a multi-account-friendly
schema, where everything per-account can get from its caller which
account it's supposed to be operating on rather than resorting to an
implicit choice of "the active account".

Also add some comments about this structure.
This is NFC because these sub-reducers already ignore any actions
that aren't in PerAccountAction.  (Flow won't check this for us;
but I just grepped for for `case` labels in these reducers' files,
piped that to `sort -u`, and confirmed that all the results are
as expected.)

Here "ignore" means they return the state they're given, but after
applying JS optional-argument semantics to it -- so when passed
`undefined`, they return their respective `initialState` values.
Also PerAccountState while we're at it, for those of them that take
the (relatively) "global" state as a third argument.
@gnprice gnprice merged commit 0d29d04 into zulip:main Nov 9, 2021
@gnprice
Copy link
Member Author

gnprice commented Nov 9, 2021

Ah indeed -- fixed, and merged. Thanks for the review!

@gnprice gnprice deleted the pr-peraccount-part7 branch November 9, 2021 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants