Skip to content

Commit 1e7c3d7

Browse files
committed
improved typings
1 parent 65ff242 commit 1e7c3d7

File tree

28 files changed

+1194
-106
lines changed

28 files changed

+1194
-106
lines changed

lib/atom/main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ var subscriptions_1 = require('./subscriptions');
55
var editor_1 = require('./editor');
66
var Main = (function () {
77
function Main() {
8-
window.coderoad = {};
8+
window.coderoad = {
9+
dir: null
10+
};
911
polyfills_1.default();
1012
editor_1.setAtomGlobals();
1113
this.root = render_1.initRoot();
@@ -22,7 +24,7 @@ var Main = (function () {
2224
};
2325
Main.prototype.deactivate = function () {
2426
if (this.statusBarTile) {
25-
this.statusBarTile.dispose();
27+
this.statusBarTile.destroy();
2628
this.statusBarTile = null;
2729
}
2830
subscriptions_1.onDeactivateSubscriptionsAndUnmount();

lib/components/page/chapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
var React = require('react');
23
var _components_1 = require('../_components');
34
Object.defineProperty(exports, "__esModule", { value: true });
45
exports.default = function (_a) {

lib/components/page/page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ var default_1 = (function (_super) {
7575
default_1.prototype.displayHint = function (task) {
7676
if (task && task.hints && task.hints.length) {
7777
if (this.state.hintPos < task.hints.length - 1) {
78-
this.setState({ hintPos: this.state.hintPos += 1 });
78+
this.setState({ hintPos: this.state.hintPos += 1, taskPos: this.state.taskPos });
7979
}
8080
}
8181
else {
82-
this.setState({ hintPos: -1 });
82+
this.setState({ hintPos: -1, taskPos: this.state.taskPos });
8383
}
8484
};
8585
default_1.prototype.hintsShown = function (task) {

lib/components/progress/progress.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ var React = require('react');
1717
var react_redux_1 = require('react-redux');
1818
var Action = require('../../actions/actions');
1919
var material_ui_1 = require('material-ui');
20-
var classNames = require('classnames');
2120
var Completed = require('material-ui/lib/svg-icons/toggle/check-box');
2221
var Current = require('material-ui/lib/svg-icons/av/play-circle-filled');
2322
var AllCompleted = require('material-ui/lib/svg-icons/action/done-all');

lib/components/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function unmount(target) {
1717
ReactDOM.unmountComponentAtNode(target);
1818
}
1919
exports.unmount = unmount;
20-
function initRoot(canStart) {
20+
function initRoot() {
2121
var root = document.createElement('div');
2222
root.setAttribute('id', rootName);
2323
root.hidden = true;

lib/reducers/editor-actions/actions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ function getParams(actionString) {
2121
var params = actionString.substring(command.length + 1, actionString.length - 1);
2222
if (!params.length) {
2323
console.error('Error loading editor action params ', actionString);
24-
return '';
24+
return null;
2525
}
26-
params = parser_1.parseParams.getParams(params);
27-
return params;
26+
var paramsList = parser_1.parseParams.getParams(params);
27+
return paramsList;
2828
}
2929
exports.getParams = getParams;
3030
function createObjectFromKeyValString(string) {

lib/reducers/editor-actions/editor-actions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ var _ = require('lodash');
44
var actions_1 = require('./actions');
55
function handleEditorActions(actionArray) {
66
if (actionArray && actionArray.length) {
7-
return Promise.all(actionArray.map(function (actionString) { return actions_1.editorActions(actionString); }));
7+
actionArray.map(function (actionString) { return actions_1.editorActions(actionString); });
88
}
99
}
1010
var currentTaskPosition = 0;
11+
var actions;
1112
function editorActionsReducer(editorActions, action) {
1213
if (editorActions === void 0) { editorActions = []; }
1314
switch (action.type) {
1415
case Type.SET_PAGE:
15-
var actions = action.payload.actions;
16+
actions = action.payload.actions;
1617
currentTaskPosition = 0;
1718
handleEditorActions(actions.shift());
1819
return actions;
1920
case Type.TEST_RESULT:
20-
var actions = action.payload.actions;
21+
actions = action.payload.actions;
2122
var nextTaskPosition = action.payload.result.taskPosition;
2223
if (nextTaskPosition > currentTaskPosition) {
2324
_.times(handleEditorActions(actions.shift()), nextTaskPosition - currentTaskPosition);

lib/reducers/reducer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var run_tests_1 = require('./run-tests/run-tests');
1313
var editor_actions_1 = require('./editor-actions/editor-actions');
1414
var tutorials_1 = require('./tutorials/tutorials');
1515
var log_1 = require('./log/log');
16-
var hint_1 = require('./hint/hint');
1716
Object.defineProperty(exports, "__esModule", { value: true });
1817
exports.default = redux_1.combineReducers({
1918
project: project_1.default,
@@ -28,6 +27,5 @@ exports.default = redux_1.combineReducers({
2827
runTests: run_tests_1.default,
2928
editorActions: editor_actions_1.default,
3029
tutorials: tutorials_1.default,
31-
log: log_1.default,
32-
hint: hint_1.default
30+
log: log_1.default
3331
});

lib/services/package.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ var PackageService = (function () {
4343
var _this = this;
4444
var config = this.config.config;
4545
return !tasks ? [] : tasks.map(function (task) {
46-
task.tests = !task.tests ? [] : task.tests.map(function (tests) {
47-
if (_.isString(tests)) {
48-
return [].concat(configTestString(config, _this.packageName, tests));
49-
}
50-
else {
51-
console.error('Invalid task test', tests);
52-
}
53-
});
46+
if (task.tests) {
47+
task.tests = task.tests.map(function (tests) {
48+
if (_.isString(tests)) {
49+
return [].concat(configTestString(config, _this.packageName, tests));
50+
}
51+
else {
52+
console.error('Invalid task test', tests);
53+
}
54+
});
55+
}
5456
return task;
5557
});
5658
};

src/atom/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class Main {
99
root: HTMLElement;
1010
statusBarTile: StatusBar.IStatusBarView;
1111
constructor() {
12-
window.coderoad = {};
12+
window.coderoad = {
13+
dir: null
14+
};
1315
loadPolyfills();
1416
setAtomGlobals();
1517
this.root = initRoot();
@@ -28,7 +30,7 @@ class Main {
2830
}
2931
deactivate(): void {
3032
if (this.statusBarTile) {
31-
this.statusBarTile.dispose();
33+
this.statusBarTile.destroy();
3234
this.statusBarTile = null;
3335
}
3436
onDeactivateSubscriptionsAndUnmount();

src/components/markdown/markdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Highlights = require('highlights');
44
let highlighter = new Highlights({registry: atom.grammars});
55

66
var options = {
7-
highlight: function (code, lang) {
7+
highlight: function (code: string, lang: string) {
88
return highlighter.highlightSync({
99
fileContents: code,
1010
scopeName: 'source.' + (lang || 'js')

src/components/page/chapter.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
import * as React from 'react';
23
import {MarkdownText} from '../_components';
34
/**
45
* Chapters Component

src/components/page/page.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class extends React.Component<{
4040
page: CR.Page, tasks: CR.Task[], taskPosition: number,
4141
editorActions: string[], log: any,
4242
runTests: boolean, callNextPage?: any, callRunTests?: any, callNextTask?: any
43-
}, {}> {
43+
}, {hintPos: number, taskPos: number}> {
4444
constructor() {
4545
super();
4646
this.state = {
@@ -51,15 +51,15 @@ constructor() {
5151
componentDidUpdate() {
5252
let taskPosition = this.props.taskPosition;
5353
if (taskPosition > 0 && taskPosition < this.props.tasks.length) {
54-
ReactDOM.findDOMNode(this.refs['task' + taskPosition]).scrollIntoView();
54+
ReactDOM.findDOMNode<HTMLElement>(this.refs['task' + taskPosition]).scrollIntoView();
5555
}
5656
if (this.state.taskPos !== taskPosition) {
5757
this.setState({
5858
hintPos: -1,
5959
taskPos: taskPosition
6060
});
6161
} else if (this.state.hintPos > -1) {
62-
ReactDOM.findDOMNode(this.refs['hint' + this.state.hintPos]).scrollIntoView();
62+
ReactDOM.findDOMNode<HTMLElement>(this.refs['hint' + this.state.hintPos]).scrollIntoView();
6363
}
6464
}
6565
visibleTasks() {
@@ -78,10 +78,10 @@ getIcon(index, position) {
7878
displayHint(task) {
7979
if (task && task.hints && task.hints.length) {
8080
if (this.state.hintPos < task.hints.length - 1) {
81-
this.setState({hintPos: this.state.hintPos += 1});
81+
this.setState({hintPos: this.state.hintPos += 1, taskPos: this.state.taskPos});
8282
}
8383
} else {
84-
this.setState({hintPos: -1});
84+
this.setState({hintPos: -1, taskPos: this.state.taskPos});
8585
}
8686
}
8787
hintsShown(task) {

src/components/render.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function unmount(target: HTMLElement) {
2828
ReactDOM.unmountComponentAtNode(target);
2929
}
3030

31-
export function initRoot(canStart: boolean) {
31+
export function initRoot(): HTMLElement {
3232
var root = document.createElement('div');
3333
root.setAttribute('id', rootName);
3434
// mark panel visibility as hidden, triggers immediately

src/reducers/alert/alert.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const defaultAlert: CR.Alert = {
1010
let current: CR.Alert = defaultAlert;
1111

1212
export default function alertReducer(alert = defaultAlert, action: CR.Action): CR.Alert {
13-
let statusBarAlert = document.getElementsByClassName('cr-alert-replay')[0];
13+
let statusBarAlert = <HTMLElement>document.getElementsByClassName('cr-alert-replay')[0];
1414
switch (action.type) {
1515
case Type.REPLAY_ALERT:
1616
return {

src/reducers/editor-actions/actions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const EditorAction = {
77
insert: 'insert'
88
};
99

10-
export function getCommand(actionString: string) {
10+
export function getCommand(actionString: string): string {
1111
// content before bracket
1212
let command = actionString.substring(0, actionString.indexOf('('));
1313
if (!command.length) {
@@ -18,16 +18,16 @@ export function getCommand(actionString: string) {
1818
}
1919

2020

21-
export function getParams(actionString: string) {
21+
export function getParams(actionString: string): string[] {
2222
// content in brackets, split by comma
2323
let command = getCommand(actionString);
2424
let params = actionString.substring(command.length + 1, actionString.length - 1); // trim brackets
2525
if (!params.length) {
2626
console.error('Error loading editor action params ', actionString);
27-
return '';
27+
return null;
2828
}
29-
params = parseParams.getParams(params);
30-
return params;
29+
let paramsList:string[] = parseParams.getParams(params);
30+
return paramsList;
3131
}
3232

3333
function createObjectFromKeyValString(string: string): Object {
@@ -62,10 +62,10 @@ export function getOptions(paramString: string): { param: string, options: Objec
6262
};
6363
}
6464

65-
export function editorActions(actionString: string): boolean {
65+
export function editorActions(actionString: string): Promise<void> {
6666
return new Promise((resolve, reject) => {
6767
let command: string = getCommand(actionString);
68-
let params: string = getParams(actionString);
68+
let params: string[] = getParams(actionString);
6969
switch (command) {
7070
case EditorAction.open:
7171
let obj = getOptions(params[0]);

src/reducers/editor-actions/editor-actions.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,25 @@ import {editorActions} from './actions';
44

55
function handleEditorActions(actionArray: string[]): void {
66
if (actionArray && actionArray.length) {
7-
return Promise.all(
8-
actionArray.map((actionString) => editorActions(actionString))
9-
);
7+
// TODO: What is this???
8+
actionArray.map((actionString) => editorActions(actionString));
109
}
1110
}
1211

1312
let currentTaskPosition = 0;
14-
13+
var actions;
1514
/**
1615
* Test is running, return true, else false
1716
*/
18-
export default function editorActionsReducer(editorActions = [], action: CR.Action): boolean {
17+
export default function editorActionsReducer(editorActions = [], action: CR.Action): string[] {
1918
switch (action.type) {
2019
case Type.SET_PAGE:
21-
let actions = action.payload.actions;
20+
actions = action.payload.actions;
2221
currentTaskPosition = 0;
2322
handleEditorActions(actions.shift());
2423
return actions;
2524
case Type.TEST_RESULT:
26-
let actions = action.payload.actions;
25+
actions = action.payload.actions;
2726
let nextTaskPosition = action.payload.result.taskPosition;
2827
if (nextTaskPosition > currentTaskPosition) {
2928
// run actions for each task position passed

src/reducers/editor-actions/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export let parseParams = {
2-
trim(text) {
2+
trim(text: string): string {
33
text = text.trim();
44
var firstBracket = text.charAt(0).match(/["']/);
55
if (firstBracket && !!text.charAt(text.length - 1).match(firstBracket[0])) {
@@ -45,7 +45,7 @@ export let parseParams = {
4545
}
4646
return this.params.concat(this.trim(this.current));
4747
},
48-
reset() {
48+
reset(): void {
4949
this.round = 0;
5050
this.square = 0;
5151
this.curly = 0;

src/reducers/hint/hint.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/reducers/reducer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import runTests from './run-tests/run-tests';
1313
import editorActions from './editor-actions/editor-actions';
1414
import tutorials from './tutorials/tutorials';
1515
import log from './log/log';
16-
import hint from './hint/hint';
1716

1817
export default combineReducers({
1918
project: project,
@@ -28,6 +27,5 @@ export default combineReducers({
2827
runTests: runTests,
2928
editorActions: editorActions,
3029
tutorials: tutorials,
31-
log: log,
32-
hint: hint
30+
log: log
3331
});

src/services/package.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as Action from '../actions/actions';
44
import {store} from '../_base';
55
const _ = require('lodash');
66

7-
function configTestString(config: PackageJson.config, packageName: string, test: string): string {
7+
function configTestString(config: CR.Config, packageName: string, test: string): string {
88
if (config.testDir) {
99
test = path.join(window.coderoad.dir, 'node_modules', packageName, config.testDir, test);
1010
} else {
@@ -45,13 +45,15 @@ class PackageService {
4545
configTaskTests(tasks: CR.Task[]): CR.Task[] {
4646
let config = this.config.config;
4747
return !tasks ? [] : tasks.map((task) => {
48-
task.tests = !task.tests ? [] : task.tests.map((tests: string) => {
48+
if (task.tests) {
49+
task.tests = task.tests.map((tests: string) => {
4950
if (_.isString(tests)) {
5051
return [].concat(configTestString(config, this.packageName, tests));
5152
} else {
5253
console.error('Invalid task test', tests);
5354
}
5455
});
56+
}
5557
return task;
5658
});
5759
}

0 commit comments

Comments
 (0)