-
Notifications
You must be signed in to change notification settings - Fork 944
Remove enum overhead #2697
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 enum overhead #2697
Conversation
Note that the TypeScript style guides recommends against this, but the reasons do not apply to our codebase. |
FYI @Feiyang1 |
@@ -51,7 +51,7 @@ export class EventManager implements SyncEngineListener { | |||
q.canonicalId() | |||
); | |||
|
|||
private onlineState: OnlineState = 'Unknown'; | |||
private onlineState: OnlineState = OnlineState.Unknown; |
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 can now probably move the explicit type here (i.e. restore it back to)
private onlineState = OnlineState.Unknown;
?
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. Note that this was part of a straight revert.
/** | ||
* The Firestore client is in an unknown online state. This means the client | ||
* is either not actively trying to establish a connection or it is currently | ||
* trying to establish a connection, but it has not succeeded or failed yet. | ||
* Higher-level components should not operate in offline mode. | ||
*/ | ||
| 'Unknown' | ||
Unknown = 'Unknown', |
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.
Do we need the strings in here anymore? Can these just be numeric?
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 string values are persisted in WebStorage (but it is mostly transient data). I added a comment to explain this.
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.
LGTM
This removes the overhead that Enums introduce in TypeScript by changing our enums to "const enums" which can be inlined: https://www.typescriptlang.org/docs/handbook/enums.html#const-enums
This also reverts some of the changes that were made to the OnlineState enum and uses the same solution.
Size before: 318393 bytes (90882 gzipped)
Size after: 315811 bytes (89863 gzipped - 1.2%)