@enact/i18n
Version:
Internationalization support for Enact using iLib
38 lines (37 loc) • 870 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.onWindowFocus = void 0;
var _dispatcher = require("@enact/core/dispatcher");
var _snapshot = require("@enact/core/snapshot");
var focused = false;
var queue = new Set();
var invoke = function invoke(fn) {
try {
fn();
} catch (e) {
// failing silently
}
};
var flush = function flush() {
return queue.forEach(invoke);
};
var onWindowFocus = exports.onWindowFocus = function onWindowFocus(handler) {
if (focused) {
handler();
} else {
queue.add(handler);
}
};
(0, _snapshot.onWindowReady)(function () {
focused = true; // Treat window as initially focused once ready
flush();
(0, _dispatcher.on)('focus', function () {
focused = true;
flush();
}, window);
(0, _dispatcher.on)('blur', function () {
focused = false;
}, window);
});