-
Notifications
You must be signed in to change notification settings - Fork 927
Firestore bundle build #4090
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
Firestore bundle build #4090
Conversation
|
You can see the code split result by looking at the generated bundle.js , e.g. |
The concept looks pretty good to me. I wonder if it makes sense to do the prototype patching for the Persistence-methods. Ideally, I would not be in this business for firestore-exp, but prototype patching would be the only way to get rid of the extra methods, as they are part of a class hierarchy. I think for now we can probably keep them as is, especially since they will already be part of the next |
The amount of code in |
We should be able to see the size report once #4094 is merged and this PR and Hui's PR rebased on master. |
This looks great! It would probably take me rest of 2020 to figure out all of these by myself! Agree with Sebastian we can probably leave persistence code out for now. |
Notable changes:
or
It is achieved by supplying a map of entry points to rollup's input field instead of building single entry point individually.
api/bundle.ts
andcore/bundle.ts
. I also created a new filelocal/local_store_bundle.ts
and moved bundle specific functions inlocal/local_store.ts
to it.This is needed to code split the bundle code from the main SDK code. Generally, code defined in the same module cannot be split into different bundles, a limitation imposed by the es6 spec. The spec says a module should only be evaluated once at runtime, so its side effects only happen once. If a module gets split into multiple bundles, the module will be effectively evaluated multiple times once per bundle. There is also the question on which bundle(s) should include the side effect code (e.g. a top level
console.log()
).In case a module doesn't have side effects, I thought it's possible to code split it safely using
but it doesn't seem to make any difference using rollup. Maybe webpack is able to, but I didn't try.
Anyway, I think it's safer to follow the spec and move bundle code into its own files.
@firebase/firestore/bundle
Todos:
Bundle code are hard coded into some classes. For example,
bundleCache
inIndexedDbPersistence
andMemoryPersistence
. We may want to look into prototype patching these classes at runtime in order to split out the bundle code.I reorganized code without thinking too much about the semantics. You might want to redo some of the changes.
We need to add a bundle entry point in
firebase
.I removed
loadBundle
andnamedQuery
from the firestore namespace definition in the main entry point to enable code split.If we want them to be available under
firebase.firestore
after people import@firebase/firestore/bundle
, we should patch them ontofirebase.firestore
. I added a TODO for it in the comment.