Skip to content

Conversation

@jamesdaniels
Copy link
Collaborator

@jamesdaniels jamesdaniels commented Feb 7, 2020

Refactoring useObservable and preloadObservable to be more suspense friendly.

The core idea here is that our "observable" should expose a promise that resolves on first emission (which can be thrown for suspense), a synchronous means of getting the latest value (to pass into useState), and a shared subscription for use thereafter (for useEffect).

As a matter of optimization they will keep their cache around for only a present amount of time (30 seconds by default) unless they are subscribed to (useEffect); in which case the cache will remain until the component is unloaded. This should be enough time to prevent suspense from thrashing.

To encapsulate this behavior this we've implemented our own Subject.

Other changes in this PR:

  • Ensure that the observable cache has to be keyed very specifically taking into account the firebase app, options, etc.
  • Make sure no cache keys overlap on tests & different exports
  • We're using more typescript in the tests, build them as part of the main build step since jest wasn't playing nice
  • There's still some meh types kicking around here, should take as an AI
  • Errors are thrown again until the cache timeout elapses, put down a TODO for now
  • FirebaseAppProvider now throws if the provided config does not match the existing instance options, rather than simply returning the default
  • FirebaseAppProvider now takes an appName property allowing you to have more than one app

@jamesdaniels jamesdaniels requested a review from jhuleatt February 7, 2020 08:43
@jhuleatt

This comment has been minimized.

@jamesdaniels

This comment has been minimized.

@jamesdaniels jamesdaniels marked this pull request as ready for review February 11, 2020 01:51
@jamesdaniels jamesdaniels merged commit 121f5e1 into master Feb 12, 2020
@jamesdaniels jamesdaniels deleted the jd_refactor branch February 12, 2020 20:59
@FirebaseExtended FirebaseExtended locked and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants