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

Add tests for ZulipAsyncStorage.getItem and .setItem. #4709

Merged
merged 14 commits into from
Jun 3, 2021

Commits on Jun 3, 2021

  1. MainTabsScreen [nfc]: Make it clear that isPad is iOS-only.

    Although it doesn't give a reason why, the `Platform` doc [1] is
    clear that `isPad` is iOS-only; we can expect it to be missing on
    Android.
    
    We'd love to know whether an Android user is on a tablet, but it
    seems `Platform` doesn't yet give us a way to do that. Until it
    does, or until we use something else that does, make it really clear
    that we're not getting accurate info on Android.
    
    [1] https://reactnative.dev/docs/platform#ispad-ios
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    96b796b View commit details
    Browse the repository at this point in the history
  2. ZulipAsyncStorage tests: Add tests for setItem.

    With a new mock for `TextCompressionModule`; we do that globally in
    case it's useful elsewhere. That module should have its own set of
    unit tests, if we plan to keep it; it looks like it doesn't yet.
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    58bbee6 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    f9bbdd0 View commit details
    Browse the repository at this point in the history
  4. ZulipAsyncStorage types: Better align .setItem/.getItem with AsyncSto…

    …rage.
    
    Now, the type for the `callback` param matches what's in the libdef
    for `AsyncStorage`. I think the question mark in the `?(...) => Foo`
    syntax isn't what we'd normally choose, but `ZulipAsyncStorage` is a
    wrapper around `AsyncStorage` so it might as well match this detail.
    
    Also the callback in `getItem` wasn't being considered optional at
    all, and now it is, which it looks like our implementation expects.
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    b35aeb9 View commit details
    Browse the repository at this point in the history
  5. ZulipAsyncStorage: Pass null for error, not undefined, on .getItem su…

    …ccess.
    
    `null` gets passed on `.setItem`'s success, so we might as well be
    consistent and do the same thing with `.getItem`.
    
    I'm starting to think that `.getItem` and `.setItem`'s
    callback-based interfaces can be trimmed away, and callers can
    exclusively use the returned Promise.
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    21f12c8 View commit details
    Browse the repository at this point in the history
  6. ZulipAsyncStorage: Also call callback on AsyncStorage.getItem failure.

    A bug like this is another reason I'm continuing to think we should
    just not bother to maintain a callback-based interface, here and in
    `.setItem`, and just maintain the Promise-based interface.
    
    Before we vendored redux-persist, which is the home of these
    methods' only callers, this would have been trickier. But now it's
    easy to make those callers adapt to the Promise-based interface.
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    d945e45 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    e91d9a8 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    f46368f View commit details
    Browse the repository at this point in the history
  9. redux-persist [nfc]: Remove some inactive code paths we'll never use.

    We don't and can't use `window.localStorage` [1],
    `window.sessionStorage` [2], or `localforage` [3]; those are (or
    they use) web APIs. So, trim all this stuff that's related to those
    out. I think I got it all, and no more; anyway, the app still runs,
    and storage seems to work fine.
    
    [1] https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
    [2] https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
    [3] https://github.com/localForage/localForage
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    317e9ea View commit details
    Browse the repository at this point in the history
  10. redux-persist: Make early return explicit.

    It looks like the rest of this callback is only meant to run if
    there hasn't been an error.
    
    In practice, I think most of it wasn't running anyway, since there
    would have been an error like "TypeError: Cannot read property
    'filter' of undefined" on the `allKeys.filter(...)` just below.
    
    Good to be explicit, though.
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    3737f61 View commit details
    Browse the repository at this point in the history
  11. redux-persist [nfc]: Stop using callbacks with ZulipAsyncStorage.foo.

    Instead, use these functions' returned Promises. This will let us
    drop ZulipAsyncStorage's callback-based interface, which will
    simplify its code.
    
    Done carefully to preserve the control flow.
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    a81847f View commit details
    Browse the repository at this point in the history
  12. ZulipAsyncStorage [nfc]: Drop support for passing callbacks.

    This simplifies the code quite a bit.
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    9fff76d View commit details
    Browse the repository at this point in the history
  13. reduxTypes: Mark GlobalState's properties as read-only.

    We already treat them as read-only everywhere except for one case,
    touched in this commit, where we've had to suppress several
    different Flow errors [0]. So, mark them as read-only with
    `$ReadOnly` [1].
    
    Treating `GlobalState`'s properties as read-only (except for that
    one exceptional case) is likely to be very stable: we treat them as
    read-only because the Redux state is a tree of objects that are all
    treated as immutable; see the Redux docs [2] and our architecture
    doc [3].
    
    [0] See Greg's comments on this at
        zulip#4709 (comment)
    
    [1] https://flow.org/en/docs/types/utilities/#toc-readonly
    
    [2] http://redux.js.org
    
    [3] ./docs/architecture.md
    chrisbobbe authored and gnprice committed Jun 3, 2021
    Configuration menu
    Copy the full SHA
    cd29cb9 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    df29833 View commit details
    Browse the repository at this point in the history