-
Notifications
You must be signed in to change notification settings - Fork 978
Adding goOnline/goOffline to the Web SDK #201
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
786f4b6
to
7f33883
Compare
7f33883
to
9375faa
Compare
packages/firestore/package.json
Outdated
"dev": "gulp dev", | ||
"test": "run-p test:browser test:node", | ||
"test:browser": "karma start --single-run", | ||
"test:browser-debug" : "karma start --browsers=Chrome", |
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: 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
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 should also probably include the --auto-watch
flag
i.e.
{
...
"test:browser:debug": "karma start --browsers Chrome --auto-watch"
...
}
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.
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; |
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.
Can you add a comment that this is public for testing? And explicitly use "public" to be consistent with the surrounding 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
return this.syncEngine.handleUserChange(user); | ||
} | ||
|
||
/** Disabled the network connection. Pending operations will not complete. */ |
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.
Disables
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
/** Enables the network connection and requeues all pending operations. */ | ||
public enableNetwork(): Promise<void> { | ||
return this.asyncQueue.schedule(() => { | ||
this.remoteStore.enableNetwork(); |
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 we should return enableNetwork() instead of 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.
Yes, that make sense. I also made disableNetwork() return a Promise to align them better.
.disableNetwork() | ||
.then(() => { | ||
return Promise.all([ | ||
docRef.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.
Can you make the same change Gil did for iOS? (Sorry, I'm not awesome enough to do it for you)
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.
Ported the changes over.
promises.push(docRef.set({ a: 1 })); | ||
promises.push( | ||
new Promise(resolve => { | ||
done = 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.
Could you use a Deferred (see other usages in this file) instead of this pattern?
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.
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(); |
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.
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)
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.
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; |
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.
Deferred?
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
|
||
coll.onSnapshot({ includeQueryMetadataChanges: true }, snapshot => { | ||
if (!snapshot.empty && !snapshot.metadata.fromCache) { | ||
done(); |
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.
Can you remove the listener?
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.
But but but... ok, done :)
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.
Thanks, looks good!
This is the JS port of firebase/firebase-ios-sdk#347