Files
2026-03-21 18:57:10 +08:00

35 lines
763 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* global module */
/**
* 轻量语言事件总线:
* 1. 设置页切换界面语言时,当前页内组件可立即刷新;
* 2. 只传递 uiLanguage不耦合其它设置项
* 3. 订阅方自行决定是否需要重新读取完整 settings。
*/
const listeners = new Set();
function emitLocaleChange(language) {
listeners.forEach((listener) => {
try {
listener(language);
} catch {
// 忽略单个订阅方异常,避免影响其它页面刷新。
}
});
}
function subscribeLocaleChange(listener) {
if (typeof listener !== "function") {
return () => {};
}
listeners.add(listener);
return () => {
listeners.delete(listener);
};
}
module.exports = {
emitLocaleChange,
subscribeLocaleChange
};