Skip to content

Commit 885d5d2

Browse files
committed
improve typings
1 parent 1f47510 commit 885d5d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+6424
-1727
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
npm-debug.log
33
notes.md
4+
test/tests.md

lib/atom/editor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function open(filePath, options) {
4444
}
4545
exports.open = open;
4646
function set(text) {
47-
getEditor().then(function (editor) {
47+
return getEditor().then(function (editor) {
4848
editor.setText(text);
4949
editor.insertNewline();
5050
editor.moveToBottom();
@@ -56,7 +56,7 @@ function insert(text, options) {
5656
options = Object.assign(options, {
5757
autoIndent: true
5858
});
59-
getEditor().then(function (editor) {
59+
return getEditor().then(function (editor) {
6060
editor.moveToBottom();
6161
editor.insertText(text, options);
6262
editor.insertNewline();

lib/atom/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use strict';
22
var render_1 = require('../components/render');
3+
var polyfills_1 = require('../services/polyfills');
34
var subscriptions_1 = require('./subscriptions');
45
var editor_1 = require('./editor');
56
var Main = (function () {
67
function Main() {
78
global.coderoad = {};
9+
polyfills_1.default();
810
editor_1.setAtomGlobals();
911
this.root = render_1.initRoot();
1012
}

lib/reducers/alert/alert.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var defaultAlert = {
66
action: '',
77
duration: 0
88
};
9-
var current = {};
9+
var current = defaultAlert;
1010
function alertReducer(alert, action) {
1111
if (alert === void 0) { alert = defaultAlert; }
1212
var statusBarAlert = document.getElementsByClassName('cr-alert-replay')[0];
@@ -52,7 +52,6 @@ function alertReducer(alert, action) {
5252
};
5353
return current;
5454
}
55-
return defaultAlert;
5655
default:
5756
return alert;
5857
}

lib/reducers/reducer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ var editor_actions_1 = require('./editor-actions/editor-actions');
1414
var tutorials_1 = require('./tutorials/tutorials');
1515
var log_1 = require('./log/log');
1616
var hint_1 = require('./hint/hint');
17-
var solution_1 = require('./solution/solution');
1817
Object.defineProperty(exports, "__esModule", { value: true });
1918
exports.default = redux_1.combineReducers({
2019
project: project_1.default,
@@ -30,6 +29,5 @@ exports.default = redux_1.combineReducers({
3029
editorActions: editor_actions_1.default,
3130
tutorials: tutorials_1.default,
3231
log: log_1.default,
33-
hint: hint_1.default,
34-
solution: solution_1.default
32+
hint: hint_1.default
3533
});

lib/reducers/run-tests/test-result.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use strict";
22
var _base_1 = require('../../_base');
33
var Action = require('../../actions/actions');
4-
;
54
function handleResult(result) {
65
_base_1.store.dispatch(Action.testComplete());
76
if (!result.pass) {

lib/reducers/solution/solution.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
"use strict";
2-
function solutionReducer(solution, action) {
3-
if (solution === void 0) { solution = []; }
4-
switch (action.type) {
5-
default:
6-
return solution;
7-
}
8-
}
9-
Object.defineProperty(exports, "__esModule", { value: true });
10-
exports.default = solutionReducer;

lib/reducers/task-tests/concat-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function concatTests(targetFile, files) {
66
}
77
files.forEach(function (tests) {
88
if (typeof tests === 'string') {
9-
readAppend(targetFile, test);
9+
readAppend(targetFile, tests);
1010
}
1111
else if (Object.prototype.toString.call(tests) === '[object Array]') {
1212
tests.forEach(function (test) {

lib/services/polyfills.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
function loadPolyfills() {
3+
if (typeof Object.assign != 'function') {
4+
(function () {
5+
Object.assign = function (target) {
6+
'use strict';
7+
if (target === undefined || target === null) {
8+
throw new TypeError('Cannot convert undefined or null to object');
9+
}
10+
var output = Object(target);
11+
for (var index = 1; index < arguments.length; index++) {
12+
var source = arguments[index];
13+
if (source !== undefined && source !== null) {
14+
for (var nextKey in source) {
15+
if (source.hasOwnProperty(nextKey)) {
16+
output[nextKey] = source[nextKey];
17+
}
18+
}
19+
}
20+
}
21+
return output;
22+
};
23+
})();
24+
}
25+
}
26+
Object.defineProperty(exports, "__esModule", { value: true });
27+
exports.default = loadPolyfills;
28+
;

lib/services/setGlobals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ function loadRepo(config) {
5050
}
5151
global.coderoad.repo = repo;
5252
}
53-
global.coderoad.edit = config.config.edit && !!repo || false;
53+
global.coderoad.edit = config.config.edit && !!global.coderoad.repo || false;
5454
}

lib/store/initialState.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ function getInitialState() {
2323
editorActions: false,
2424
runTests: false,
2525
tutorials: [],
26-
alert: {},
27-
log: { open: false, message: '' },
28-
hint: []
26+
alert: {}
2927
};
3028
}
3129
exports.getInitialState = getInitialState;

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@
4747
"classnames": "2.2.3"
4848
},
4949
"devDependencies": {
50+
"ava": "^0.12.0",
5051
"enzyme": "2.0.0",
5152
"jsdom": "8.0.4",
5253
"react-addons-test-utils": "0.14.7"
54+
},
55+
"scripts": {
56+
"test": "ava"
5357
}
5458
}

src/actions/actions.spec.ts

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

src/actions/actions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@ import {store} from '../_base';
44
import Package from '../services/package';
55

66
/* Project */
7-
export function setProject(): Action {
7+
export function setProject(): CR.Action {
88
return { type: Type.SET_PROJECT };
99
}
1010

11-
export function setProgress(): Action {
11+
export function setProgress(): CR.Action {
1212
return { type: Type.SET_PROGRESS };
1313
}
1414

1515
/* Navigation */
16-
export function setRoute(route: string): Action {
16+
export function setRoute(route: string): CR.Action {
1717
return { type: Type.SET_ROUTE, payload: { route } };
1818
}
1919

2020
/* Position */
21-
export function setPosition(position: cr.Position): Action {
21+
export function setPosition(position: CR.Position): CR.Action {
2222
return { type: Type.SET_POSITION, payload: { position } };
2323
}
2424

25-
export function loadTutorial(name) {
25+
export function loadTutorial(name: string): void {
2626
Package.selectPackage(name);
2727
store.dispatch(setProject());
2828
store.dispatch(setPosition({chapter: 0, page: 0}));
2929
store.dispatch(setProgress());
3030
}
3131

32-
export function toggleLog(): Action {
32+
export function toggleLog(): CR.Action {
3333
let open = !store.getState().log.open;
3434
return { type: Type.TOGGLE_LOG, payload: { open } };
3535
}
3636

37-
export function logMessage(message: string): Action {
37+
export function logMessage(message: string): CR.Action {
3838
return { type: Type.LOG_MESSAGE, payload: { message }};
3939
}
4040

src/actions/alert.ts

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

5-
export function toggleAlert(alert?: cr.Alert): Action {
5+
export function toggleAlert(alert?: CR.Alert): CR.Action {
66
const isOpen = store.getState().alert.open;
77
if (!alert) {
88
alert = { message: '', action: '', open: false };
@@ -12,6 +12,6 @@ export function toggleAlert(alert?: cr.Alert): Action {
1212
return { type: Type.TOGGLE_ALERT, payload: { alert } };
1313
}
1414

15-
export function replayAlert(): Action {
15+
export function replayAlert(): CR.Action {
1616
return { type: Type.REPLAY_ALERT };
1717
}

src/actions/page-actions.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import {store} from '../_base';
44
import Package from '../services/package';
55
const _ = require('lodash');
66

7-
export function setPage(selectedPosition: cr.Position = { chapter: 0, page: 0 }): Action {
8-
const page = Package.getPage(selectedPosition);
9-
const tasks = Package.getTasks(selectedPosition);
10-
const taskTests: cr.TaskTest[] = _.flatten(tasks.map((task) => task.tests || []));
11-
let actions: string[] = tasks.map((task) => task.actions || []);
7+
export function setPage(selectedPosition: CR.Position = { chapter: 0, page: 0 }): CR.Action {
8+
const page: CR.Page = Package.getPage(selectedPosition);
9+
const tasks: CR.Task[] = Package.getTasks(selectedPosition);
10+
const taskTests: CR.TaskTest[] = _.flatten(tasks.map((task) => task.tests || []));
11+
const actions: string[] = tasks.map((task) => task.actions || []);
1212
return { type: Type.SET_PAGE, payload: { page, tasks, position: selectedPosition, taskTests, actions } };
1313
}
1414

15-
export function nextPage(): Action {
16-
const position = store.getState().position;
17-
const nextPosition = Package.getNextPosition(position);
15+
export function nextPage(): CR.Action {
16+
const position: CR.Position = store.getState().position;
17+
const nextPosition: CR.Position = Package.getNextPosition(position);
1818
return setPage(nextPosition);
1919
}

src/actions/progress-actions.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
import * as Type from './actionTypes';
22
import {store} from '../_base';
33

4-
export function pageComplete() {
5-
const position = store.getState().position;
6-
const pageLength = store.getState().progress.chapters[position.chapter].pages.length;
7-
const action = { type: Type.PAGE_COMPLETE, payload: { position } };
4+
export function pageComplete(): CR.Action {
5+
const position: CR.Position = store.getState().position;
6+
const pageLength: number = store.getState().progress.chapters[position.chapter].pages.length;
7+
const action: CR.Action = { type: Type.PAGE_COMPLETE, payload: { position } };
88
if (position.page >= pageLength - 1) {
99
store.dispatch(chapterComplete());
1010
return action;
1111
}
1212
return action;
1313
}
1414

15-
export function chapterComplete(): Action {
16-
const chapter = store.getState().position.chapter;
17-
const chapterLength = store.getState().progress.chapters.length;
18-
const action = { type: Type.CHAPTER_COMPLETE, payload: { chapter } };
15+
export function chapterComplete(): CR.Action {
16+
const chapter: number = store.getState().position.chapter;
17+
const chapterLength: number = store.getState().progress.chapters.length;
18+
const action: CR.Action = { type: Type.CHAPTER_COMPLETE, payload: { chapter } };
1919
if (chapter >= chapterLength - 1) {
2020
store.dispatch(projectComplete());
2121
return action;
2222
}
2323
return action;
2424
}
2525

26-
export function projectComplete(): Action {
26+
export function projectComplete(): CR.Action {
2727
return { type: Type.PROJECT_COMPLETE };
2828
}

src/actions/task-actions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@ import * as Type from './actionTypes';
22
import * as Action from './actions';
33
import {store} from '../_base';
44

5-
function checkPageComplete(taskPosition: number) {
5+
function checkPageComplete(taskPosition: number): void {
66
const taskLength: number = store.getState().taskTests.length;
77
if (taskPosition > taskLength) {
88
store.dispatch(Action.pageComplete());
99
}
1010
}
1111

12-
export function setTaskPosition(taskPosition: number): Action {
13-
const currentTaskPosition = store.getState().taskPosition;
12+
export function setTaskPosition(taskPosition: number): CR.Action {
13+
const currentTaskPosition: number = store.getState().taskPosition;
1414
if (currentTaskPosition === taskPosition) {
1515
return { type: Type.NULL };
1616
}
1717
checkPageComplete(taskPosition);
1818
return { type: Type.SET_TASK_POSITION, payload: { taskPosition } };
1919
}
2020

21-
export function showHint(): Action {
21+
export function showHint(): CR.Action {
2222
return { type: Type.SHOW_HINT };
2323
}
2424

25-
export function runTests(): Action {
25+
export function runTests(): CR.Action {
2626
return { type: Type.RUN_TESTS };
2727
}
2828

29-
export function testResult(result): Action {
29+
export function testResult(result): CR.Action {
3030
let actions = store.getState().editorActions;
3131
return { type: Type.TEST_RESULT, payload: { result, actions } };
3232
}
3333

34-
export function testComplete(): Action {
34+
export function testComplete(): CR.Action {
3535
return { type: Type.TEST_COMPLETE };
3636
}

src/actions/tutorials.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import * as fs from 'fs';
55
import * as Type from './actionTypes';
66
import {fileExists} from '../services/exists';
77

8-
export function loadTutorials(): Action {
8+
export function loadTutorials(): CR.Action {
99
let tutorials = [];
1010
if (global.coderoad.dir) {
11-
let packageJson = loadRootPackageJson();
11+
let packageJson: PackageJson|boolean = loadRootPackageJson();
1212
if (!packageJson) {
1313
global.coderoad.package = null;
1414
let message = 'No package.json file available. Try running "npm init --y" in terminal';
@@ -24,7 +24,7 @@ export function loadTutorials(): Action {
2424
}
2525

2626

27-
function loadRootPackageJson() {
27+
function loadRootPackageJson(): PackageJson|boolean {
2828
let pathToPackageJson = path.join(global.coderoad.dir, 'package.json');
2929
if (fileExists(pathToPackageJson)) {
3030
return JSON.parse(fs.readFileSync(pathToPackageJson, 'utf8'));

0 commit comments

Comments
 (0)