Skip to content

Commit 683b0f5

Browse files
committed
fix task run styles, lower timeout values
1 parent c93d997 commit 683b0f5

File tree

26 files changed

+66
-90
lines changed

26 files changed

+66
-90
lines changed

lib/atom/actions/file.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var fs_1 = require('fs');
33
var exists_1 = require('../../services/exists');
44
var editor_1 = require('./editor');
5+
var openTimeout = 200;
56
function openFolder() {
67
atom.open();
78
}
@@ -19,7 +20,7 @@ function open(filePath, options) {
1920
atom.workspace.open(filePath, options);
2021
setTimeout(function () {
2122
resolve();
22-
}, 200);
23+
}, openTimeout);
2324
});
2425
}
2526
exports.open = open;

lib/atom/actions/terminal.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
"use strict";
22
function openTerminal() {
3-
if (atom.packages.isPackageActive('terminal-plus')) {
4-
if (!document.getElementsByClassName('xterm')[0]) {
5-
atom.commands.dispatch(document.getElementsByTagName('atom-workspace')[0], 'terminal-plus:toggle');
6-
}
7-
return true;
8-
}
93
return false;
104
}
115
exports.openTerminal = openTerminal;

lib/atom/actions/write.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ function set(text) {
1717
exports.set = set;
1818
function insert(text, options) {
1919
if (options === void 0) { options = {}; }
20-
options = Object.assign(options, {
21-
autoIndent: true,
22-
});
2320
return write('insert', text, options);
2421
}
2522
exports.insert = insert;

lib/components/Page/Task/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ function getStatus(index, taskPosition, testRun) {
2727
exports.Task = function (_a) {
2828
var task = _a.task, taskPosition = _a.taskPosition, index = _a.index, testRun = _a.testRun;
2929
var backgroundColor = getStatus(index, taskPosition, testRun);
30-
var currentTask = taskPosition === index;
31-
return (React.createElement(List_1.ListItem, {key: index, style: Object.assign({}, styles, { backgroundColor: backgroundColor })}, taskCheckbox_1.taskCheckbox(task, testRun), React.createElement("span", {style: indexStyles}, index + 1, "."), React.createElement("div", {style: descriptionStyles}, React.createElement(index_1.Markdown, null, task.description))));
30+
var isCurrentTask = taskPosition === index;
31+
return (React.createElement(List_1.ListItem, {key: index, style: Object.assign({}, styles, { backgroundColor: backgroundColor })}, taskCheckbox_1.taskCheckbox(isCurrentTask, testRun), React.createElement("span", {style: indexStyles}, index + 1, "."), React.createElement("div", {style: descriptionStyles}, React.createElement(index_1.Markdown, null, task.description))));
3232
};

lib/components/Page/Task/taskCheckbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var styles = {
66
position: 'absolute',
77
top: '15px'
88
};
9-
function taskCheckbox(currentTask, testRun) {
10-
if (!currentTask || !testRun) {
9+
function taskCheckbox(isCurrentTask, testRun) {
10+
if (!isCurrentTask || !testRun) {
1111
return null;
1212
}
1313
return (React.createElement("span", {style: styles}, React.createElement(indeterminate_check_box_1.default, {color: colors_1.orange500})));

lib/reducers/editor-actions/actions.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ function editorActions(actionString) {
1313
var params = action_helpers_1.getParams(actionString);
1414
switch (command) {
1515
case Type.OPEN:
16-
var obj = action_helpers_1.getOptions(params[0]);
17-
var file = obj.param;
18-
var options = obj.options;
16+
var _a = action_helpers_1.getOptions(params[0]), param = _a.param, options = _a.options;
1917
if (params.length === 1) {
20-
editor_1.open(file, options);
18+
editor_1.open(param, options);
2119
setTimeout(function () {
2220
resolve();
2321
}, 100);

lib/reducers/editor-actions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function editorActionsReducer(editorActions, action) {
1818
handleEditorActions(actions.shift());
1919
return actions;
2020
case _types_1.TEST_RESULT:
21-
actions = action.payload.actions;
21+
actions = action.payload.actions || [];
2222
var nextTaskPosition = action.payload.result.taskPosition;
2323
if (nextTaskPosition > currentTaskPosition) {
2424
for (var i = 0; i < nextTaskPosition - currentTaskPosition; i++) {

lib/reducers/progress/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function progressReducer(progress, action) {
2727
})
2828
};
2929
case _types_1.COMPLETE_PAGE:
30-
var position = action.payload.position;
31-
progress.chapters[position.chapter].pages[position.page] = true;
30+
var _a = action.payload.position, chapter = _a.chapter, page = _a.page;
31+
progress.chapters[chapter].pages[page] = true;
3232
local_storage_1.saveToLocalStorage(progress);
3333
return progress;
3434
case _types_1.COMPLETE_CHAPTER:

lib/reducers/route/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ function routeReducer(route, action) {
55
if (route === void 0) { route = _route; }
66
switch (action.type) {
77
case _types_1.ROUTE_SET:
8-
var next = action.payload.route;
98
return action.payload.route;
109
default:
1110
return route;

lib/reducers/task-tests/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@ function taskTestsReducer(taskTests, action) {
66
if (taskTests === void 0) { taskTests = ''; }
77
switch (action.type) {
88
case _types_1.TESTS_LOAD:
9-
var tasks = store_1.default.getState().tasks;
10-
var tests = [].concat.apply([], tasks.map(function (task) { return task.tests || []; }));
11-
var output_1 = '';
12-
tests.forEach(function (file) {
9+
return [].concat.apply([], store_1.default.getState().tasks.map(function (task) { return task.tests || []; })).reduce(function (output, file) {
1310
try {
14-
var data = fs_1.readFileSync(file, 'utf8');
15-
output_1 += data + '\n';
11+
output += fs_1.readFileSync(file, 'utf8') + '\n';
1612
}
1713
catch (e) {
1814
console.log('Error reading test file', e);
1915
}
20-
});
21-
return output_1;
16+
return output;
17+
}, '');
2218
default:
2319
return taskTests;
2420
}

lib/reducers/tasks/config-task-tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ function configTestString(config, name, testPath) {
1111
testPath = path_1.join(tutorial.config.dir, testPath);
1212
}
1313
else {
14-
var dir = store_1.default.getState().dir;
15-
testPath = path_1.join(dir, 'node_modules', name, testPath);
14+
testPath = path_1.join(store_1.default.getState().dir, 'node_modules', name, testPath);
1615
}
1716
if (tutorial.config.testSuffix) {
1817
testPath += tutorial.config.testSuffix;

lib/reducers/test-run/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
var _types_1 = require('../../actions/_types');
33
var run_1 = require('./run');
4-
var pageTimeout = 2000;
4+
var pageTimeout = 800;
55
var previous = new Date().getTime();
66
function runTestReducer(testRun, action) {
77
if (testRun === void 0) { testRun = false; }

src/atom/actions/editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function getEditor(): Promise<AtomCore.IEditor> {
44
let editor = atom.workspace.getActiveTextEditor();
55
while (!editor) {
66
getEditorCount += 1;
7-
setTimeout(function() {
7+
setTimeout(() => {
88
editor = atom.workspace.getActiveTextEditor();
99
}, 10);
1010
if (getEditorCount > 1000) {

src/atom/actions/file.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {unlink} from 'fs';
22
import {fileExists} from '../../services/exists';
33
import {getEditor} from './editor';
44

5+
// delay necessary since opening a file is slow
6+
const openTimeout = 200;
7+
58
export function openFolder(): void {
69
atom.open();
710
}
@@ -19,6 +22,6 @@ export function open(filePath: string, options = {}): Promise<any> {
1922
atom.workspace.open(filePath, options);
2023
setTimeout(() => {
2124
resolve();
22-
}, 200); // delay necessary since opening a file is slow
25+
}, openTimeout);
2326
});
2427
}

src/atom/actions/terminal.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
export function openTerminal(): boolean {
2-
if (atom.packages.isPackageActive('terminal-plus')) {
3-
if (!document.getElementsByClassName('xterm')[0]) {
4-
atom.commands.dispatch(
5-
document.getElementsByTagName('atom-workspace')[0], 'terminal-plus:toggle'
6-
);
7-
}
8-
return true;
9-
}
2+
// if (atom.packages.isPackageActive('terminal-plus')) {
3+
// if (!document.getElementsByClassName('xterm')[0]) {
4+
// atom.commands.dispatch(
5+
// document.getElementsByTagName('atom-workspace')[0], 'terminal-plus:toggle'
6+
// );
7+
// }
8+
// return true;
9+
// }
10+
// return false;
1011
return false;
1112
}

src/atom/actions/write.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import {getEditor} from './editor';
22

33
function write(action: 'set' | 'insert', text: string, options = {}) {
44
return getEditor().then((editor: AtomCore.IEditor) => {
5-
editor.moveToBottom();
6-
editor[`${action}Text`](text, options);
7-
editor.insertNewline();
8-
editor.moveToBottom();
9-
setCursorPosition(editor);
10-
editor.save();
11-
});
5+
editor.moveToBottom();
6+
editor[`${action}Text`](text, options);
7+
editor.insertNewline();
8+
editor.moveToBottom();
9+
setCursorPosition(editor);
10+
editor.save();
11+
});
1212
}
1313

1414
// Set text, removes any previous content in file
@@ -17,15 +17,12 @@ export function set(text: string) {
1717
}
1818

1919
export function insert(text: string, options = {}) {
20-
options = Object.assign(options, {
21-
autoIndent: true,
22-
});
2320
return write('insert', text, options);
2421
}
2522

2623
const cursor: RegExp = /::>/g;
2724
function setCursorPosition(editor: AtomCore.IEditor) {
28-
return editor.scan(cursor, function(scanned) {
25+
return editor.scan(cursor, (scanned) => {
2926
editor.setCursorScreenPosition(scanned.range.start);
3027
scanned.replace('');
3128
scanned.stop();

src/components/Page/Task/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export const Task: React.StatelessComponent<{
3434
task: CR.Task, taskPosition: number, index: number, testRun: boolean
3535
}> = ({task, taskPosition, index, testRun}) => {
3636
const backgroundColor = getStatus(index, taskPosition, testRun);
37-
const currentTask = taskPosition === index;
37+
const isCurrentTask = taskPosition === index;
3838
return (
3939
<ListItem
4040
key={index}
4141
style={Object.assign({}, styles, {backgroundColor})}
4242
>
43-
{taskCheckbox(task, testRun)}
43+
{taskCheckbox(isCurrentTask, testRun)}
4444
<span style={indexStyles}>{index + 1}.</span>
4545
<div style={descriptionStyles}>
4646
<Markdown >{task.description}</Markdown>

src/components/Page/Task/taskCheckbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const styles = {
99
top: '15px'
1010
};
1111

12-
export function taskCheckbox(currentTask: number, testRun: boolean) {
13-
if (!currentTask || !testRun) { return null; }
12+
export function taskCheckbox(isCurrentTask: boolean, testRun: boolean) {
13+
if (!isCurrentTask || !testRun) { return null; }
1414
return (
1515
<span style={styles}>
1616
<IndeterminateCheckBox color={orange500} />

src/reducers/editor-actions/actions.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@ export function editorActions(actionString: string): Promise<void> {
1414
let params: string[] = getParams(actionString);
1515
switch (command) {
1616
case Type.OPEN:
17-
let obj = getOptions(params[0]);
18-
let file = obj.param;
19-
let options = obj.options;
17+
const {param, options} = getOptions(params[0]);
2018
if (params.length === 1) {
21-
open(file, options);
22-
setTimeout(function() {
19+
open(param, options);
20+
setTimeout(() => {
2321
resolve();
2422
}, 100);
2523
}
2624
break;
2725
case Type.SET:
2826
if (params.length === 1) {
29-
let content = params[0];
30-
31-
setTimeout(function() {
27+
const content: string = params[0];
28+
setTimeout(() => {
3229
set(content);
3330
resolve(true);
3431
});
@@ -37,17 +34,17 @@ export function editorActions(actionString: string): Promise<void> {
3734
case Type.INSERT:
3835
if (params.length === 1) {
3936
// let obj = getOptions(params[0]);
40-
let content: string = params[0];
37+
const content: string = params[0];
4138
// let options: object = obj.options;
42-
setTimeout(function() {
39+
setTimeout(() => {
4340
insert(content, {});
4441
resolve(true);
4542
});
4643
}
4744
break;
4845
case Type.OPEN_CONSOLE:
4946
if (params.length === 0) {
50-
setTimeout(function() {
47+
setTimeout(() => {
5148
openDevTools();
5249
resolve(true);
5350
});

src/reducers/editor-actions/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ export default function editorActionsReducer(
2323
case TESTS_LOAD:
2424
actions = store.getState().tasks.map(task => task.actions || []);
2525
currentTaskPosition = 0;
26-
handleEditorActions(actions.shift());
26+
handleEditorActions(actions.shift()); // run first action
2727
return actions;
2828

2929
case TEST_RESULT:
30-
actions = action.payload.actions;
30+
actions = action.payload.actions || [];
3131
const nextTaskPosition = action.payload.result.taskPosition;
3232
if (nextTaskPosition > currentTaskPosition) {
3333
// run actions for each task position passed
3434
for (let i = 0; i < nextTaskPosition - currentTaskPosition; i++) {
35-
handleEditorActions(actions.shift());
35+
handleEditorActions(actions.shift()); // run first action
3636
}
3737
currentTaskPosition = nextTaskPosition;
3838
}

src/reducers/progress/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default function progressReducer(
3131
})
3232
};
3333
case COMPLETE_PAGE:
34-
const position = action.payload.position;
35-
progress.chapters[position.chapter].pages[position.page] = true;
34+
const {chapter, page} = action.payload.position;
35+
progress.chapters[chapter].pages[page] = true;
3636
saveToLocalStorage(progress);
3737
return progress;
3838
case COMPLETE_CHAPTER:

src/reducers/route/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export default function routeReducer(
88
): string {
99
switch (action.type) {
1010
case ROUTE_SET:
11-
const next = action.payload.route;
1211
return action.payload.route;
1312
default:
1413
return route;

src/reducers/task-tests/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ export default function taskTestsReducer(
77
): string {
88
switch (action.type) {
99
case TESTS_LOAD:
10-
const tasks = store.getState().tasks;
11-
let tests: string[] = [].concat.apply([], tasks.map(
12-
task => task.tests || [])
13-
);
14-
let output = '';
15-
tests.forEach(function(file: string): void {
10+
return [].concat.apply([], store.getState().tasks.map(
11+
task => task.tests || [])
12+
).reduce((output: string, file: string): string => {
1613
try {
17-
let data = readFileSync(file, 'utf8');
18-
output += data + '\n';
14+
output += readFileSync(file, 'utf8') + '\n';
1915
} catch (e) {
2016
console.log('Error reading test file', e);
2117
}
22-
});
23-
return output;
18+
return output;
19+
}, '');
2420
default:
2521
return taskTests;
2622
}

src/reducers/tasks/config-task-tests.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ function configTestString(config: Tutorial.Config, name: string, testPath: strin
1212
if (tutorial && tutorial.config.dir) {
1313
testPath = join(tutorial.config.dir, testPath);
1414
} else {
15-
const dir = store.getState().dir;
16-
testPath = join(dir, 'node_modules', name, testPath);
15+
testPath = join(store.getState().dir, 'node_modules', name, testPath);
1716
}
1817

1918
if (tutorial.config.testSuffix) {

src/reducers/test-run/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
} from '../../actions/_types';
44
import {runTaskTests} from './run';
55

6-
const pageTimeout = 2000;
6+
const pageTimeout = 800;
77

88
let previous: number = new Date().getTime();
99

0 commit comments

Comments
 (0)