-
-
Notifications
You must be signed in to change notification settings - Fork 835
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
Convert common time helpers to Typescript #2391
Conversation
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 mostly makes sense, thanks!
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.
Why does one import uses import * as dayjs from 'dayjs';
while the others use import dayjs from 'dayjs';
?
Do we actually want to import global variables or could we just type-hint them somewhere? Using the global variable instead of an import will save up on the file size, as webpack won't have to add the additional code that resolves each import.
@clarkwinkelmann We can test locally if the bundle size increases if they're just used for typings. Haven't done so myself yet. |
I removed the |
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.
Looks good to me! I'm approving this as long as
Do we actually want to import global variables or could we just type-hint them somewhere? Using the global variable instead of an import will save up on the file size, as webpack won't have to add the additional code that resolves each import.
doesn't prove to be an issue
@askvortsov Thanks, I'll test this as soon as possible. |
TestSo, apparently webpack doesn't inject the module resolving code on each module, but use a global one. Here's the test i did. Flarum buildHeres "use strict";
__webpack_require__.d(__webpack_exports__, "a", function() { return humanTime; });
var dayjs = __webpack_require__(28);
var dayjs_default = /*#__PURE__*/__webpack_require__.n(dayjs);
var dayjs_plugin_relativeTime = __webpack_require__(73);
var dayjs_plugin_relativeTime_default = /*#__PURE__*/__webpack_require__.n(dayjs_plugin_relativeTime);
function humanTime(time) {
var d = dayjs_default()(time);
var now = dayjs_default()();
// ...
} Dayjs pluginsOne thing we could optimize is, even not using directly, we need to import relativeTime dayjs plugin at We can avoid this import if we move this plugin installation process to a separated dayjs library module, something like: // js/src/common/lib/dayjs.ts
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime)
export default dayjs
// js/src/common/utils/humanTime.ts
// no need import relativeTime from 'dayjs/plugin/relativeTime';
import dayjs from '../../common/lib/dayjs'
|
Thank you for testing this!
Hmm I really like this idea! @clarkwinkelmann @rob006 could this also work for https://discuss.flarum.org/d/25196-beta-14-dayjs-translations? |
@askvortsov1 It could technically work but the config files would need to use We could also just have language packs set the JS objects to an |
It seems that it would be a more drastic change, and the code already works without it, so I created a new issue for this subject so that we can move forward here. |
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 triggered by the imports order ahah (fullTime
imports dayjs first, while humanTime
imports Mithril first 🙉 )
Looks good otherwise.
@clarkwinkelmann Fixed following this rule: external imports first, internal last, both alphabetically sorted. |
See #3533