-
Notifications
You must be signed in to change notification settings - Fork 938
Migrate firestore to component framework #2329
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
Conversation
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.
LGTM but I'll let @wilhuff approve since he reviewed the previous iterations.
Oh, also:
|
(this.app as _FirebaseApp).INTERNAL.addAuthTokenListener( | ||
this.tokenListener | ||
); | ||
this.auth = authProvider.getImmediate(undefined, { optional: true }); |
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.
undefined
here is wrong. We should be getting the auth instance associated with the current Firebase App.
Most of the reason why people use Firestore with multiple apps is to be able to associate multiple different login credentials with different logical sessions. Imagine if you were implementing Gmail's mobile app with Firestore: each identity (and its associated mailboxes from Firestore) should be a separate App, making it possible to simultaneously get new mail notifications from all currently signed-in accounts.
Tying this unconditionally to the default app breaks secondary sign-in.
Indeed I'm not sure why Provider would want to expose this kind of functionality to callers at all. Provider should give the instance scoped to the current app. If the SDK exposed by the provider is a singleton that should be that SDK's problem in how it registers its component.
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.
I think there is a misunderstanding here. The provider instances are indeed scoped to the current app (Not necessarily the default app), so it should work as we expect.
Some SDKs allow multiple instances per app, e.g. Storage and Database. The first parameter of getImmediate()
let you provide the name for the specific service instance scoped to the same app.
Firestore doesn't support multiple instances per app, so we pass 'undefined'. Actually you can pass any string, but the provider will only create and cache a single instance of Firestore, because we set multipleInstances
to false
when registering Firestore component.
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.
I may be confused but I think undefined
is some sort of identifier
string (https://github.com/firebase/firebase-js-sdk/blob/fei-component-firestore/packages/component/src/provider.ts#L57) and isn't too significant (though I'm not sure what it's for)...
Given that getImmediate() allows for an options object already it seems like moving identifier
into the options object would be much cleaner. i.e.:
// here we would just do:
this.auth = authProvider.getImmediate({ optional: true });
// Elsewhere that identifier is used you would do:
foo = fooProvider.getImmediate({ identifier: 'gobbly gook' });
Passing literal values like true
, false
, null
, undefined
as raw function arguments tends to be unreadable. I always avoid it or comment them (e.g. ...getImmediate(/*identifier=*/undefined, ...)
)
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.
Firestore is designed to support multiple instances per app. We happen to only expose a single (default)
database right now but our intent is to expose many databases per cloud project.
I have no idea how that maps to multiple instances of Auth per instance.
On the whole though the thing that threw me is that undefined
means DEFAULT_ENTRY_NAME = '[DEFAULT]'
. I misinterpreted this to mean that it was the default app, not the default instance within the app. This could be avoided if there any comments (at all) about the meanings of these things in Provider
.
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.
Yup. It's the identifier string for SDKs that allow multiple instances per app. You are right that it is insignificant for Firestore because Firestore doesn't support multiple instances per app.
It's intended for the following use case:
const app = firebase.initializeApp({
...
databaseUrl: "https://test.firebaseio.com",
...
});
// use the databaseUrl from the config
const database1 = app.database();
// user has 2 RTDB instances
// https://test-2.firebaseio.com is the identifier as well as the database url
// database2 is scoped to the same `app` and share the same auth state with database1
const database2 = app.database('https://test-2.firebaseio.com');
I like the idea of moving identifier
to the options object because it hides identifier
from SDKs that doesn't need it. I will make the change in #2316 and in other PRs.
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.
@wilhuff I added comments to Provider
and updated getImmediate()
signature as @mikelehen suggested.
9722dbc
to
4e57970
Compare
Yeah, I manually run tests for each SDK and made sure all tests pass before opening the PR. For travis to pass, we'd need to wait until all PRs are merged into I tested auth and firestore integration manually in my test project by merging auth and firestore branches locally. I tried regular auth import, dynamic auth import which all works. Once everything merged into |
2de97a2
to
fa22d0e
Compare
@wilhuff Can I get the approval, so I can merge it into the integration branch for integration testing ? |
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.
LGTM
* Migrate Firestore to component framework * [AUTOMATED]: Prettier Code Styling * remove unused import * removed unnecessary type assertion * update getImmeidate call
* Migrate Firestore to component framework * [AUTOMATED]: Prettier Code Styling * remove unused import * removed unnecessary type assertion * update getImmeidate call
* Migrate Firestore to component framework * [AUTOMATED]: Prettier Code Styling * remove unused import * removed unnecessary type assertion * update getImmeidate call
* Migrate Firestore to component framework * [AUTOMATED]: Prettier Code Styling * remove unused import * removed unnecessary type assertion * update getImmeidate call
* Component framework implementation (#2316) * Component implementation * update dep version * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * rename variables * address comments * [AUTOMATED]: Prettier Code Styling * remove unused comment * update code * [AUTOMATED]: Prettier Code Styling * rename to clearInstance to have naming consistency * make FirebaseApp tests work again * fix node tests * [AUTOMATED]: Prettier Code Styling * add comments for ComponentType * [AUTOMATED]: Prettier Code Styling * pass Component directly into Providers * [AUTOMATED]: Prettier Code Styling * correct spellings * update readme * fix lint issue * remove unused import * fix API change * move types around * [AUTOMATED]: Prettier Code Styling * improve provider typing * [AUTOMATED]: Prettier Code Styling * Migrate analytics to component platform (#220) * migrate analytics * minor analytics refactoring * interface merge * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * allow overwriting a registered component * [AUTOMATED]: Prettier Code Styling * change ComponentType to string enum * address comments * [AUTOMATED]: Prettier Code Styling * remove return only generics * Move identifier to options object for getImmediate() * [AUTOMATED]: Prettier Code Styling * Make getProvider() type safe * [AUTOMATED]: Prettier Code Styling * define a new method to replace overwrite flag * [AUTOMATED]: Prettier Code Styling * Make component type safe * [AUTOMATED]: Prettier Code Styling * remove the generic type from component container * Update FirebaseApp and Analytics * [AUTOMATED]: Prettier Code Styling * remove unneccessary casting * [AUTOMATED]: Prettier Code Styling * fix typo * address comments * [AUTOMATED]: Prettier Code Styling * update some types * [AUTOMATED]: Prettier Code Styling * handle errors from instance factory * [AUTOMATED]: Prettier Code Styling * Migrate Performance to component framework (#2325) * Migrate Performance to component framework * [AUTOMATED]: Prettier Code Styling * removed unused import * Migrate RC to component framework (#2324) * Migrate RC to component framework * [AUTOMATED]: Prettier Code Styling * remove unused import * Migrate storage to component framework (#2326) * Migrate Database to component framework (#2327) * Migrate Database to component framework * revert auth formatting * Mirgrate functions to component framework (#2328) * Migrate installations to component framework (#2322) * Migrate installations to component framework * remove unused import * update calling code according to the latest component changes * added forceRefresh back * Migrate messaging to component framework (#2323) * Migrate messaging to component framework * remove unused import * bundle firebase services in a single object * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * address comment * Make tests work again * Migrate firestore to component framework (#2329) * Migrate Firestore to component framework * [AUTOMATED]: Prettier Code Styling * remove unused import * removed unnecessary type assertion * update getImmeidate call * Migrate testing to component framework * [AUTOMATED]: Prettier Code Styling * Update SDKs to use the new type system (#2358) * update database types * update Firestore types * update installations type * update messaging types * update functions types * update performance types * update remoteconfig types * update storage types * fix analytics issue * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: Prettier Code Styling * Use the new method * Migrate Auth to component framework (#2342) * Mirgrate Auth to component framework * update Auth types * [AUTOMATED]: Prettier Code Styling * address comments * update deps * [AUTOMATED]: Prettier Code Styling * Get installations service from the container (#2376) * Get installations from the container * [AUTOMATED]: Prettier Code Styling * revert dev changes * convert eslint from json to js. * [AUTOMATED]: Prettier Code Styling * fix broken scripts * address comments * [AUTOMATED]: Prettier Code Styling * fix typos
Context
go/firebase-js-platform
#2316 implements the proposal.
Changes
This PR changes
@firebase/firestore
to use the component platform implemented in #2316Dependencies
#2316
#2317