Skip to content

Commit c7bfc1f

Browse files
committed
export editor, pass editor into Main
1 parent ea0f64c commit c7bfc1f

16 files changed

+214
-90
lines changed

lib/editor/compareVersions.js

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/editor/compareVersions.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/editor/index.js

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/editor/index.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/editor/setup.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/editor/setup.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js

+3-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/main.js

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/main.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/editor/compareVersions.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* extracts versions intro array from a string
3+
* "0.1.0" -> ['0', '1', '0']
4+
* or returns null
5+
* @param {string} v
6+
*/
7+
function matchVersions(v: string): string[]|null {
8+
return v.match(/([0-9]+)\.([0-9]+)/);
9+
}
10+
11+
/**
12+
* checks that a version is >= b version
13+
* @param {string} a
14+
* @param {string} b
15+
* @returns boolean
16+
*/
17+
export function isAboveVersion(a: string, b: string): boolean {
18+
if (a === b) { return true; }
19+
const a_components = a.split('.');
20+
const b_components = b.split('.');
21+
const len = Math.min(a_components.length, b_components.length);
22+
for (let i = 0; i < len; i++) {
23+
const first = parseInt(a_components[i], 10);
24+
const second = parseInt(b_components[i], 10);
25+
if (first > second) { return true; }
26+
if (first < second) { return false; }
27+
}
28+
if (a_components.length > b_components.length) { return true; }
29+
if (a_components.length < b_components.length) { return false; }
30+
return true;
31+
}

src/editor/index.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { directory } from './directory';
2+
import { getGrammar, tokenizeLines } from './grammar';
3+
import {
4+
editorIssuesPath, editorMinVersion, editorName,
5+
editorVersionFailMessage, editorVersionLabel, minVersion
6+
} from './setup';
7+
import Subscriptions from './subscriptions';
8+
import {addRightPanel} from './ui';
9+
10+
const editor = {
11+
directory,
12+
getGrammar,
13+
tokenizeLines,
14+
editorName,
15+
editorMinVersion,
16+
editorVersionLabel,
17+
editorVersionFailMessage,
18+
editorIssuesPath,
19+
minVersion,
20+
Subscriptions,
21+
addRightPanel
22+
}
23+
24+
export default editor;

src/editor/setup.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22

3-
import {isAboveVersion} from '../utils/compareVersions';
3+
import {isAboveVersion} from './compareVersions';
44
import commandLine from 'atom-plugin-command-line';
55

66
export const editorName = 'Atom';

src/index.ts

+3-48
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,7 @@
1-
import * as React from 'react';
2-
import * as ReactDOM from 'react-dom';
3-
4-
import * as actions from './actions';
5-
import {SideRoot, sideElement} from './components/SidePanel';
6-
import addToStatusBar from './components/StatusBar';
7-
import Subscriptions from './editor/subscriptions';
8-
import {addRightPanel} from './editor/ui';
9-
import {setupVerify} from './modules/setup';
10-
import store from './store';
11-
import loadPolyfills from './utils/polyfills';
12-
import * as injectTapEventPlugin from 'react-tap-event-plugin';
1+
import editor from './editor';
2+
import Main from './main';
133

144
// React optimization
155
process.env.NODE_ENV = 'production';
166

17-
class Main {
18-
private side: HTMLElement;
19-
private statusBarTile: StatusBar.IStatusBarView|null;
20-
private subscriptions: any;
21-
constructor() {
22-
injectTapEventPlugin(); // remove later
23-
loadPolyfills();
24-
// run startup checks
25-
store.dispatch(setupVerify());
26-
this.side = sideElement.init();
27-
this.subscriptions = new Subscriptions();
28-
}
29-
public activate(): void {
30-
// create editor panel
31-
addRightPanel(this.side);
32-
// activate subscriptions
33-
this.subscriptions.onActivate(store, actions);
34-
// render React component
35-
ReactDOM.render(SideRoot(store), this.side);
36-
}
37-
public deactivate(): void {
38-
// remove bottom status bar icon
39-
if (this.statusBarTile) {
40-
this.statusBarTile.destroy();
41-
this.statusBarTile = null;
42-
}
43-
// remove subscriptions & unmount react app
44-
this.subscriptions.onDeactivate(store);
45-
// unmount React
46-
sideElement.unmount();
47-
}
48-
private consumeStatusBar(statusBar) {
49-
this.statusBarTile = addToStatusBar(store, statusBar);
50-
}
51-
};
52-
export = new Main();
7+
export = new Main(editor);

src/main.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as React from 'react';
2+
import * as ReactDOM from 'react-dom';
3+
4+
import * as actions from './actions';
5+
import {SideRoot, sideElement} from './components/SidePanel';
6+
import addToStatusBar from './components/StatusBar';
7+
import {setupVerify} from './modules/setup';
8+
import store from './store';
9+
import loadPolyfills from './utils/polyfills';
10+
import * as injectTapEventPlugin from 'react-tap-event-plugin';
11+
12+
class Main {
13+
public editor: any;
14+
private side: HTMLElement;
15+
private statusBarTile: StatusBar.IStatusBarView|null;
16+
private subscriptions: any;
17+
constructor(editor) {
18+
injectTapEventPlugin(); // remove later
19+
loadPolyfills();
20+
21+
this.editor = editor;
22+
// run startup checks
23+
store.dispatch(setupVerify());
24+
this.side = sideElement.init();
25+
this.subscriptions = new editor.Subscriptions();
26+
}
27+
public activate(): void {
28+
// create editor panel
29+
this.editor.addRightPanel(this.side);
30+
// activate subscriptions
31+
this.subscriptions.onActivate(store, actions);
32+
// render React component
33+
ReactDOM.render(SideRoot(store), this.side);
34+
}
35+
public deactivate(): void {
36+
// remove bottom status bar icon
37+
if (this.statusBarTile) {
38+
this.statusBarTile.destroy();
39+
this.statusBarTile = null;
40+
}
41+
// remove subscriptions & unmount react app
42+
this.subscriptions.onDeactivate(store);
43+
// unmount React
44+
sideElement.unmount();
45+
}
46+
private consumeStatusBar(statusBar) {
47+
this.statusBarTile = addToStatusBar(store, statusBar);
48+
}
49+
};
50+
export default Main;

tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@
9393
"src/editor/actions/terminal.ts",
9494
"src/editor/actions/write.ts",
9595
"src/editor/actions/writeFile.ts",
96+
"src/editor/compareVersions.ts",
9697
"src/editor/directory.ts",
9798
"src/editor/grammar.ts",
99+
"src/editor/index.ts",
98100
"src/editor/subscriptions.ts",
99101
"src/editor/ui.ts",
100102
"src/index.ts",
103+
"src/main.ts",
101104
"src/modules/alert/actions.ts",
102105
"src/modules/alert/index.ts",
103106
"src/modules/alert/types.ts",

0 commit comments

Comments
 (0)