UNPKG

@atlaskit/editor-plugin-user-preferences

Version:

UserPreferences plugin for @atlaskit/editor-core

46 lines 1.8 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import { useEffect } from 'react'; import { bind } from 'bind-event-listener'; import { logException } from '@atlaskit/editor-common/monitoring'; export var useDocumentVisibilityWatcher = function useDocumentVisibilityWatcher(userPreferencesProvider) { useEffect(function () { if (userPreferencesProvider) { var refreshPreferences = /*#__PURE__*/function () { var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: if (!(document.visibilityState === 'visible')) { _context.next = 9; break; } _context.prev = 1; _context.next = 4; return userPreferencesProvider.loadPreferences(); case 4: _context.next = 9; break; case 6: _context.prev = 6; _context.t0 = _context["catch"](1); logException(_context.t0, { location: 'editor-plugin-user-preferences/userPreferencesPlugin' }); case 9: case "end": return _context.stop(); } }, _callee, null, [[1, 6]]); })); return function refreshPreferences() { return _ref.apply(this, arguments); }; }(); return bind(document, { type: 'visibilitychange', listener: refreshPreferences }); } }, [userPreferencesProvider]); };