Skip to content

Conversation

schmidt-sebastian
Copy link
Contributor

This is the JS port of firebase/firebase-ios-sdk#347

"dev": "gulp dev",
"test": "run-p test:browser test:node",
"test:browser": "karma start --single-run",
"test:browser-debug" : "karma start --browsers=Chrome",
Copy link
Contributor

@jshcrowthe jshcrowthe Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Can we call this test:browser:debug

NOTE: I'm going to be adding the same script to all of the SDKs, just wanted to be consistent with the naming

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also probably include the --auto-watch flag

i.e.

{
  ...
  "test:browser:debug": "karma start --browsers Chrome --auto-watch"
  ...
}

Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good, but a few comments... mostly with promises. :-)

// Operations on the _firestoreClient don't block on _firestoreReady. Those
// are already set to synchronize on the async queue.
private _firestoreClient: FirestoreClient | undefined;
_firestoreClient: FirestoreClient | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment that this is public for testing? And explicitly use "public" to be consistent with the surrounding code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return this.syncEngine.handleUserChange(user);
}

/** Disabled the network connection. Pending operations will not complete. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

/** Enables the network connection and requeues all pending operations. */
public enableNetwork(): Promise<void> {
return this.asyncQueue.schedule(() => {
this.remoteStore.enableNetwork();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return enableNetwork() instead of Promise.resolve() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that make sense. I also made disableNetwork() return a Promise to align them better.

.disableNetwork()
.then(() => {
return Promise.all([
docRef.delete(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the same change Gil did for iOS? (Sorry, I'm not awesome enough to do it for you)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ported the changes over.

promises.push(docRef.set({ a: 1 }));
promises.push(
new Promise(resolve => {
done = resolve;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a Deferred (see other usages in this file) instead of this pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done (well, in the query test - see below)

firestoreClient.enableNetwork().then(() => {
return docRef.get().then(snapshot => {
expect(snapshot.metadata.fromCache).to.be.false;
done();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm fuzzy why you need the done thing at all. Why can't you just promises.push() this whole docRef.get().then(snapshot => ...) block? (you probably need to "return firestoreClient.enableNetwork()..." a couple lines up too)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is indeed a great simplification. And it turns out that I don't even need to keep all promises around, I just need a reference to the first promise.


let done: () => void;
const promise = new Promise<void>(resolve => {
done = resolve;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferred?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


coll.onSnapshot({ includeQueryMetadataChanges: true }, snapshot => {
if (!snapshot.empty && !snapshot.metadata.fromCache) {
done();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the listener?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But but but... ok, done :)

Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

@schmidt-sebastian schmidt-sebastian merged commit 1d9f803 into master Oct 11, 2017
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt-gooffline branch November 4, 2017 20:38
@firebase firebase locked and limited conversation to collaborators Oct 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants