alm
Version:
The best IDE for TypeScript
202 lines (201 loc) • 8.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Load up TypeScript
*/
var _ts = require("byots");
var ensureImport = _ts;
/**
* The main entry point for the front end
*/
var root_1 = require("./root");
var commands = require("./commands/commands");
var React = require("react");
var ReactDOM = require("react-dom");
var ReactDOMServer = require("react-dom/server");
var react_redux_1 = require("react-redux");
var state = require("./state/state");
var state_1 = require("./state/state");
var ui = require("./ui");
var appTabsContainer_1 = require("./tabs/v2/appTabsContainer");
var settings = require("./state/settings");
var clientSession = require("./state/clientSession");
var types = require("../common/types");
var globalErrorCacheClient_1 = require("./globalErrorCacheClient");
var clientTestResultsCache_1 = require("./clientTestResultsCache");
var socketClient_1 = require("../socket/socketClient");
var Modal = require('react-modal');
// Having jQuery ($) on the console helps us debug certin libs that use jQuery
var $ = require("jquery");
window.$ = $;
// prevent backspace
var preventBackspaceNav_1 = require("./utils/preventBackspaceNav");
preventBackspaceNav_1.preventBackspaceNav();
// Normalize css
require('normalize.css');
// Lost connection indicator
require('./lostConnection.css');
// Load clipboard and enable for all things clipboard
var Clipboard = require('clipboard/dist/clipboard.min');
new Clipboard('[data-clipboard-text]');
// Load hint.css for fancy (styleable) titles
require('hint.css/hint.css');
// Setup font awesome
require('font-awesome/css/font-awesome.css');
var afterLoaded = function () {
// The main app element
var appElement = document.getElementById('app');
// Register a modal location
Modal.setAppElement(appElement);
// Render the main app
ReactDOM.render(React.createElement(react_redux_1.Provider, { store: state_1.store },
React.createElement(root_1.Root, null)), appElement);
// Register commands
commands.register();
// For testing
// server.echo({text:"123",num:345}).then((res)=>console.log(res));
// Anything that should mutate the state
socketClient_1.server.getErrors({}).then(function (errorsUpdate) {
globalErrorCacheClient_1.errorsCache.setErrors(errorsUpdate);
});
socketClient_1.cast.errorsDelta.on(function (errorsDelta) {
if (errorsDelta.initial) {
globalErrorCacheClient_1.errorsCache.clearErrors();
}
globalErrorCacheClient_1.errorsCache.applyDelta(errorsDelta);
});
socketClient_1.server.getTestResults({}).then(function (results) {
clientTestResultsCache_1.testResultsCache.setResults(results);
});
socketClient_1.cast.testResultsDelta.on(function (testResultsDelta) {
clientTestResultsCache_1.testResultsCache.applyTestResultsDelta(testResultsDelta);
});
socketClient_1.pendingRequestsChanged.on(function (r) {
state.setPendingRequests(r.pending);
});
var firstConnectionState = true;
socketClient_1.connectionStatusChanged.on(function (r) {
state.setSocketConnected(r.connected);
if (firstConnectionState) {
$('.alm-connection-status').css('display', 'block');
firstConnectionState = false;
return;
}
$('.alm-connection-status').toggleClass('alm-connection-status-active', !r.connected);
});
socketClient_1.server.getActiveProjectConfigDetails({}).then(function (res) {
state.setActiveProject(res);
});
socketClient_1.cast.activeProjectConfigDetailsUpdated.on(function (res) {
state.setActiveProject(res);
});
socketClient_1.server.activeProjectFilePaths({}).then(function (res) {
state.setFilePathsInActiveProject(res.filePaths);
});
socketClient_1.cast.activeProjectFilePathsUpdated.on(function (res) {
state.setFilePathsInActiveProject(res.filePaths);
});
socketClient_1.server.filePaths({}).then(function (res) {
state.setFilePaths({ filePaths: res.filePaths, rootDir: res.rootDir, completed: res.completed });
});
socketClient_1.cast.filePathsUpdated.on(function (res) {
state.setFilePaths({ filePaths: res.filePaths, rootDir: res.rootDir, completed: res.completed });
});
socketClient_1.server.getCompleteOutputStatusCache({}).then(function (res) {
state.completeOuputStatusCacheUpdated(res);
});
socketClient_1.cast.fileOutputStatusUpdated.on(function (res) {
state.fileOuputStatusUpdated(res);
});
socketClient_1.cast.completeOutputStatusCacheUpdated.on(function (res) {
state.completeOuputStatusCacheUpdated(res);
});
socketClient_1.server.getLiveBuildResults({}).then(function (res) {
state.setLiveBuildResults(res);
});
socketClient_1.cast.liveBuildResults.on(function (res) {
state.setLiveBuildResults(res);
});
socketClient_1.cast.tsWorking.on(function (res) {
state.setTSWorking(res);
});
socketClient_1.cast.testedWorking.on(function (res) {
state.setTestedWorking(res);
});
commands.sync.on(function () {
socketClient_1.server.sync({});
});
commands.build.on(function () {
socketClient_1.server.build({});
});
/** Consolidate the file edit stuff into a single command */
socketClient_1.cast.didEdits.on(function (e) { commands.fileContentsChanged.emit({ filePath: e.filePath }); });
socketClient_1.cast.savedFileChangedOnDisk.on(function (e) { commands.fileContentsChanged.emit({ filePath: e.filePath }); });
commands.toggleDoctor.on(function () {
if (!state.inActiveProjectFilePath(appTabsContainer_1.tabState.getSelectedFilePath())) {
ui.notifyWarningNormalDisappear('Doctor is only available for files in active project');
return;
}
state.toggleDoctor({});
});
commands.toggleSemanticView.on(function () {
if (!state.inActiveProjectFilePath(appTabsContainer_1.tabState.getSelectedFilePath())) {
ui.notifyWarningNormalDisappear('Semantic view is only available for files in active project');
return;
}
state.toggleSemanticView({});
});
commands.duplicateWindow.on(function () {
var width = window.innerWidth;
var height = window.innerHeight;
window.open(window.location.href.replace(location.href, '') + "#" + types.urlHashNewSession, '', "innerWidth=" + width + ", innerHeight=" + height);
});
/** Set the window session */
socketClient_1.server.getValidSessionId({ sessionId: clientSession.getSessionId() }).then(function (res) {
clientSession.setSessionId(res.sessionId);
var sessionId = res.sessionId;
// Now load all the other settings we want:
/**
* Pattern:
* - Load the setting into redux
* - Then keep it updated as redux changes
*/
settings.showDoctor.get().then(function (res) {
state.setShowDoctor(res);
state.subscribeSub(function (s) { return s.showDoctor; }, function (showDoctor) {
settings.showDoctor.set(showDoctor);
});
});
settings.showSemanticView.get().then(function (res) {
state.setShowSemanticView(res);
state.subscribeSub(function (s) { return s.showSemanticView; }, function (showSemanticView) {
settings.showSemanticView.set(showSemanticView);
});
});
settings.errorsExpanded.get().then(function (res) {
if (res)
state.expandErrors({});
else
state.collapseErrors({});
state.subscribeSub(function (s) { return s.errorsExpanded; }, function (errorsExpanded) {
settings.errorsExpanded.set(errorsExpanded);
});
});
settings.errorsDisplayMode.get().then(function (res) {
state.setErrorsDisplayMode(res || types.ErrorsDisplayMode.all);
state.subscribeSub(function (s) { return s.errorsDisplayMode; }, function (errorsDisplayMode) {
settings.errorsDisplayMode.set(errorsDisplayMode);
});
});
settings.fileTreeExpanded.get().then(function (res) {
if (res)
state.expandFileTree({});
else
state.collapseFileTree({});
state.subscribeSub(function (s) { return s.fileTreeShown; }, function (fileTreeShown) {
settings.fileTreeExpanded.set(fileTreeShown);
});
});
});
};
afterLoaded();