-
Notifications
You must be signed in to change notification settings - Fork 893
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
Remove return Promise.resolve()
statements from the codebase
#422
Conversation
@@ -132,14 +132,13 @@ export class DatabaseInternals { | |||
constructor(public database: Database) {} | |||
|
|||
/** @return {Promise<void>} */ | |||
delete(): Promise<void> { | |||
async delete(): 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.
How will this be supported in browsers that don't support async/await. Last time I asked - this wasn't being polyfilled.
If it is - that may be a big polyfill.
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 TypeScript supports async/await and has downlevel helpers to make the generated code work in ES3/ES5 (https://blog.mariusschulz.com/2016/12/09/typescript-2-1-async-await-for-es3-es5) but we need to see what the resulting code size change is...
Hey @merlinnot thanks for the heads up, you can run the tests by creating a test project at https://console.firebase.google.com/ In the mean time, I'll get that URL updated! Thanks! |
@jshcrowthe I had a plan to use Travis for testing when I saw you actually run CI for external PRs, glad to see I can do that much easier :) I'll find some time to finish this tomorrow and I'll try to make some size comparison for the built code. |
a86e26b
to
c0c3c63
Compare
Tests are failing with These changes do indeed increase code size, but this increase is almost constant (helper functions) in gzipped versions and allows us to use async/await all over the place 👍
|
c0c3c63
to
fecde12
Compare
@merlinnot Thanks for this cleanup PR! In general, I would be happy to proceed with this if it didn't impact code size as much. Do you think we can find a way to reduce the impact? Adding 9kb to FIrestore is a little hard to swallow, especially since we want to reduce our size in general. |
We have enabled billing for the test projects recently. I have re-kicked your tests to take advantage of this. |
I’ll try to take a look on reducing the size impact over the weekend. |
It reduces the size of TypeScript packages (namely `firebase-database`, `firebase-firestore`, `firebase-messaging` and the combined `firebase`) be reusing TypeScript helper methods (e.g. `__awaiter`) which were included in every single file relying on features not available in ES5 (emitted during transpilation process).
0b0bba4
to
58400cf
Compare
58400cf
to
547d1dc
Compare
547d1dc
to
c1f73c0
Compare
Ok, here we go:
Some changes were made automatically by Prettier, I guess they've slipped into master somehow ( Tests are passing locally, there's something wrong with Travis 😟 |
I'll resolve all of the issues once we'll agree it's ready to be merged. |
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.
In general the changes look good, I like where this is headed. When you remerge w/ master, you should pick up some of these prettier changes which should help to trim down what the actual delta is here.
@@ -2,6 +2,7 @@ | |||
"compileOnSave": false, | |||
"compilerOptions": { | |||
"declaration": true, | |||
"importHelpers": 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.
Because you are doing this in the base tsconfig, any helper fxns, across all packages, that match this flag will be required via tslib
. As such, we need to add the tslib
dependency to all packages using this base config not just the 3 using async
/await
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.
You're right, done in 12c2b54. I've omitted *-types
packages as stated in the commit message.
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.
Perfect, thanks!
…til packages. Since we set `importHelpers` compiler option to `true` in the base config, we need to add `tslib` to all packages. `*-types` packages are omitted since they do not contain any executable code.
Merged with master, all changes are meaningful. Travis has some existential problems 😉 Ready for a review. |
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've reviewed all of the package.json/yarn.lock and top-level config changes and they all look good.
I've given the other files a once over as well and the changes seem fine, though I'll let the other reviewers take a look at those in more depth.
@@ -205,7 +197,7 @@ describe('Firebase Messaging > *Controller.deleteToken()', function() { | |||
it(`should handle error on deleteToken ${ServiceClass.name}`, function() { | |||
const fakeSubscription = { | |||
endpoint: EXAMPLE_TOKEN_SAVE.endpoint, | |||
unsubscribe: () => Promise.resolve() | |||
unsubscribe: async () => {} |
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'm personally not a fan of this pattern - it's difficult to tell what the stubbed behavior should be doing.
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.
It clearly states "do nothing", doesn't 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.
It's more about the expectation of the API (i.e. return a Promise).
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.
Would rather the stubs were reverted but not enough to argue about 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.
Approved for 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.
Approved for Firestore with 2 minor requests (Josh if it's easier, you can merge this and then you or I can fix them).
I also think this leaves us in a somewhat messy state with mixing usage of await with manual Promise chaining within methods. I think we should work towards cleaning this up, but not in this PR, and in general it's not super urgent.
} else { | ||
// Some other error, don't reset stream token. Our stream logic will | ||
// just retry with exponential backoff. | ||
return 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.
Can you leave the else block (just containing the comment)? It makes the context for the comment more clear.
@@ -798,10 +785,9 @@ export class RemoteStore { | |||
// another slot has freed up. | |||
return this.fillWritePipeline(); | |||
}); | |||
} else { | |||
// Transient error, just let the retry logic kick in. | |||
return 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.
Again, can you leave the else block?
I've verified tests are passing so this is good to go @merlinnot, can you address the two issues from @mikelehen and then we'll get this merged? |
the context more clear. Addresses @mikelehen review firebase#422 (review)
Done ✅ |
Awesome work here @merlinnot thanks so much for the contribution! |
I cannot make sure all existing tests in the repository pass after these changes since I'm not able to run them. An error message is clear and it says I'd have to create a test project by visiting https://firebase.corp.google.com/ which I'm not allowed to since I'm not a Google employee.
I'd appreciate if someone with access could run all of the tests for me.