fix(localize): don't fire localeChanged event if set to the same locale
This commit is contained in:
parent
5452ae6fca
commit
3115c50d59
2 changed files with 13 additions and 0 deletions
|
|
@ -181,6 +181,9 @@ export class LocalizeManager extends LionSingleton {
|
|||
}
|
||||
|
||||
_onLocaleChanged(newLocale, oldLocale) {
|
||||
if (newLocale === oldLocale) {
|
||||
return;
|
||||
}
|
||||
this.dispatchEvent(new CustomEvent('localeChanged', { detail: { newLocale, oldLocale } }));
|
||||
if (this._autoLoadOnLocaleChange) {
|
||||
this._loadAllMissing(newLocale, oldLocale);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { expect, oneEvent } from '@open-wc/testing';
|
||||
import sinon from 'sinon';
|
||||
import { fetchMock } from '@bundled-es-modules/fetch-mock';
|
||||
import { setupFakeImport, resetFakeImport, fakeImport } from './test-utils.js';
|
||||
|
||||
|
|
@ -48,6 +49,15 @@ describe('LocalizeManager', () => {
|
|||
expect(event.detail.oldLocale).to.equal('en-GB');
|
||||
});
|
||||
|
||||
it('does not fire "localeChanged" event if it was set to the same locale', () => {
|
||||
const manager = new LocalizeManager();
|
||||
const eventSpy = sinon.spy();
|
||||
manager.addEventListener('localeChanged', eventSpy);
|
||||
manager.locale = 'en-US';
|
||||
manager.locale = 'en-US';
|
||||
expect(eventSpy.callCount).to.equal(1);
|
||||
});
|
||||
|
||||
describe('addData()', () => {
|
||||
it('allows to provide inline data', () => {
|
||||
const manager = new LocalizeManager();
|
||||
|
|
|
|||
Loading…
Reference in a new issue