-
-
Notifications
You must be signed in to change notification settings - Fork 652
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
refactor: static createInstance for wider browser support #1973
Conversation
@@ -578,7 +578,7 @@ class I18n extends EventEmitter { | |||
: 'ltr'; | |||
} | |||
|
|||
static createInstance = (options = {}, callback) => new I18n(options, callback) | |||
static createInstance(options = {}, callback) { return new I18n(options, callback) } |
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.
@adrai do you think this change is equivalent ? In my understanding yes. (no late static binding issue, no async, no need for the function / class property), but I guess there is or was a reason..
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.
we may ask @perrin4869 => e401175
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 equivalent to me!
I generally prefer to use arrow functions because it saves the need to use curly braces, so it was probably only an esthetics decision, feel free to change 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.
@perrin4869 to give you a bit of context... in the latest I18next v23 we don't transpile for older browser/platforms... but the notation with static xxx = function
might bring some issues (does not pass eschecks before es2022). So the idea here is to refactor at the source. See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static
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.
Thank you so much @perrin4869 !
@adrai on my side it seems okay... feel free to merge whenever needed. I'll dig into other issues in the coming days |
thank you @belgattitude and @perrin4869 v23.0.2 has just been released |
Reason: i18next 23 dropped support for older node and browsers.... The new version runs fine with recent node, but I feel there's an issue regarding the transpilation of
It's currently transpiled as
Runs fine from es2022 (not before) ... but browser support I'm less sure how static + function will work (https://caniuse.com/mdn-javascript_classes_static -> 95% / but I suspect that
static = function
is a different case).With this PR the transpiled code would be
Which:
Need to dig more...
PS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static
Checklist
npm run test