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
Plugins: how extend only one instance of dayjs? #655
Comments
Yes, and I can’t see if there is a problem. What’s your concern, please? |
Thanks @iamkun for your answer, I don't agree much with this design choice. Not that I expect it giving practical problems for now, but an external component using dayjs would alter how dayjs works in the whole app. This doesn't sound correct to me. What I would have preferred is a factory like: const dayjs = dayjs.factory();
dayjs.extend(aPlugin); // only this instance of dayjs will use `aPlugin` Just my feedback! Thanks for your work on dayjs! |
Thanks. To keep only one type of dayjs might be better I think. 😊 |
I'll close this issue since it's been a while since it's been opened. Feel free to reopen if you have updates on this |
@iamkun, I found this issue as I was actually looking for the sort of The problem I have is this: dayjs.extend(updateLocale);
dayjs.updateLocale('en', {
relativeTime: {
future: 'in %s',
past: '%s ago',
s: '<1 min',
m: '1 min',
mm: '%d mins',
h: '1 hour',
hh: '%d hours',
},
}); So I updated locales according to our product needs, but now it will update it for the entire app which I believe is not what we want. What can be a work around here? |
@szympajka there's no dayjs factory function atm. In your case, it's better to use two locales. e.g. import somelocale from 'dayjs/locale/somelocale'
// update somelocale to other config and name
const otherlocale = {
name: 'otherlocale',
...somelocale
}
// then register otherlocale
dayjs().locale(otherlocale)
// then you will have two locale config that you want
dayjs().locale(somelocale)
dayjs().locale(otherlocale) |
thanks, @iamkun, it helped :) |
I need to have badMutable plugin in specific places not globally , any suggestions @iamkun |
@kb-ally I have the same issue. How did you end up solving it? |
How to change local to UTC time?
|
This should really be re-opened. This is the same sort of unexpected behavior that people are leaving It doesn't need to be fixed per se, but closing without resolution? Why? |
Hi @iamkun, In a micro frontend architecture with a single appshell hosting multiple (full app) remotes, each remote should be able to set its own default day js configs (locale, tz ec) without affecting/overriding other remotes. |
Seems like you could keep the current behavior as the default, but offer a method that returns a new untouched DayJS instance, for cases like this. |
@iamkun would you be open to reconsidering your previous stance? I think many developers would prefer to use |
For me it's an issue when using it as a replacement for moment.js in a 3rd party library. In the rest of my codebase i do want to use the non BadMutable version of Dayjs. |
yeah would prefer plugins/updateLocale to return an immutable instance of dayjs rather than overriding global config |
@iamkun the code you shared with @szympajka does not appear to work... I am unable to have a custom That being said, I am in agreeance with other commenters in this thread - it would be ideal to spawn a unique instance of |
I think this package is unmaintained, but still, friendly bump. |
I'm evaluating this library for react-day-picker and I have a concern about plugins.
For what I understand, extending dayjs with plugins will affect all the instances of dayjs.
E.g. if I extend dayjs with
weekOfYear
plugin, the dayjs instances used by an application implementing react-day-picker+dayjs will be extended too. Is it correct? If yes, how to extend just one instance of dayjs?The text was updated successfully, but these errors were encountered: