Skip to content
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

Support for setLocale regardless of import order #125

Merged
merged 2 commits into from
Oct 12, 2017

Conversation

haydnhkim
Copy link
Contributor

Previously, import order was important to use setLocale.
It had to import setLocale first, then run setLocale and import yup.

this pull request can set the locale via setLocale regardless of the import order.
This is also convenient when someone use it, and is also useful if someone need to load and set the user language asynchronously.

@ctavan
Copy link
Contributor

ctavan commented Sep 20, 2017

I actually stumbled upon this exact issue about 5 minutes before you opened this PR, so I'd be really happy to see this merged ;).

However it made me think that it might be worthwhile to reconsider the singleton-nature of the yup library. Before your patch the whole locale thing was dependent of import order.

With your patch that's fixed but now we have an implicit dependency on call order which would make it really hard to reliably reconfigure locales during runtime (not sure if that's an actual use case though).

This could be mitigated by introducing instances of yup where locales are always loaded upon instance creation and remain immutable afterwards.

Again, I'm not sure if there's a real use case for this. Being independent of import order is already a huge step forward! 👏

@ctavan ctavan mentioned this pull request Sep 26, 2017
@jquense jquense merged commit da11a83 into jquense:master Oct 12, 2017
@jquense
Copy link
Owner

jquense commented Oct 12, 2017

Thanks!

@klis87
Copy link
Contributor

klis87 commented Oct 18, 2017

@ctavan 1 use case I see is for example server side rendering. Singletons are really dangerous there as 2 requests executed at the same time could cause some race conditions - like request 2 could overwrite request 1 language which would cause mixed languages in request 1. With SSR, it is always safest to work with independent instances for each request.

Tadwork pushed a commit to Tadwork/yup that referenced this pull request Apr 18, 2018
Support for setLocale regardless of import order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants