Files
Alta-Proxy-Tool/renderer-controller.js
T

42 lines
1.3 KiB
JavaScript

'use strict';
(function exposeRendererController(globalScope) {
function createRendererController({
disconnect,
renderConnectionState,
clearDisconnectedState,
showConnectionStatus,
} = {}) {
if (
typeof disconnect !== 'function' ||
typeof renderConnectionState !== 'function' ||
typeof clearDisconnectedState !== 'function' ||
typeof showConnectionStatus !== 'function'
) {
throw new TypeError('Renderer controller dependencies are invalid.');
}
return Object.freeze({
async disconnect() {
const result = await disconnect();
if (!result || result.success !== true) {
const message = result && typeof result.message === 'string'
? result.message
: 'Failed to disconnect from Alta. The current connection remains active.';
showConnectionStatus(message, 'error');
return result;
}
renderConnectionState(result);
clearDisconnectedState();
showConnectionStatus('Disconnected from Alta.', 'info');
return result;
},
});
}
const api = Object.freeze({ createRendererController });
if (typeof module !== 'undefined' && module.exports) module.exports = api;
if (globalScope) globalScope.AptRendererController = api;
}(typeof window !== 'undefined' ? window : undefined));