-
Notifications
You must be signed in to change notification settings - Fork 374
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
Importing RTDB code via @firebase/database #112
Conversation
Related to #54 |
/** | ||
* Deletes the service and its associated resources. | ||
* | ||
* @return {Promise<()>} An empty Promise that will be fulfilled when the service is deleted. |
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.
Promise<void>
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.
We have been using Promise<()>
in other modules (see auth.ts
for example). Perhaps we keep this as it is for now, and change them all to Promise<void>
in a future PR?
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.
Ok that is fine.
let db: Database = this.databases[dbUrl]; | ||
db.INTERNAL.delete(); | ||
} | ||
return Promise.resolve(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.
Promise.resolve()
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.
Same comment as above. We are currently doing Promise.resolve(undefined)
in other modules.
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.
Ok.
|
||
let db: Database = this.INTERNAL.databases[dbUrl]; | ||
if (typeof db === 'undefined') { | ||
let rtdb = require('@firebase/database'); |
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.
Why do you do this when you already:
import {Database} from '@firebase/database';
?
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.
This is a lazy loading tactic we used with Firestore. This ensures that the RTDB implementation does not get loaded until somebody actually makes a DB call. Import statement only loads the type definition.
Plus we need to call initStandalone()
, which cannot be imported like other types due to the way JS SDK exposes it.
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.
Not sure how lazy loading is useful in a backend server environment. Anyway, thanks for the explanation.
src/database/database.ts
Outdated
constructor(app: FirebaseApp) { | ||
if (!validator.isNonNullObject(app) || !('options' in app)) { | ||
throw new FirebaseDatabaseError({ | ||
code: 'database/invalid-argument', |
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.
FirebaseDatabaseError already adds the database/ prefix in the code.
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.
Done
test/unit/database/database.spec.ts
Outdated
|
||
afterEach(() => { | ||
return database.INTERNAL.delete().then(() => { | ||
return mockApp.delete(); |
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.
nit: 2 space indent instead of 4
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.
Done
test/unit/database/database.spec.ts
Outdated
it('should return a cached version of Database on subsequent calls', () => { | ||
const db1: Database = database.getDatabase(mockApp.options.databaseURL); | ||
const db2: Database = database.getDatabase(mockApp.options.databaseURL); | ||
expect(db1).to.deep.equal(db2); |
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 would expect this to be equal instead of deep equal. Why are you returning different references each time?
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.
Done. It was just a misunderstanding on my part about the semantics of equal()
. Thanks for pointing it out.
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.
Took a look at this and ran the tests myself. All seems to look good here!
I did update NPM (now v5.5.1
) and running npm install
updated your package-lock.json so keep that in mind.
@firebase/database
module.database.js
file.admin
namespace andFirebaseApp
.