Skip to content

Prep work before new revision for #4694.#4892

Merged
gnprice merged 21 commits intozulip:masterfrom
chrisbobbe:pr-redux-persist-multi-set-prep
Jul 16, 2021
Merged

Prep work before new revision for #4694.#4892
gnprice merged 21 commits intozulip:masterfrom
chrisbobbe:pr-redux-persist-multi-set-prep

Conversation

@chrisbobbe
Copy link
Copy Markdown
Contributor

@chrisbobbe chrisbobbe commented Jul 9, 2021

Related: #4694

Greg confirms that `false` would have been treated the same way as
zero:
  zulip#4694 (comment)

The documented thing to do is to pass a number, so, do that:
  zulip#4694 (comment).
And, since that leaves us with `.reduce`s and `.reduceRight`s being
done on empty arrays (which is pointless), drop those and use the
`initialValue`s that had been passed to them.
…or`.

So it's easier to inline `stateIterator`, which we'll do soon.
So it'll be easier to inline `stateIterator`, which we'll do soon.
…rn`.

None of these logs are actually active in production, but we'd like
to change that soon, since they might help us discover unknown
problems with storage.

They're not active for two reasons:

- The ones in `autoRehydrate` are behind a check for `config.log`,
  which we haven't been passing (we'll change that soon)

- The others are behind a check for whether we're running in
  production or not (we'll change that soon)

Since we're looking to dissolve or replace redux-persist, we feel
comfortable making this kind of project-specific change.
This wasn't being logged anyway, since we haven't been passing
`config.log` with the `autoRehydrate` call so far.

But it's something that would get logged when things work as
expected, so it'd be really noisy. If someone needs to log stuff for
debugging, they'll want to find their own targeted logs to use
anyway.
We're working with unaltered state from memory, which should be
shaped just like `GlobalState`. If a whole substate is undefined,
it's not because redux-persist made it so.

Still, `AsyncStorage.setItem` won't want anything other than a
string [1]. In particular, we might end up giving it `undefined` if
the value straight from Redux were `undefined`; I expect
`serializer(undefined)` would give `undefined` because we serialize
with JSON, and `JSON.stringify(undefined)` gives `undefined`. So,
add a check to `reduxTypes` that `GlobalState` doesn't allow
`undefined` at any of its keys.

Also, if `AsyncStorage` does run into a problem, then
redux-persist's function `warnIfSetError` should give us a console
warning. The previous behavior of silently doing nothing when a
value is `undefined` seems worse than that.

[1] https://react-native-async-storage.github.io/async-storage/docs/api#setitem
Like we did for `removeItem` in 1d8ef1b. As in that case, grow the
libdef for @react-native-community/async-storage, with the method
suggested at the top:

```
// All definitions taken directly from:
//    @react-native-community/async-storage/lib/AsyncStorage.js
```
@gnprice gnprice force-pushed the pr-redux-persist-multi-set-prep branch from 21ddc25 to 9027646 Compare July 16, 2021 00:35
@gnprice
Copy link
Copy Markdown
Member

gnprice commented Jul 16, 2021

Looks good, thanks! Merging.

@gnprice gnprice merged commit 9027646 into zulip:master Jul 16, 2021
@chrisbobbe
Copy link
Copy Markdown
Contributor Author

Thanks for the review!

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