Skip to content

Commit

Permalink
feat(i18n): work background without delay
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd authored and njfamirm committed Feb 25, 2023
1 parent 4c5f669 commit 2876d00
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions core/i18n/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ l18eContextConsumer.subscribe(
* Example:
*
* ```ts
* setLocale('fa');
* setLocale();
* ```
*/
export const setLocale = (locale?: LocaleContext): void => {
Expand All @@ -118,7 +118,7 @@ export const setLocale = (locale?: LocaleContext): void => {

logger.logMethodArgs('setLocale', locale);
if (activeLocaleContext?.code !== locale.code) {
localeContextProvider.setValue(locale);
localeContextProvider.setValue(locale, {debounce: 'No'});
}
};

Expand Down Expand Up @@ -158,17 +158,19 @@ export const setL18eLoader = (l18eLoader: (locale: LocaleContext) => MaybePromis
return;
}

activeL18eContext = null;
l18eContextProvider.expire();
if (l18eContextProvider.getValue()) {
l18eContextProvider.expire();
activeL18eContext = null;
}

try {
const l18e = await l18eLoader(locale);
l18eContextProvider.setValue(l18e);
l18eContextProvider.setValue(l18e, {debounce: 'No'});
}
catch (err) {
logger.error('l18eLoader', 'loader_function_error', err);
}
});
}, {receivePrevious: 'NextCycle'});
};

/**
Expand Down

0 comments on commit 2876d00

Please sign in to comment.