-
Notifications
You must be signed in to change notification settings - Fork 945
Remove cyclic references in RemoteDocumentCache #3857
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
|
Binary Size ReportAffected SDKs
Test Logs
|
Size Analysis ReportAffected ProductsNo changes between base commit (d4db75f) and head commit (446954f). Test Logs
|
* The RemoteDocumentCache for IndexedDb. To construct, invoke | ||
* `newIndexedDbRemoteDocumentCache()`. | ||
*/ | ||
export class IndexedDbRemoteDocumentCacheImpl implements RemoteDocumentCache { |
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 "export" be removed from the declaration of IndexedDbRemoteDocumentCacheImpl
? It doesn't appear to be used outside of this file and its name implies that it is an implementation detail that should not be exposed.
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.
The entire idea behind the XYZ and XYZImpl is that XYZImpl is not exported, so that the public fields in XYZImpl are only visible within the module. So, yes, this should not be exported.
* The RemoteDocumentCache for IndexedDb. To construct, invoke | ||
* `newIndexedDbRemoteDocumentCache()`. | ||
*/ | ||
export class IndexedDbRemoteDocumentCacheImpl implements RemoteDocumentCache { |
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.
Should IndexedDbRemoteDocumentCache
implement IndexedDbRemoteDocumentCache
instead of RemoteDocumentCache
?
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. Thanks for catching.
* The memory-only RemoteDocumentCache for IndexedDb. To construct, invoke | ||
* `newMemoryRemoteDocumentCache()`. | ||
*/ | ||
class MemoryRemoteDocumentCacheImpl implements RemoteDocumentCache { |
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.
Should MemoryRemoteDocumentCacheImpl
implement MemoryRemoteDocumentCache
instead of RemoteDocumentCache
?
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. Thanks for catching.
indexManager: IndexManager, | ||
sizer: DocumentSizer | ||
): MemoryRemoteDocumentCache { | ||
return new MemoryRemoteDocumentCacheImpl(indexManager, sizer); |
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.
TypeScript noobie question: How does this compile since MemoryRemoteDocumentCacheImpl
does not implement MemoryRemoteDocumentCache
?
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.
TypeScript interfaces are enforced by duck-typing - if a type happens to implement all members of an interface, it is considered identical to a type that explicitly implements the interface. Explicitly implementing comes in handy when the methods are renamed or added as it will produce much saner errors.
This PR removes a static inheritance that WebPack cannot tree-shake.
Before, our RemoteDocumentCaches would look like this:
This patterns breaks code optimization in Webpack (as per @Feiyang1's research), but it does allow us to access "private" members within the enclosing class while also extending from another class. To address the Webpack issue while keeping some of the encapsulation, I:
The rest of the repo still refers to the old types, which are now interfaces and hide the new public methods. This is the same pattern that I applied in lots of other places already (see LocalStore), and it also allowed me to make two functions tree-shakeable that are only used in Multi-Tab (
getNewDocumentChanges()
andgetReadTime()
).There are no logic changes.